#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007, iv6 = 166666668;
long long m;
template <const int T>
class modint {
 public:
  int dat;
  modint() { dat = 0; }
  modint(int x) { dat = x; }
  modint(long long x) { dat = x % T; }
  modint<T> operator+(const modint<T> &t) const {
    modint ret(dat + t.dat);
    if (ret.dat >= T) ret.dat -= T;
    return ret;
  }
  modint<T> operator-(const modint<T> &t) const {
    modint ret(dat - t.dat);
    if (ret.dat < 0) ret.dat += T;
    return ret;
  }
  modint<T> operator*(const modint<T> &t) const {
    long long tmp = 1ll * dat * t.dat;
    return modint<T>(tmp);
  }
  modint<T> operator^(int t) const {
    modint<T> ret(1), a = *this;
    while (t) {
      if (t & 1) ret = ret * a;
      a = a * a;
      t >>= 1;
    }
    return ret;
  }
};
modint<mod> s2[1000010], s4[1000010], s6[1000010];
int main() {
  scanf("%lld", &m);
  for (long long i = 1; i * i <= m; i++) {
    s2[i] = s2[i - 1] + modint<mod>(i * i);
    s4[i] = s4[i - 1] + (modint<mod>(i) ^ 4);
    s6[i] = s6[i - 1] + (modint<mod>(i) ^ 6);
  }
  modint<mod> ans, tm(m);
  modint<mod> S = tm * (tm + 1) * (tm + 2);
  for (long long i = 0; i * i <= m; i++) {
    modint<mod> x(i);
    long long ymax = sqrt(m - i * i) + 1e-7;
    modint<mod> cur =
        (S * ymax + (x ^ 6) * ymax * 2 + s2[ymax] * (x ^ 4) * 6 +
         s4[ymax] * (x ^ 2) * 6 + s6[ymax] * 2 -
         (tm + 2) * ((x ^ 4) * ymax + x * x * s2[ymax] * 2 + s4[ymax]) * 3 +
         (tm * 3 + 4) * (x * x * ymax + s2[ymax])) *
            2 +
        S + (x ^ 6) * 2 + (tm * 3 + 4) * x * x - (tm + 2) * (x ^ 4) * 3;
    if (i == 0)
      ans = ans + cur;
    else
      ans = ans + cur * 2;
  }
  printf("%d\n", (ans * iv6).dat);
  return 0;
}
