#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5, mod = 1e9 + 7;
inline long long gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  long long sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
long long n, lim, ans, ans2;
long long pw2[maxn], pw4[maxn], pw6[maxn], sum2[maxn], sum4[maxn], sum6[maxn];
inline long long fpow(long long x, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = (long long)res * x % mod;
    k >>= 1;
    x = (long long)x * x % mod;
  }
  return res;
}
signed main() {
  n = gi();
  lim = sqrt(n);
  for (long long i = 1; i <= lim; ++i) {
    sum2[i] = (sum2[i - 1] + (pw2[i] = (long long)i * i % mod)) % mod;
    sum4[i] = (sum4[i - 1] + (pw4[i] = (long long)pw2[i] * pw2[i] % mod)) % mod;
    sum6[i] = (sum6[i - 1] + (pw6[i] = (long long)pw2[i] * pw4[i] % mod)) % mod;
  }
  long long N = n;
  n %= mod;
  for (long long x = -lim; x <= lim; ++x) {
    long long y = sqrt(N - x * x), x2 = pw2[abs(x)], x4 = pw4[abs(x)],
              x6 = pw6[abs(x)];
    ans = (ans + (long long)n * (n + 1) % mod * (n + 2) % mod * y) % mod;
    ans = (ans + (long long)2 * x6 % mod * y) % mod;
    ans = (ans + (long long)6 * x4 % mod * sum2[y]) % mod;
    ans = (ans + (long long)6 * x2 % mod * sum4[y]) % mod;
    ans = (ans + (long long)2 * sum6[y]) % mod;
    ans = (ans + (long long)(mod - 3) * (n + 2) % mod *
                     ((long long)x4 * y % mod + 2ll * x2 % mod * sum2[y] % mod +
                      sum4[y])) %
          mod;
    ans = (ans + (long long)(3ll * n + 4) % mod *
                     ((long long)x2 * y % mod + sum2[y])) %
          mod;
    ans2 = (ans2 + (long long)n * (n + 1) % mod * (n + 2)) % mod;
    ans2 = (ans2 + (long long)2 * x6 % mod) % mod;
    ans2 = (ans2 + (long long)(mod - 3) * (n + 2) % mod * x4) % mod;
    ans2 = (ans2 + (long long)(3ll * n % mod + 4) * x2) % mod;
  }
  ans = ((long long)ans * 2 + ans2) % mod;
  ans = (long long)ans * fpow(6, mod - 2) % mod;
  printf("%lld\n", ans);
  return 0;
}
