#include <bits/stdc++.h>
using namespace std;
long long tavan(long long x, long long y) {
  long long res = 1;
  while (y) {
    res *= (y % 2) ? x : 1;
    res %= ((long long)1e9 + 7);
    x *= x;
    x %= ((long long)1e9 + 7);
    y /= 2;
  }
  return res;
}
long long C(long long x, long long y) {
  long long res = 1;
  for (int i = y + 1; i <= x; i++) res *= i;
  for (int i = 1; i <= x - y; i++) res /= i;
  return (res % ((long long)1e9 + 7));
}
long long n, ans;
long long num[((long long)1000 * 1000 + 10)],
    prt[4][((long long)1000 * 1000 + 10)];
long long zarib[4][4];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < ((long long)1000 * 1000 + 10); i++) {
    num[i] = i * i;
    for (int j = 0; j <= 3; j++)
      prt[j][i] =
          ((i ? prt[j][i - 1] : 0) + tavan(num[i] % ((long long)1e9 + 7), j)) %
          ((long long)1e9 + 7);
  }
  for (int i = 0; i <= 3; i++) {
    long long ex = tavan(3, ((long long)1e9 + 7) - 2);
    if (i == 2)
      ex = (((((-n - 2) % ((long long)1e9 + 7)) + ((long long)1e9 + 7)) %
             ((long long)1e9 + 7)) *
            tavan(2, ((long long)1e9 + 7) - 2)) %
           ((long long)1e9 + 7);
    if (i == 1)
      ex = ((((n + 1) % ((long long)1e9 + 7)) *
             tavan(2, ((long long)1e9 + 7) - 2)) %
                ((long long)1e9 + 7) +
            tavan(6, ((long long)1e9 + 7) - 2)) %
           ((long long)1e9 + 7);
    if (i == 0)
      ex = (((((((n + 2) % ((long long)1e9 + 7)) *
                ((n + 1) % ((long long)1e9 + 7))) %
               ((long long)1e9 + 7)) *
              (n % ((long long)1e9 + 7))) %
             ((long long)1e9 + 7)) *
            tavan(6, ((long long)1e9 + 7) - 2)) %
           ((long long)1e9 + 7);
    for (int j = 0; j <= i; j++)
      zarib[j][i - j] += (C(i, j) * ex) % ((long long)1e9 + 7),
          zarib[j][i - j] %= ((long long)1e9 + 7);
  }
  for (long long i = 1; i * i <= n; i++) {
    long long j =
        upper_bound(num, num + ((long long)1000 * 1000 + 10), n - i * i) - num -
        1;
    for (int j2 = 0; j2 <= 3; j2++) {
      long long now = 0;
      for (int i2 = 0; i2 <= 3; i2++)
        now += (tavan(num[i] % ((long long)1e9 + 7), i2) * zarib[i2][j2]) %
               ((long long)1e9 + 7),
            now %= ((long long)1e9 + 7);
      now *= prt[j2][j];
      now %= ((long long)1e9 + 7);
      ans += now;
      ans %= ((long long)1e9 + 7);
    }
  }
  ans *= 4;
  ans %= ((long long)1e9 + 7);
  ans += zarib[0][0];
  ans %= ((long long)1e9 + 7);
  cout << ans << "\n";
  return 0;
}
