#include <bits/stdc++.h>
using namespace std;
int main() {
  long long m;
  scanf("%lld", &m);
  long long modu = 1000000007;
  long long t = m % modu;
  t = t * (t + 1) % modu * (t + 2) % modu;
  long long I2 = 500000004;
  long long I3 = 333333336;
  long long I6 = I2 * I3 % modu;
  t = t * I6 % modu;
  long long t00, t01, t02, t03, t10, t11, t12, t20, t21, t30;
  t00 = t;
  t01 = (2 * I3 % modu + m % modu * I2 % modu) % modu;
  t02 = (modu - (m % modu * I2 % modu + 1) % modu) % modu;
  t03 = I3;
  t10 = t01;
  t11 = (modu - (2 + m) % modu) % modu;
  t12 = 1;
  t20 = t02;
  t21 = 1;
  t30 = I3;
  long long ans = 0;
  long long x = sqrt(m);
  long long y = 0;
  long long _0, _1, _2, _3;
  long long __0, __1, __2, __3;
  _0 = _1 = _2 = _3 = 0;
  long long X, X2, X3, Y, Y2, Y3;
  X = x * x % modu;
  X2 = X * X % modu;
  X3 = X2 * X % modu;
  for (; x >= 0; x--) {
    X = x * x % modu;
    X2 = X * X % modu;
    X3 = X2 * X % modu;
    for (; x * x + y * y <= m; y++) {
      Y = y * y % modu;
      Y2 = Y * Y % modu;
      Y3 = Y2 * Y % modu;
      __0 = t00 + Y * t01 % modu + Y2 * t02 % modu + Y3 * t03 % modu;
      __1 = t10 + Y * t11 % modu + Y2 * t12 % modu;
      __2 = t20 + Y * t21 % modu;
      __3 = t30;
      if (y) __0 *= 2, __1 *= 2, __2 *= 2, __3 *= 2;
      _0 += __0;
      _0 %= modu;
      _1 += __1;
      _1 %= modu;
      _2 += __2;
      _2 %= modu;
      _3 += __3;
      _3 %= modu;
    }
    long long tmp = _0 + X * _1 % modu + X2 * _2 % modu + X3 * _3 % modu;
    if (x) tmp *= 2;
    ans = (ans + tmp) % modu;
  }
  printf("%lld\n", ans);
  return 0;
}
