#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e6 + 100, inv2 = (mod + 1) >> 1,
          inv6 = (mod + 1) / 6;
long long n, nn, Ans, s1[N], s2[N], s3[N];
void Inc(long long &x, long long y) { x += y, x = x >= mod ? x - mod : x; }
int main() {
  scanf("%lld", &n);
  nn = n % mod;
  for (long long x = 1, tp = 1; x * x <= n; ++x, tp = x * x % mod) {
    s1[x] = s1[x - 1], s2[x] = s2[x - 1], s3[x] = s3[x - 1], Inc(s1[x], tp),
    Inc(s2[x], tp * tp % mod), Inc(s3[x], tp * tp % mod * tp % mod);
  }
  for (long long x = 0; x * x <= n; ++x) {
    long long y = sqrt(n - x * x), tp = x * x % mod;
    long long tmp = 0;
    Inc(tmp, (nn + 1) * inv2 % mod * (nn * nn % mod + nn + tp - tp * tp % mod) %
                 mod * (2 * y + 1) % mod);
    Inc(tmp, mod - (nn + 1) * inv2 % mod * (2 * tp + mod - 1) % mod * s1[y] %
                       mod * 2 % mod);
    Inc(tmp, mod - (nn + 1) % mod * inv2 % mod * s2[y] % mod * 2 % mod);
    Inc(tmp, inv6 * (6 * tp % mod * tp % mod - 6 * tp % mod + mod + 1) % mod *
                 s1[y] % mod * 2 % mod);
    Inc(tmp, inv6 * (6 * tp % mod + mod - 3) % mod * s2[y] % mod * 2 % mod);
    Inc(tmp, inv6 * (4 * s3[y]) % mod);
    Inc(tmp, inv6 *
                 (2 * tp % mod * tp % mod * tp % mod - 3 * tp * tp % mod + mod +
                  tp) %
                 mod * (2 * y + 1) % mod);
    Inc(tmp, mod - (2 * nn + 1) * inv6 % mod * nn % mod * (nn + 1) % mod *
                       (2 * y + 1) % mod);
    if (x) Inc(tmp, tmp);
    Inc(Ans, tmp);
  }
  printf("%lld", Ans);
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

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>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e6 + 100, inv2 = (mod + 1) >> 1,
          inv6 = (mod + 1) / 6;
long long n, nn, Ans, s1[N], s2[N], s3[N];
void Inc(long long &x, long long y) { x += y, x = x >= mod ? x - mod : x; }
int main() {
  scanf("%lld", &n);
  nn = n % mod;
  for (long long x = 1, tp = 1; x * x <= n; ++x, tp = x * x % mod) {
    s1[x] = s1[x - 1], s2[x] = s2[x - 1], s3[x] = s3[x - 1], Inc(s1[x], tp),
    Inc(s2[x], tp * tp % mod), Inc(s3[x], tp * tp % mod * tp % mod);
  }
  for (long long x = 0; x * x <= n; ++x) {
    long long y = sqrt(n - x * x), tp = x * x % mod;
    long long tmp = 0;
    Inc(tmp, (nn + 1) * inv2 % mod * (nn * nn % mod + nn + tp - tp * tp % mod) %
                 mod * (2 * y + 1) % mod);
    Inc(tmp, mod - (nn + 1) * inv2 % mod * (2 * tp + mod - 1) % mod * s1[y] %
                       mod * 2 % mod);
    Inc(tmp, mod - (nn + 1) % mod * inv2 % mod * s2[y] % mod * 2 % mod);
    Inc(tmp, inv6 * (6 * tp % mod * tp % mod - 6 * tp % mod + mod + 1) % mod *
                 s1[y] % mod * 2 % mod);
    Inc(tmp, inv6 * (6 * tp % mod + mod - 3) % mod * s2[y] % mod * 2 % mod);
    Inc(tmp, inv6 * (4 * s3[y]) % mod);
    Inc(tmp, inv6 *
                 (2 * tp % mod * tp % mod * tp % mod - 3 * tp * tp % mod + mod +
                  tp) %
                 mod * (2 * y + 1) % mod);
    Inc(tmp, mod - (2 * nn + 1) * inv6 % mod * nn % mod * (nn + 1) % mod *
                       (2 * y + 1) % mod);
    if (x) Inc(tmp, tmp);
    Inc(Ans, tmp);
  }
  printf("%lld", Ans);
  return 0;
}

```