#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void gcdE(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    gcdE(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long inv(long long a, long long n) {
  long long d, x, y;
  gcdE(a, n, d, x, y);
  return d == 1 ? (x + n) % n : -1;
}
long long inv2, inv3;
long long power(long long a, long long x) {
  long long ans = 1;
  while (x) {
    if (x & 1) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    x >>= 1;
  }
  return ans;
}
int main() {
  inv2 = inv(2, mod);
  inv3 = inv(3, mod);
  vector<long long> p2, p4, p6;
  p2.assign(1000010, 0);
  p4 = p6 = p2;
  for (int i = 1; i <= 1000000; i++) {
    p2[i] = power(i, 2);
    p4[i] = power(i, 4);
    p6[i] = power(i, 6);
    p2[i] += p2[i - 1];
    p4[i] += p4[i - 1];
    p6[i] += p6[i - 1];
    p2[i] %= mod;
    p4[i] %= mod;
    p6[i] %= mod;
  }
  long long n;
  cin >> n;
  long long y = 1000000;
  long long ans = 0;
  long long nm = n % mod;
  for (long long i = 1; i * i <= n; i++) {
    while (y * y + i * i > n) y--;
    long long temp = 0;
    temp += p6[y] * inv3 % mod;
    temp += power(i, 2) * p4[y] % mod;
    temp += power(i, 4) * p2[y] % mod;
    temp += power(i, 6) * (y + 1) % mod * inv3 % mod;
    temp %= mod;
    long long coef = mod - (n % mod * inv2 % mod + 1) % mod;
    temp += coef * p4[y] % mod;
    temp += 2LL * coef % mod * power(i, 2) % mod * p2[y] % mod;
    temp += coef * power(i, 4) % mod * (y + 1) % mod;
    coef = (n % mod * inv2 % mod + 2 * inv3) % mod;
    temp += coef * power(i, 2) % mod * (y + 1) % mod;
    temp += coef * p2[y] % mod;
    temp += nm * (nm + 1) % mod * (nm + 2) % mod * inv2 % mod * inv3 % mod *
            (y + 1) % mod;
    ans += temp;
    ans %= mod;
  }
  ans *= 4LL;
  ans %= mod;
  ans += nm * (nm + 1) % mod * (nm + 2) % mod * inv2 % mod * inv3 % mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
