#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long sqrt(long long x) {
  long long i = 0;
  long long j = 10000000;
  while (i != j) {
    long long m = (i + j + 1) / 2;
    if (m * m > x)
      j = m - 1;
    else
      i = m;
  }
  return i;
}
long long exp(long long a, long long b) {
  if (b == 0)
    return 1;
  else {
    long long x = exp(a, b / 2);
    if (b % 2 == 0)
      return (x * x) % mod;
    else {
      x = (x * x) % mod;
      return (a * x) % mod;
    }
  }
}
int main() {
  long long m;
  cin >> m;
  long long s = sqrt(m);
  long long mom2[s + 1], mom4[s + 1], mom6[s + 1];
  long long total = 0;
  for (long long i = 0; i < s + 1; i++) {
    mom2[i] = 0;
    mom4[i] = 0;
    mom6[i] = 0;
  }
  for (long long i = 1; i < s + 1; i++) {
    mom2[i] = (mom2[i - 1] + exp(i, 2)) % mod;
    mom4[i] = (mom4[i - 1] + exp(i, 4)) % mod;
    mom6[i] = (mom6[i - 1] + exp(i, 6)) % mod;
  }
  for (long long a = 0; a <= s; a++) {
    long long mx = sqrt(m - a * a);
    long long running = 0;
    long long current1 = (m - a * a + 1) % mod;
    long long current2 = current1 + 1;
    long long current3;
    current1 = (current1 * current2) % mod;
    current2 = m + 2 * a * a;
    current2 = current2 % mod;
    current1 = (current1 * current2) % mod;
    running += ((2 * mx + 1) * current1) % mod;
    current2 = (m - a * a + 1) % mod;
    current1 = ((current2 + 1) * current2) % mod;
    current1 = (current1 * 2) % mod;
    current3 = (m + 2 * a * a) % mod;
    current2 = (2 * current2 + 1) % mod;
    current2 = (current2 * current3) % mod;
    current2 = mod - current2;
    current1 = (current1 + current2) % mod;
    current2 = (2 * mom2[mx]) % mod;
    current1 = (current1 * current2) % mod;
    running = (running + current1) % mod;
    current2 = (a * a * 6) % mod - (3 * m) % mod - 6;
    while (current2 < 0) current2 += mod;
    current3 = (2 * mom4[mx]) % mod;
    current1 = (current2 * current3) % mod;
    running = (running + current1) % mod;
    current1 = (2 * mom6[mx]) % mod;
    running = (running + 2 * current1) % mod;
    if (a == 0)
      total = (total + running) % mod;
    else
      total = (total + 2 * running) % mod;
  }
  total = total * exp(6, mod - 2);
  total = total % mod;
  cout << total << endl;
  return 0;
}
