#include <bits/stdc++.h>
using namespace std;
long long n, nn, inv2, inv3, inv6;
int mod = 1e9 + 7, ans;
long long calc(long long a) {
  long long x = (1 + nn) * (nn + a) % mod * (nn - a + 1) % mod * inv2 % mod -
                nn * (nn + 1) % mod * (2 * nn + 1) % mod * inv6 % mod +
                (a - 1) * a % mod * (2 * a - 1) % mod * inv6 % mod;
  return (x % mod + mod) % mod;
}
inline int qpow(int x, int y = mod - 2) {
  int res = 1;
  for (; y; y >>= 1, x = 1ll * x * x % mod)
    if (y & 1) res = 1ll * res * x % mod;
  return res;
}
long long val[10], mul[10], imul[10], pre[10], suf[10];
void init() {
  nn = n % mod;
  for (int i = 1; i <= 8; ++i) {
    mul[i] = qpow(i);
    imul[i] = qpow(mod - i);
  }
  inv2 = mul[2], inv3 = mul[3], inv6 = mul[6];
  for (int i = 2; i <= 8; ++i) {
    mul[i] = mul[i] * mul[i - 1] % mod;
    imul[i] = imul[i] * imul[i - 1] % mod;
  }
}
long long lglr(long long y) {
  if (y <= 8) return val[y];
  for (int i = 1; i <= 8; ++i) pre[i] = suf[i] = y - i;
  for (int i = 2; i <= 8; ++i) pre[i] = pre[i - 1] * pre[i] % mod;
  for (int i = 7; i >= 1; --i) suf[i] = suf[i + 1] * suf[i] % mod;
  long long ans = 0;
  for (int i = 1; i <= 8; ++i) {
    long long b = val[i];
    if (i != 1) b = b * mul[i - 1] % mod * pre[i - 1] % mod;
    if (i != 8) b = b * imul[8 - i] % mod * suf[i + 1] % mod;
    ans = (ans + b) % mod;
  }
  return ans;
}
int main() {
  cin >> n;
  init();
  for (long long x = 0; x * x <= n; ++x) {
    long long t = sqrt(n - x * x), add = calc(x * x % mod);
    for (int i = 1; i <= 8; ++i)
      val[i] = (val[i - 1] + calc((x * x + i * i) % mod)) % mod;
    add = (add + 2 * lglr(t)) % mod;
    if (x == 0)
      ans = (ans + add) % mod;
    else
      ans = (ans + 2 * add) % mod;
  }
  cout << ans << endl;
}
