933_D. A Creative Cutout_16965
Everything red frightens Nian the monster. So do red paper and... you, red on Codeforces, potential or real.

Big Banban has got a piece of paper with endless lattice points, where lattice points form squares with the same area. His most favorite closed shape is the circle because of its beauty and simplicity. Once he had obtained this piece of paper, he prepares it for paper-cutting.

<image>

He drew n concentric circles on it and numbered these circles from 1 to n such that the center of each circle is the same lattice point and the radius of the k-th circle is <image> times the length of a lattice edge.

Define the degree of beauty of a lattice point as the summation of the indices of circles such that this lattice point is inside them, or on their bounds. Banban wanted to ask you the total degree of beauty of all the lattice points, but changed his mind.

Defining the total degree of beauty of all the lattice points on a piece of paper with n circles as f(n), you are asked to figure out <image>.

Input

The first line contains one integer m (1 ≤ m ≤ 1012).

Output

In the first line print one integer representing <image>.

Examples

Input

5


Output

387


Input

233


Output

788243189

Note

A piece of paper with 5 circles is shown in the following.

<image>

There are 5 types of lattice points where the degree of beauty of each red point is 1 + 2 + 3 + 4 + 5 = 15, the degree of beauty of each orange point is 2 + 3 + 4 + 5 = 14, the degree of beauty of each green point is 4 + 5 = 9, the degree of beauty of each blue point is 5 and the degree of beauty of each gray point is 0. Therefore, f(5) = 5·15 + 4·14 + 4·9 + 8·5 = 207.

Similarly, f(1) = 5, f(2) = 23, f(3) = 50, f(4) = 102 and consequently <image>.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mod = 1e9 + 7, N = 1e6 + 1;
const int rev2 = 500000004, rev3 = 333333336, rev6 = 1ll * rev2 * rev3 % mod;
int s2[N], s4[N], s6[N];
LL q2(LL i) {
  i %= mod;
  return i * i % mod;
}
LL q4(LL i) {
  i %= mod;
  return i * i % mod * i % mod * i % mod;
}
LL q6(LL i) {
  i %= mod;
  return i * i % mod * i % mod * i % mod * i % mod * i % mod;
}
int main() {
  for (int i = 1; i < N; i++) {
    s2[i] = (s2[i - 1] + q2(i)) % mod;
    s4[i] = (s4[i - 1] + q4(i)) % mod;
    s6[i] = (s6[i - 1] + q6(i)) % mod;
  }
  LL n, ans = 0;
  cin >> n;
  LL 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) % mod * (nn + 2) % mod + q2(i) * (3 * nn + 4) % mod -
            q4(i) * (3 * nn + 6) % mod + mod + 2 * q6(i)) %
               mod * (m + 1)) %
          mod;
    ans =
        (ans + (3 * nn + 4 - q2(i) * 2 * (3 * nn + 6) % mod + mod + 6 * q4(i)) %
                   mod * s2[m]) %
        mod;
    ans = (ans + (-(3 * nn + 6) % mod + mod + 6 * q2(i)) % mod * s4[m]) % mod;
    ans = (ans + 2 * s6[m]) % mod;
  }
  ans = (ans * 4 % mod + nn * (nn + 1) % mod * (nn + 2) % mod) * rev6 % mod;
  cout << ans << endl;
  return 0;
}
