#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline long long ty() {
  long long a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
}  // namespace ae86
using ae86::ty;
const int _ = 1000007, mo = 1000000007;
template <typename T1, typename T2>
inline T1 ad(T1 &a, T2 b) {
  return a = a + b >= mo ? a + b - mo : a + b;
}
template <typename T1, typename T2>
inline T1 dl(T1 &a, T2 b) {
  return a = a >= b ? a - b : a - b + mo;
}
template <typename T1, typename T2>
inline T1 add(T1 a, T2 b) {
  return a + b >= mo ? a + b - mo : a + b;
}
template <typename T1, typename T2>
inline T1 del(T1 a, T2 b) {
  return a >= b ? a - b : a - b + mo;
}
long long powa(long long a, long long t) {
  long long b = 1;
  a = (a + mo) % mo;
  while (t) {
    if (t & 1) b = b * a % mo;
    a = a * a % mo, t >>= 1;
  }
  return b;
}
inline long long inva(long long a) { return powa(a, mo - 2); }
long long si2[_] = {0}, si4[_] = {0}, si6[_] = {0};
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  long long n = ty(), m = n % mo, nn = sqrt(n);
  for (int i = 1; i <= nn; i++) {
    ad(si2[i], add(si2[i - 1], powa(i, 2)));
    ad(si4[i], add(si4[i - 1], powa(i, 4)));
    ad(si6[i], add(si6[i - 1], powa(i, 6)));
  }
  long long ans = 0;
  for (long long x = -nn; x <= nn; x++) {
    long long y = sqrt(n - x * x), x2 = powa(x, 2), x4 = powa(x, 4),
              x6 = powa(x, 6);
    ad(ans, 12 * x4 % mo * si2[y] % mo);
    ad(ans, 12 * x2 % mo * si4[y] % mo);
    ad(ans, 4 * si6[y] % mo);
    dl(ans, 12 * (m + 2) % mo * x2 % mo * si2[y] % mo);
    dl(ans, 6 * (m + 2) % mo * si4[y] % mo);
    ad(ans, 2 * (m + m + m + 4) * si2[y] % mo);
    ad(ans, (m * (m + 1) % mo * (m + 2) % mo + x6 + x6 - 3 * (m + 2) * x4 % mo +
             (m + m + m + 4) * x2 % mo + mo) %
                mo * (y + y + 1) % mo);
  }
  cout << ans * inva(6) % mo << lf;
  return 0;
}
