#include <bits/stdc++.h>
int ans, f0, f1, f2, f3, inv6, inv30, inv42, n;
long long m;
using namespace std;
inline int qpower(int a, int k) {
  int ans = 1;
  for (; k; k >>= 1, a = (1ll * a * a) % 1000000007)
    if (k & 1) ans = (1ll * ans * a) % 1000000007;
  return ans;
}
inline int inv(int x) { return qpower(x, 1000000007 - 2); }
void init() {
  ans = 0;
  scanf("%I64d", &m);
  n = sqrt(m);
  f0 = (((m % 1000000007) * ((m + 1) % 1000000007)) % 1000000007 *
        ((m + 2) % 1000000007)) %
       1000000007;
  f1 = (3 * m + 4) % 1000000007;
  f2 = (-(3 * m + 6)) % 1000000007;
  f3 = 2;
  inv6 = inv(6);
  inv30 = inv(30);
  inv42 = inv(42);
}
int sum(int n, int k) {
  if (!k) return (2 * n + 1) % 1000000007;
  int s = (2ll * n * (n + 1) % 1000000007 * ((2 * n + 1) % 1000000007)) %
          1000000007;
  if (k == 2) return 1ll * s * inv6 % 1000000007;
  int n2 = (1ll * n * n) % 1000000007, n3 = (1ll * n2 * n) % 1000000007,
      n4 = (1ll * n3 * n) % 1000000007;
  if (k == 4) {
    s = (1ll * s * (3ll * n2 + 3ll * n - 1) % 1000000007);
    return 1ll * s * inv30 % 1000000007;
  }
  if (k == 6) {
    s = (1ll * s * (3ll * n4 + 6ll * n3 - 3ll * n + 1)) % 1000000007;
    return 1ll * s * inv42 % 1000000007;
  }
}
void solve() {
  for (int x = -n; x <= n; ++x) {
    int y = sqrt(m - 1ll * x * x), x2 = (1ll * x * x) % 1000000007,
        x4 = (1ll * x2 * x2) % 1000000007, x6 = (1ll * x2 * x4) % 1000000007;
    ans = (ans + (f0 + (1ll * f1 * x2) % 1000000007 +
                  (1ll * f2 * x4) % 1000000007 + (1ll * f3 * x6) % 1000000007) *
                     sum(y, 0) % 1000000007) %
          1000000007;
    ans = (ans + (f1 + (2ll * f2 * x2) % 1000000007 + (6ll * x4) % 1000000007) *
                     sum(y, 2) % 1000000007) %
          1000000007;
    ans = (ans + (f2 + (6ll * x2) % 1000000007) * sum(y, 4)) % 1000000007;
    ans = (ans + (1ll * f3 * sum(y, 6))) % 1000000007;
  }
  ans = (1ll * ans * inv6) % 1000000007;
  if (ans < 0) ans += 1000000007;
  printf("%d\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
