#include <bits/stdc++.h>
using namespace std;
int _p = 1e9 + 7;
long long ans = 0, m, k, xx[8], tt[8], kk[8];
inline long long calc(long long x, long long t, long long k) {
  for (int i = (1); i <= (6); ++i)
    xx[i] = xx[i - 1] * x % _p, tt[i] = tt[i - 1] * t % _p;
  k %= _p;
  long long ans = 70 * k + 105 * kk[2] + 35 * kk[3] + 64 * t + k * t % _p * 42 +
                  12 * tt[2] + k * tt[2] % _p * 21 + 30 * tt[5] + 10 * tt[6];
  ans += tt[3] * xx[2] % _p * 84 + tt[4] * xx[2] % _p * 42 + 140 * xx[2] +
         k * xx[2] % _p * 105 + xx[4] * t % _p * 70 + xx[4] * tt[2] % _p * 70 +
         70 * xx[6];
  ans -= 94 * tt[3] + 42 * k % _p * tt[3] % _p + 22 * tt[4] % _p +
         k * tt[4] % _p * 21 + t * xx[2] % _p * 154 +
         k * t % _p * xx[2] % _p * 70;
  (ans -= tt[2] * xx[2] % _p * 112 + k * tt[2] % _p * xx[2] % _p * 70 +
          210 * xx[4] + xx[4] * k % _p * 105) %= _p,
      (ans *= 2 * t + 1) %= _p;
  return ans;
}
int main() {
  scanf("%I64d", &m), k = floor(sqrt(m * 1.0));
  xx[0] = tt[0] = kk[0] = 1;
  for (int i = (1); i <= (3); ++i) kk[i] = kk[i - 1] * (m % _p) % _p;
  for (int x = (-k); x <= (k); ++x)
    ans += calc(x, (long long)floor(sqrt(m - (long long)x * x)), m);
  printf("%I64d\n", (ans % _p * 604761909 % _p + _p) % _p);
  return 0;
}
