#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ '0');
    ch = getchar();
  }
  return f ? x : -x;
}
const int mod = 1000000007;
long long m;
int n, s2[1000005], s4[1000005], s6[1000005];
inline void inc(int& x, int y) { x = x + y < mod ? x + y : x + y - mod; }
inline void dec(int& x, int y) { x = x - y >= 0 ? x - y : x - y + mod; }
inline int power(int b, int n) {
  int ans = 1;
  for (; n; n >>= 1, b = 1ll * b * b % mod)
    if (n & 1) ans = 1ll * ans * b % mod;
  return ans;
}
int main() {
  n = sqrt(m = read());
  for (int i = (1), _ed = (1000004); i <= _ed; ++i) {
    s2[i] = 1ll * i * i % mod;
    s4[i] = 1ll * s2[i] * s2[i] % mod;
    s6[i] = 1ll * s2[i] * s4[i] % mod;
    inc(s2[i], s2[i - 1]);
    inc(s4[i], s4[i - 1]);
    inc(s6[i], s6[i - 1]);
  }
  int ans = 0, inv = power(6, mod - 2), l, C, F;
  for (int x = (-n), _ed = (n); x <= _ed; ++x) {
    int x2 = (s2[abs(x)] - s2[abs(x) - 1] + mod) % mod,
        x4 = (s4[abs(x)] - s4[abs(x) - 1] + mod) % mod,
        x6 = (s6[abs(x)] - s6[abs(x) - 1] + mod) % mod;
    l = sqrt(m - 1ll * x * x);
    C = ((1ll * 2 * x6 % mod - (3 * m + 6) % mod * x4 % mod +
          (3 * m + 4) % mod * x2 % mod +
          (m % mod) * ((m + 1) % mod) % mod * ((m + 2) % mod) % mod) %
             mod +
         mod) %
        mod;
    F = ((1ll * 2 * s6[l] % mod +
          (1ll * 6 * x2 % mod - 3 * m % mod - 6) % mod * s4[l] % mod +
          (1ll * 6 * x4 % mod - (6 * m % mod + 12) * x2 % mod + 3 * m % mod +
           4) %
              mod * s2[l] % mod) %
             mod +
         mod) %
        mod;
    int tmp = (F + F + 1ll * (l + l + 1) * C % mod) % mod;
    inc(ans, 1ll * tmp * inv % mod);
  }
  printf("%d\n", ans);
  return 0;
}
