#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e6 + 1;
struct Int {
  int a;
  Int(int a = 0) : a(a) {}
  Int operator+(const Int& x) const { return (a + x.a) % mod; }
  Int operator-(const Int& x) const { return (a - x.a + mod) % mod; }
  Int operator*(const Int& x) const { return 1ll * a * x.a % mod; }
  void show() const { cout << a << endl; }
};
const Int rev2 = 500000004, rev3 = 333333336, rev6 = 166666668;
Int s2[N], s4[N], s6[N];
Int q2(Int i) { return i * i; }
Int q4(Int i) { return i * i * i * i; }
Int q6(Int i) { return i * i * i * i * i * i; }
int main() {
  for (int i = 1; i < N; i++) {
    s2[i] = s2[i - 1] + q2(i);
    s4[i] = s4[i - 1] + q4(i);
    s6[i] = s6[i - 1] + q6(i);
  }
  long long n;
  cin >> n;
  Int ans, nn = n % mod;
  for (int i = 1, m = N; 1ll * i * i <= n; i++) {
    while (1ll * m * m > n - 1ll * i * i) m--;
    ans = ans + (nn * (nn + 1) * (nn + 2) + q2(i) * (nn * 3 + 4) -
                 q4(i) * (nn * 3 + 6) + q6(i) * 2) *
                    (m + 1);
    ans = ans + (nn * 3 + 4 - q2(i) * 2 * (nn * 3 + 6) + q4(i) * 6) * s2[m];
    ans = ans + (Int() - (nn * 3 + 6) + q2(i) * 6) * s4[m];
    ans = ans + s6[m] * 2;
  }
  ans = (ans * 4 + nn * (nn + 1) * (nn + 2)) * rev6;
  ans.show();
  return 0;
}
