#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T Tmin(const T &lch, const T &rch) {
  if (lch < rch) return lch;
  return rch;
}
template <class T>
inline T Tmax(const T &lch, const T &rch) {
  if (lch < rch) return rch;
  return lch;
}
const int Inf = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int Gp = 3;
inline int R_int() {
  register int n = 0;
  register char ch = getchar();
  register bool I = false;
  while (ch < '0' || ch > '9') I = (ch == '-' ? 1 : 0), ch = getchar();
  while (ch >= '0' && ch <= '9')
    n = (n << 1) + (n << 3) + (ch ^ '0'), ch = getchar();
  return I ? -n : n;
}
inline int Add(int a, int b) {
  int ans = (a + b);
  ans = (ans >= Mod ? ans - Mod : ans);
  return ans;
}
inline int Mis(int a, int b) {
  int ans = a - b;
  ans = (ans < 0 ? ans + Mod : ans);
  return ans;
}
inline int Mul(int a, int b) { return a * 1ll * b % Mod; }
inline int Pow(int a, long long k) {
  int ans = 1;
  while (k) {
    if (k & 1) ans = Mul(ans, a);
    a = Mul(a, a);
    k = k >> 1;
  }
  return ans;
}
const int maxn = 1e6 + 10;
int sum2[maxn];
int sum4[maxn];
int sum6[maxn];
long long n;
signed main() {
  scanf("%I64d", &n);
  int m = n % Mod, Maxv = sqrt(n);
  for (int i = 1; i <= Maxv; i++) {
    sum2[i] = Add(sum2[i - 1], Mul(i, i));
    sum4[i] = Add(sum4[i - 1], Pow(i, 4));
    sum6[i] = Add(sum6[i - 1], Pow(i, 6));
  }
  for (int i = 1; i <= Maxv; i++) {
    sum2[i] = Mul(sum2[i], 2);
    sum4[i] = Mul(sum4[i], 2);
    sum6[i] = Mul(sum6[i], 2);
  }
  int ans = 0;
  for (int x = -Maxv, d; x <= Maxv; x++) {
    int Px2 = Pow(x, 2), Px4 = Pow(x, 4), Px6 = Pow(x, 6);
    int y = sqrt(n - x * 1ll * x), tmp = Mul(m, Mul(Add(m, 1), Add(m, 2)));
    d = Add(1, Mul(2, y));
    tmp = Mul(tmp, d);
    ans = Add(ans, tmp);
    ans = Add(ans, Mul(2, Add(Mul(Px6, d), sum6[y])));
    ans = Add(ans, Mul(6, Add(Mul(Px4, sum2[y]), Mul(Px2, sum4[y]))));
    ans = Mis(ans,
              Mul(Add(Mul(3, m), 6),
                  Add(Mul(Px4, d), Add(sum4[y], Mul(2, Mul(Px2, sum2[y]))))));
    ans = Add(ans, Mul(Add(Mul(3, m), 4), Add(Mul(Px2, d), sum2[y])));
  }
  ans = Mul(ans, Pow(6, Mod - 2));
  printf("%d\n", ans);
  return 0;
}
