#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 1000000;
const int MOD = 1000000007;
const int INV6 = (MOD + 1) / 6;
long long m;
int sumsqpw[MAXN + 1][4];
void run() {
  scanf("%lld", &m);
  int n = (int)floor(sqrt(1.0 * m));
  for (int j = (0); j < (4); ++j) sumsqpw[0][j] = j == 0 ? 1 : 0;
  for (int i = (1); i <= (n); ++i) {
    int ii = (long long)i * i % MOD, cur = 1;
    for (int j = (0); j < (4); ++j) {
      sumsqpw[i][j] = (sumsqpw[i - 1][j] + cur) % MOD;
      cur = (long long)cur * ii % MOD;
    }
  }
  for (int i = (1); i <= (n); ++i)
    for (int j = (0); j < (4); ++j)
      sumsqpw[i][j] =
          ((long long)2 * sumsqpw[i][j] + MOD - sumsqpw[0][j]) % MOD;
  int ret = 0;
  int a = 2;
  int b = ((-3 * m - 6) % MOD + MOD) % MOD;
  int c = (3 * m + 4) % MOD;
  int d = ((m + 2) % MOD) * ((m + 1) % MOD) % MOD * (m % MOD) % MOD;
  for (int x = (-n); x <= (+n); ++x) {
    int xx = (long long)x * x % MOD, xxxx = (long long)xx * xx % MOD,
        xxxxxx = (long long)xxxx * xx % MOD;
    int A = a;
    int B = ((long long)3 * a * xx + b) % MOD;
    int C = ((long long)3 * a * xxxx + (long long)2 * b * xx + c) % MOD;
    int D =
        ((long long)a * xxxxxx + (long long)b * xxxx + (long long)c * xx + d) %
        MOD;
    int ylim = (int)floor(sqrt(1.0 * (m - (long long)x * x)));
    ret = (ret + (long long)A * sumsqpw[ylim][3] +
           (long long)B * sumsqpw[ylim][2] + (long long)C * sumsqpw[ylim][1] +
           (long long)D * sumsqpw[ylim][0]) %
          MOD;
  }
  ret = (long long)ret * INV6 % MOD;
  printf("%d\n", ret);
}
int main() {
  run();
  return 0;
}
