#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long n, m, ans, iv6, iv30, iv42, f[5];
long long pw(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ans = ans * a % mod;
  return ans;
}
long long S(long long i, long long k) {
  if (k == 0) return 2 * i + 1;
  long long s0 = 2 * i * (i + 1) % mod * (2 * i + 1) % mod;
  if (k == 2) return iv6 * s0 % mod;
  long long t0, t1, t2, t3, t4;
  t0 = 1;
  t1 = i;
  t2 = i * i % mod;
  t3 = t1 * t2 % mod;
  t4 = t2 * t2 % mod;
  if (k == 4) return (3 * t2 + 3 * t1 - t0) % mod * s0 % mod * iv30 % mod;
  if (k == 6)
    return (3 * t4 + 6 * t3 - 3 * t1 + t0) % mod * s0 % mod * iv42 % mod;
}
int main() {
  ans = 0;
  cin >> m;
  n = sqrt(m);
  f[0] = 1ll * (m % mod) * ((m + 1) % mod) % mod * ((m + 2) % mod) % mod;
  f[1] = (3 * m + 4) % mod;
  f[2] = mod - (3 * m + 6) % mod;
  f[3] = 2;
  iv6 = pw(6, mod - 2);
  iv30 = pw(30, mod - 2);
  iv42 = pw(42, mod - 2);
  for (long long x = -n, x2, x4, x6, y; x <= n; x++) {
    y = sqrt(m - x * x);
    x2 = 1ll * x * x % mod;
    x4 = 1ll * x2 * x2 % mod;
    x6 = 1ll * x2 * x4 % mod;
    ans = (ans + f[3] * S(y, 6) % mod) % mod;
    ans = (ans + (6ll * x2 + f[2]) * S(y, 4) % mod) % mod;
    ans = (ans +
           (6ll * x4 + 2ll * f[2] * x2 % mod + f[1]) % mod * S(y, 2) % mod) %
          mod;
    ans = (ans + (f[3] * x6 % mod + f[2] * x4 % mod + f[1] * x2 % mod + f[0]) %
                     mod * S(y, 0) % mod) %
          mod;
  }
  cout << (ans * iv6 % mod + mod) % mod << endl;
  return 0;
}
