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>
const long long m = 1000000007LL;
int N, Q;
long long sum[6][100005 << 2];
long long lazy[6][100005 << 2];
long long f[6][100005];
int pascal[6][6] = {{1, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0},
                    {1, 2, 1, 0, 0, 0}, {1, 3, 3, 1, 0, 0},
                    {1, 4, 6, 4, 1, 0}, {1, 5, 10, 10, 5, 1}};
void PushUp(int now) {
  for (int i = 0; i < 6; i++)
    sum[i][now] = (sum[i][now << 1] + sum[i][now << 1 | 1]) % m;
}
void PushDown(int now, int L, int M, int R) {
  for (int i = 0; i < 6; i++) {
    if (lazy[i][now] != -1LL) {
      lazy[i][now << 1] = lazy[i][now << 1 | 1] = lazy[i][now];
      sum[i][now << 1] = (lazy[i][now] * ((f[i][M] - f[i][L - 1] + m) % m)) % m;
      sum[i][now << 1 | 1] = (lazy[i][now] * ((f[i][R] - f[i][M] + m) % m)) % m;
      lazy[i][now] = -1LL;
    }
  }
}
void build(int L, int R, int now) {
  for (int i = 0; i < 6; i++) lazy[i][now] = -1LL;
  if (L == R) {
    long long t;
    scanf(" %I64d", &t);
    for (int i = 0; i < 6; i++)
      sum[i][now] = (t * ((f[i][R] - f[i][L - 1] + m) % m)) % m;
    return;
  }
  int M = (L + R) >> 1;
  build(L, M, now << 1);
  build(M + 1, R, now << 1 | 1);
  PushUp(now);
}
void update(int l, int r, long long num, int L, int R, int now) {
  if (l <= L && R <= r) {
    for (int i = 0; i < 6; i++) {
      lazy[i][now] = num;
      sum[i][now] = (num * ((f[i][R] - f[i][L - 1] + m) % m)) % m;
    }
    return;
  }
  int M = (L + R) >> 1;
  PushDown(now, L, M, R);
  if (l <= M) update(l, r, num, L, M, now << 1);
  if (M < r) update(l, r, num, M + 1, R, now << 1 | 1);
  PushUp(now);
}
long long query(int l, int r, int lv, int L, int R, int now) {
  if (l <= L && R <= r) {
    return sum[lv][now];
  }
  int M = (L + R) >> 1;
  long long ret = 0LL;
  PushDown(now, L, M, R);
  if (l <= M) ret = (ret + query(l, r, lv, L, M, now << 1)) % m;
  if (M < r) ret = (ret + query(l, r, lv, M + 1, R, now << 1 | 1)) % m;
  return ret;
}
int main() {
  f[0][0] = f[1][0] = f[2][0] = f[3][0] = f[4][0] = f[5][0] = 0;
  for (int i = 1; i <= 100000; i++) {
    long long t = 1LL;
    for (int j = 0; j < 6; j++) {
      f[j][i] = (f[j][i - 1] + t) % m;
      t = (t * i) % m;
    }
  }
  int a, b, k;
  char s[100];
  long long t, v;
  while (scanf(" %d %d", &N, &Q) != EOF) {
    build(1, N, 1);
    while (Q--) {
      scanf(" %s%d%d%d", s, &a, &b, &k);
      if (s[0] == '=') {
        update(a, b, (long long)k, 1, N, 1);
      } else {
        t = 0LL, v = 1LL;
        for (int i = k; i >= 0; i--) {
          t = (t +
               ((((query(a, b, i, 1, N, 1) * pascal[k][k - i]) % m) * v) % m)) %
              m;
          v = (v * ((1 - a + m) % m)) % m;
        }
        printf("%I64d\n", t);
      }
    }
  }
  return 0;
}