#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long mul(long long a, long long b) {
  return (mod + (a * b) % mod) % mod;
}
inline long long add(long long a, long long b) {
  return (mod + (a + b) % mod) % mod;
}
long long pwr(long long a, long long b) {
  if (!b) return 1;
  long long h = pwr(a, (b >> 1));
  h = mul(h, h);
  if (b & 1) h = mul(h, a);
  return h;
}
const long long maxc = 5;
long long p[maxc][maxc];
long long mysqrt(long long a) {
  long long b = sqrt(a);
  while (b * b > a) b--;
  while ((b + 1) * (b + 1) <= a) b++;
  return b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < maxc; i++) {
    p[i][0] = p[i][i] = 1;
    for (int j = 1; j < i; j++) p[i][j] = add(p[i - 1][j - 1], p[i - 1][j]);
  }
  long long m;
  cin >> m;
  const long long c[4] = {mul(add(m, 2), mul(add(m, 1), add(m, 0))),
                          add(3 * m, 4), add(-6, -3 * m), 2};
  long long ans = 0, maxi = mysqrt(m) + 1;
  vector<vector<long long> > s(maxi, vector<long long>(maxc * 2));
  s[0][0] = 1;
  for (long long y = 1; y < maxi; y++) {
    long long pw = 1;
    for (long long p = 0; p < s[y].size(); pw = mul(pw, y), p++)
      s[y][p] = add(s[y - 1][p], mul(2, pw));
  }
  for (int deg = 0; deg < 4; deg++) {
    for (long long x = 0; x * x <= m; x++) {
      long long pwx = (x == 0 ? 1 : 2);
      for (int xp = 0; xp <= deg; xp++, pwx = mul(pwx, mul(x, x))) {
        int yp = deg - xp;
        long long maxy = mysqrt(m - x * x);
        ans = add(ans, mul(mul(p[deg][xp], c[deg]), mul(pwx, s[maxy][yp * 2])));
      }
    }
  }
  ans = mul(ans, pwr(6, mod - 2));
  cout << ans << "\n";
  return 0;
}
