#include <bits/stdc++.h>
using namespace std;
const long long O = 1000000007;
const long long iv2 = (O + 1) / 2;
const long long iv3 = (O + 1) / 3;
const int maxN = 1000007;
template <class T>
T rd() {
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  T x = 0;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return f ? x : -x;
}
long long m;
int n;
long long res = 0;
long long pwr(long long x, long long t) {
  x %= O;
  long long res = 1;
  for (; t; t >>= 1, x = x * x % O)
    if (t & 1) res = res * x % O;
  return res;
}
inline long long Add(long long &x, long long y) { return (x += y) %= O; }
inline long long Minus(long long &x, long long y) { return (x -= y) %= O; }
inline long long Mul(long long &x, long long y) { return (x *= y) %= O; }
inline long long inv(long long x) { return pwr(x, O - 2); }
long long C1(long long x) {
  x %= O;
  return x * (x + 1) % O * iv2 % O;
}
long long C2(long long x) {
  x %= O;
  return x * (x + 1) % O * (2 * x + 1) % O * iv2 % O * iv3 % O;
}
long long C4[maxN], S0[maxN], S1[maxN], S2[maxN], G0[maxN], G1[maxN], G2[maxN],
    G3[maxN];
long long f0(int V) { return (2 * V + 1) % O; }
long long f1(int V) { return C2(V) * 2 % O; }
long long f2(int V) { return C4[V] * 2 % O; }
long long calc0() {
  long long res = 0;
  for (int i = (-n), _ = (n); i <= _; ++i) {
    int V = sqrtl(m - (long long)i * i);
    long long r = m - (long long)i * i - (long long)V * V + 1;
    long long tmp = 0;
    Add(tmp, r *
                 (pwr(i, 4) + 2 * pwr(i, 2) * pwr(V, 2) % O + pwr(V, 4) +
                  pwr(V, 2) + pwr(i, 2)) %
                 O);
    Add(tmp, 2 * pwr(i, 2) * C1(r - 1) % O + 2 * pwr(V, 2) * C1(r - 1) % O +
                 C2(r - 1) + C1(r - 1));
    Mul(tmp, f0(V));
    if (V) Add(res, G0[V - 1]);
    if (V) Add(res, (pwr(i, 4) + pwr(i, 2)) * G3[V - 1]);
    if (V) Add(res, 2 * pwr(i, 2) * G1[V - 1]);
    if (V) Add(res, 2 * pwr(i, 2) * G2[V - 1]);
    Add(res, tmp);
  }
  return res;
}
long long calc1() {
  long long res = 0;
  for (int i = (-n), _ = (n); i <= _; ++i) {
    int V = sqrtl(m - (long long)i * i);
    long long tmp = f1(V);
    long long r = m - (long long)i * i - (long long)V * V + 1;
    Add(tmp, pwr(i, 2) * f0(V) % O);
    Mul(tmp, r);
    if (V) Add(res, S1[V - 1]);
    if (V) Add(res, pwr(i, 2) * S0[V - 1] % O);
    Add(res, tmp);
  }
  return res;
}
long long calc2() {
  long long res = 0;
  for (int i = (-n), _ = (n); i <= _; ++i) {
    int V = sqrtl(m - (long long)i * i);
    long long tmp = f2(V);
    long long r = m - (long long)i * i - (long long)V * V + 1;
    Add(tmp, pwr(i, 4) * f0(V) % O);
    Add(tmp, pwr(i, 2) * 2 * f1(V) % O);
    Mul(tmp, r);
    if (V) Add(res, S2[V - 1]);
    if (V) Add(tmp, pwr(i, 4) * S0[V - 1] % O);
    if (V) Add(tmp, pwr(i, 2) * 2 * S1[V - 1] % O);
    Add(res, tmp);
  }
  return res;
}
int main() {
  m = rd<long long>();
  n = sqrtl(m);
  assert((long long)n * n <= m);
  assert((long long)(n + 1) * (n + 1) > m);
  for (int i = (1), _ = (n); i <= _; ++i) C4[i] = (C4[i - 1] + pwr(i, 4)) % O;
  S0[0] = f0(0);
  for (int i = (1), _ = (n); i <= _; ++i)
    S0[i] = (S0[i - 1] + f0(i) * (pwr(i + 1, 2) - pwr(i, 2)) % O) % O;
  S1[0] = f1(0);
  for (int i = (1), _ = (n); i <= _; ++i)
    S1[i] = (S1[i - 1] + f1(i) * (pwr(i + 1, 2) - pwr(i, 2)) % O) % O;
  S2[0] = f2(0);
  for (int i = (1), _ = (n); i <= _; ++i)
    S2[i] = (S2[i - 1] + f2(i) * (pwr(i + 1, 2) - pwr(i, 2)) % O) % O;
  for (int i = (0), _ = (n); i <= _; ++i) {
    int V = i;
    long long r = pwr(i + 1, 2) - pwr(i, 2);
    long long tmp = 0;
    Add(tmp, r * (pwr(V, 4) + pwr(V, 2)) % O);
    Add(tmp, 2 * pwr(V, 2) * C1(r - 1) % O + C2(r - 1) + C1(r - 1));
    Mul(tmp, f0(V));
    G0[i] = ((i ? G0[i - 1] : 0) + tmp) % O;
    tmp = pwr(V, 2) * r % O * f0(V) % O;
    G1[i] = ((i ? G1[i - 1] : 0) + tmp) % O;
    tmp = C1(r - 1) * f0(V) % O;
    G2[i] = ((i ? G2[i - 1] : 0) + tmp) % O;
    tmp = r * f0(V) % O;
    G3[i] = ((i ? G3[i - 1] : 0) + tmp) % O;
  }
  Add(res, calc0());
  Add(res, calc1());
  Minus(res, calc2());
  Mul(res, iv2);
  printf("%I64d\n", (res % O + O) % O);
  return 0;
}
