#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long mpow(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
long long s2(long long n) {
  n %= mod;
  return n * (n - 1) % mod;
}
long long s3(long long n) {
  n %= mod;
  return n * (n - 1) % mod * (n - 2) % mod;
}
long long eval(vector<long long> p, long long t) {
  long long res = 0;
  for (int i = p.size() - 1; i >= 0; --i) {
    res = (res * t + p[i]) % mod;
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> p(4);
  long long inv2 = mpow(2, mod - 2);
  long long inv3 = mpow(3, mod - 2);
  p[3] = (inv3) % mod;
  p[2] = (-(n + 2) % mod * inv2) % mod;
  p[1] = (-inv3 + (n + 2) % mod * inv2) % mod;
  p[0] = (-s3(n + 2) * inv3 + (n + 2) % mod * inv2 % mod * s2(n + 1)) % mod;
  long long s = eval(p, 1);
  for (long long x = 1; x * x <= n; ++x) {
    s = (s + 4 * eval(p, x * x % mod)) % mod;
  }
  vector<vector<long long> > pws(4, vector<long long>(1000003));
  for (int i = 0; i < pws.size(); ++i) {
    for (long long j = 1; j < pws[i].size(); ++j) {
      long long j2 = j * j % mod;
      long long add = 1;
      for (int t = 0; t < i; ++t) add = add * j2 % mod;
      pws[i][j] = (pws[i][j - 1] + add) % mod;
    }
  }
  long long y = sqrt(n) + 2;
  for (long long x = 1; x * x < n; ++x) {
    while (x * x + y * y > n) --y;
    long long x2 = x * x % mod;
    long long s1 = 0;
    s1 = (s1 + y * p[0]) % mod;
    s1 = (s1 + (x2 * y % mod + pws[1][y]) * p[1]) % mod;
    s1 =
        (s1 + (x2 * x2 % mod * y % mod + 2 * x2 * pws[1][y] % mod + pws[2][y]) *
                  p[2]) %
        mod;
    s1 = (s1 + (x2 * x2 % mod * x2 % mod * y % mod +
                3 * x2 * x2 % mod * pws[1][y] % mod + 3 * x2 * pws[2][y] % mod +
                pws[3][y]) *
                   p[3]) %
         mod;
    s = (s + 4 * s1) % mod;
  }
  cout << (s % mod + mod) % mod << endl;
  return 0;
}
