#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000006;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
namespace ModCalculator {
const int MOD = 1e9 + 7;
inline void Inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
inline void Dec(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
inline int Add(int x, int y) {
  Inc(x, y);
  return x;
}
inline int Sub(int x, int y) {
  Dec(x, y);
  return x;
}
inline int Mul(int x, int y) { return 1LL * x * y % MOD; }
inline int ksm(int x, int k) {
  int ret = 1;
  for (; k; k >>= 1) {
    if (k & 1) ret = Mul(ret, x);
    x = Mul(x, x);
  }
  return ret;
}
inline int Inv(int x) { return ksm(x, MOD - 2); }
}  // namespace ModCalculator
using namespace ModCalculator;
long long n;
int _n, c3, n6, n4, sq, s2[MAXN], s4[MAXN], s6[MAXN];
void init() {
  read(n);
  sq = sqrt(n);
  _n = n % MOD;
  c3 = Mul(_n, Mul(_n + 1, _n + 2));
  n6 = Add(Mul(_n, 3), 6);
  n4 = Add(Mul(_n, 3), 4);
  for (int i = 1; i <= sq; ++i) {
    int i2 = Mul(i, i), i4 = Mul(i2, i2), i6 = Mul(i2, i4);
    s2[i] = Add(s2[i - 1], i2);
    s4[i] = Add(s4[i - 1], i4);
    s6[i] = Add(s6[i - 1], i6);
  }
}
void solve() {
  int ans = 0;
  for (int x = 0; x <= sq; ++x) {
    int x2 = Mul(x, x), x4 = Mul(x2, x2), x6 = Mul(x2, x4);
    int y = sqrt(n - 1LL * x * x), curx = c3, cury = 0;
    Inc(curx, Mul(x6, 2));
    Dec(curx, Mul(x4, n6));
    Inc(curx, Mul(x2, n4));
    curx = Mul(curx, y * 2 + 1);
    Inc(cury, Mul(s6[y], 2));
    Dec(cury, Mul(s4[y], n6));
    Inc(cury, Mul(s2[y], n4));
    Inc(cury, Mul(Mul(x4, s2[y]), 6));
    Inc(cury, Mul(Mul(x2, s4[y]), 6));
    Dec(cury, Mul(Mul(x2, s2[y]), Mul(n6, 2)));
    Inc(cury, cury);
    Inc(curx, cury);
    Inc(ans, curx);
    if (x) Inc(ans, curx);
  }
  printf("%d\n", Mul(ans, Inv(6)));
}
int main() {
  init();
  solve();
  return 0;
}
