#include <bits/stdc++.h>
using namespace std;
long long n, m, M, a[1000005], b[1000005], c[1000005], i, j, k, ans;
int main() {
  cin >> n;
  for (i = 1; i < 1000005; i++) {
    a[i] = (a[i - 1] + i * i) % 1000000007;
    b[i] = (b[i - 1] + i * i * i % 1000000007 * i) % 1000000007;
    c[i] = (c[i - 1] +
            i * i * i % 1000000007 * i % 1000000007 * i % 1000000007 * i) %
           1000000007;
  }
  for (m = 1; m * m <= n; m++)
    ;
  m--;
  M = n % 1000000007;
  for (i = 1, j = m; i <= m; i++) {
    for (; i * i + j * j > n; j--)
      ;
    k = i * i % 1000000007;
    ans =
        (ans +
         (1 + M - k) * (2 + M - k) % 1000000007 * (M + 2 * k) % 1000000007 *
             (j + 1) +
         (4 + 3 * M - 12 * k % 1000000007 - 6 * M * k % 1000000007 + 6 * k * k +
          2 * 1000000007) %
             1000000007 * a[j] +
         (6 * k - 3 * M % 1000000007 - 6 + 2 * 1000000007) % 1000000007 * b[j] +
         2 * c[j]) %
        1000000007;
  }
  ans = ans * 2 % 1000000007 * (1000000007 + 1) / 3 % 1000000007;
  ans = (ans + M * (M + 1) % 1000000007 * (M + 2) % 1000000007 *
                   (1000000007 + 1) / 6) %
        1000000007;
  cout << ans << endl;
}
