#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
long long sump2[1000005], sump4[1000005];
long long zzpow(long long x, long long p) {
  if (!p) return 1ll;
  long long t = zzpow(x, p / 2);
  if (p % 2) return t * t % mod * x % mod;
  return t * t % mod;
}
long long prod3(long long x) {
  return x % mod * (x % mod + mod - 1) % mod * (x % mod + 1) % mod;
}
long long phrase1(long long x) {
  return ((zzpow(x, 6) - zzpow(x, 2) + mod) % mod + mod) % mod;
}
long long phrase2(long long x, long long n) {
  return ((mod - zzpow(x, 6)) + (n + 2) % mod * zzpow(x, 4) % mod +
          (mod - (n + 1) % mod) * zzpow(x, 2) % mod) %
         mod;
}
int main() {
  for (int i = 1; i <= 1000000; i++) {
    sump2[i] = (sump2[i - 1] + zzpow(i, 2)) % mod;
    sump4[i] = (sump4[i - 1] + zzpow(i, 4)) % mod;
  }
  long long n;
  cin >> n;
  long long tmp = 0;
  long long partOne = 0;
  for (long long i = 1; i * i <= n; i++) {
    tmp = (tmp + (long long)sqrt(n - i * i)) % mod;
  }
  partOne = tmp * prod3(n + 1) % mod * zzpow(2, mod - 2) % mod *
            zzpow(3, mod - 2) % mod;
  long long partTwo = 0;
  for (long long i = 1; i * i <= n; i++) {
    long long mjk = (long long)sqrt(n - i * i);
    partTwo = (partTwo + mjk % mod * phrase1(i) % mod) % mod;
  }
  partTwo = partTwo * 2 % mod;
  for (long long i = 1; i <= (long long)sqrt(n); i++) {
    long long mjk = (long long)sqrt(n - i * i);
    partTwo = ((partTwo + zzpow(i, 4) * sump2[mjk] % mod * 3 % mod +
                zzpow(i, 2) * sump4[mjk] % mod * 3 % mod) %
                   mod +
               mod) %
              mod;
  }
  partTwo = partTwo * zzpow(2, mod - 2) % mod * zzpow(3, mod - 2) % mod;
  long long partThree = 0;
  for (long long i = 1; i * i <= n; i++) {
    long long mjk = (long long)sqrt(n - i * i);
    partThree = (partThree + mjk % mod * phrase2(i, n) % mod) % mod;
  }
  partThree = partThree * 2 % mod;
  for (long long i = 1; i * i <= n; i++) {
    long long mjk = (long long)sqrt(n - i * i);
    partThree =
        (partThree - zzpow(i, 4) * sump2[mjk] % mod * 3 % mod + mod) % mod;
    partThree =
        (partThree - zzpow(i, 2) * sump4[mjk] % mod * 3 % mod + mod) % mod;
    partThree =
        (partThree + zzpow(i, 2) * sump2[mjk] % mod * (n % mod * 2 + 4) % mod +
         mod) %
        mod;
  }
  partThree = partThree * zzpow(2, mod - 2) % mod;
  long long ans = (partOne - partTwo - partThree + mod * 2) * 4 % mod;
  for (long long i = 1; i * i <= n; i++) {
    ans = (ans + 4ll * (prod3(n + 1) - prod3(i * i % mod) + mod) % mod *
                     zzpow(2, mod - 2) % mod * zzpow(3, mod - 2) % mod) %
          mod;
    ans =
        (ans -
         4ll * (n % mod - zzpow(i, 2) + 1 + mod) % mod *
             (zzpow(i, 4) - zzpow(i, 2) + mod) % mod * zzpow(2, mod - 2) % mod +
         mod) %
        mod;
  }
  ans += prod3(n + 1) % mod * zzpow(2, mod - 2) % mod * zzpow(3, mod - 2) % mod;
  cout << (ans + mod) % mod;
}
