Problem: You've got an array, consisting of n integers: a1, a2, ..., an. Your task is to quickly run the queries of two types:

  1. Assign value x to all elements from l to r inclusive. After such query the values of the elements of array al, al + 1, ..., ar become equal to x.
  2. Calculate and print sum <image>, where k doesn't exceed 5. As the value of the sum can be rather large, you should print it modulo 1000000007 (109 + 7).

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105), showing, how many numbers are in the array and the number of queries, correspondingly. The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 109) — the initial values of the array elements.

Then m queries follow, one per line:

  1. The assign query has the following format: "<image>", (1 ≤ l ≤ r ≤ n; 0 ≤ x ≤ 109).
  2. The query to calculate the sum has the following format: "<image>", (1 ≤ l ≤ r ≤ n; 0 ≤ k ≤ 5).



All numbers in the input are integers.

Output

For each query to calculate the sum print an integer — the required sum modulo 1000000007 (109 + 7).

Examples

Input

4 5
5 10 2 1
? 1 2 1
= 2 2 0
? 2 4 3
= 1 4 1
? 1 4 5


Output

25
43
1300


Input

3 1
1000000000 1000000000 1000000000
? 1 3 0


Output

999999986

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 100500;
struct node {
  long long l, r, check, num;
  long long sum[6];
};
node g[8 * NMAX];
long long Sum[NMAX][6];
long long C[20][20];
long long N, M, i, j, x, y, k;
char ch;
long long A[NMAX];
void build(long long a, long long b, long long u) {
  if (a == b) {
    g[u].l = a;
    g[u].r = b;
    g[u].check = 0;
    g[u].sum[0] = A[a];
    for (int i = 1; i < 6; i++) g[u].sum[i] = g[u].sum[i - 1] * a % 1000000007;
    return;
  }
  g[u].l = a;
  g[u].r = b;
  g[u].check = 0;
  long long mid = (a + b) >> 1;
  build(a, mid, 2 * u);
  build(mid + 1, b, 2 * u + 1);
  for (i = 0; i < 6; i++)
    g[u].sum[i] =
        ((long long)((long long)g[2 * u].sum[i] + g[2 * u + 1].sum[i])) %
        1000000007;
}
void update(long long a, long long b, long long u) {
  if (g[u].check) {
    g[2 * u].check = 1;
    g[2 * u].num = g[u].num;
    g[2 * u + 1].check = 1;
    g[2 * u + 1].num = g[u].num;
    for (int i = 0; i < 6; i++)
      g[u].sum[i] =
          (Sum[g[u].r][i] - Sum[g[u].l - 1][i]) * g[u].num % 1000000007;
    g[u].check = 0;
  }
  long long left = g[u].l;
  long long right = g[u].r;
  if (left > b || a > right) return;
  if (a <= left && right <= b) {
    g[u].check = 1;
    g[u].num = k;
    for (int i = 0; i < 6; i++)
      g[u].sum[i] =
          (Sum[g[u].r][i] - Sum[g[u].l - 1][i]) * g[u].num % 1000000007;
    return;
  }
  update(a, b, 2 * u);
  update(a, b, 2 * u + 1);
  for (int i = 0; i < 6; i++)
    g[u].sum[i] =
        ((long long)((long long)g[2 * u].sum[i] + g[2 * u + 1].sum[i])) %
        1000000007;
}
long long getsum(long long a, long long b, long long u, int ind) {
  if (g[u].check) {
    g[2 * u].check = 1;
    g[2 * u].num = g[u].num;
    g[2 * u + 1].check = 1;
    g[2 * u + 1].num = g[u].num;
    for (int i = 0; i < 6; i++)
      g[u].sum[i] =
          (Sum[g[u].r][i] - Sum[g[u].l - 1][i]) * g[u].num % 1000000007;
    g[u].check = 0;
  }
  long long left = g[u].l;
  long long right = g[u].r;
  if (left > b || a > right) return 0;
  if (a <= left && right <= b) return g[u].sum[ind];
  return (long long)((long long)getsum(a, b, 2 * u, ind) +
                     getsum(a, b, 2 * u + 1, ind)) %
         1000000007;
}
long long deg(long long a, long long k) {
  long long h = 1;
  for (long long i = 0; i < k; i++) h = (long long)h * a % 1000000007;
  return h;
}
long long go(long long x, long long y, long long K) {
  if (K == 0) return getsum(x, y, 1, 0);
  long long h = getsum(x, y, 1, K) % 1000000007;
  for (int i = 1; i <= K; i++)
    h -= (long long)((long long)C[K][i] * deg(x - 1, i) % 1000000007) *
         go(x, y, K - i) % 1000000007;
  h += (long long)1000000007 * 1000000007;
  h %= 1000000007;
  return h;
}
int main() {
  scanf("%I64d %I64d\n", &N, &M);
  for (i = 1; i <= N; i++) scanf("%I64d", &A[i]);
  for (i = 0; i <= 10; i++) C[i][0] = 1;
  for (i = 1; i <= 10; i++)
    for (j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
  for (i = 1; i <= N; i++)
    for (k = 0; k <= 5; k++)
      Sum[i][k] = (Sum[i - 1][k] + deg(i, k)) % 1000000007;
  build(1, N, 1);
  scanf("\n");
  while (M--) {
    scanf("%c %I64d %I64d %I64d\n", &ch, &x, &y, &k);
    if (ch == '=') {
      update(x, y, 1);
    } else {
      printf("%I64d\n", go(x, y, k));
    }
  }
}