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>
int aa;
char ch;
int F() {
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  aa = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - 48;
  return aa;
}
int n, m, l, r, x, y, k, i, j, c[6][6], ans[6], t[100010 << 2][6],
    set[100010 << 2];
char op;
long long sum[100010][6], ret, tmp;
void bt(int o, int l, int r) {
  set[o] = -1;
  if (l == r) {
    t[o][0] = F() % 1000000007;
    for (int i = 1; i <= 5; i++) t[o][i] = 1LL * t[o][i - 1] * l % 1000000007;
    return;
  }
  int mid = l + r >> 1;
  bt(o << 1, l, mid), bt(o << 1 | 1, mid + 1, r);
  for (int i = 0; i <= 5; i++)
    t[o][i] = (t[o << 1][i] + t[o << 1 | 1][i]) % 1000000007;
}
void query(int o, int l, int r) {
  if (x <= l && r <= y) {
    for (int i = 0; i <= 5; i++)
      ans[i] += t[o][i], ans[i] >= 1000000007 ? ans[i] -= 1000000007 : 1;
    return;
  }
  if (set[o] != -1) {
    l <= x ? l = x : 1, y <= r ? r = y : 1;
    for (int i = 0; i <= 5; i++)
      ans[i] +=
          1LL * (sum[r][i] - sum[l - 1][i] + 1000000007) * set[o] % 1000000007,
          ans[i] >= 1000000007 ? ans[i] -= 1000000007 : 1;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid) query(o << 1, l, mid);
  if (mid < y) query(o << 1 | 1, mid + 1, r);
}
void update(int o, int l, int r) {
  if (x <= l && r <= y) {
    set[o] = k;
    for (int i = 0; i <= 5; i++)
      t[o][i] = 1LL * (sum[r][i] - sum[l - 1][i] + 1000000007) * k % 1000000007;
    return;
  }
  int mid = l + r >> 1;
  if (set[o] != -1) {
    set[o << 1] = set[o << 1 | 1] = set[o];
    for (int i = 0; i <= 5; i++)
      t[o << 1][i] = 1LL * (sum[mid][i] - sum[l - 1][i] + 1000000007) * set[o] %
                     1000000007,
             t[o << 1 | 1][i] = 1LL * (sum[r][i] - sum[mid][i] + 1000000007) *
                                set[o] % 1000000007;
    set[o] = -1;
  }
  if (x <= mid) update(o << 1, l, mid);
  if (mid < y) update(o << 1 | 1, mid + 1, r);
  for (int i = 0; i <= 5; i++)
    t[o][i] = (t[o << 1][i] + t[o << 1 | 1][i]) % 1000000007;
}
int main() {
  for (c[0][0] = 1, i = 1; i <= 5; i++)
    for (c[i][0] = 1, j = 1; j <= i; j++)
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  for (n = F(), m = F(), i = 1; i <= n; i++) {
    for (sum[i][0] = 1, j = 1; j <= 5; j++)
      sum[i][j] = sum[i][j - 1] * i % 1000000007;
    for (j = 0; j <= 5; j++)
      sum[i][j] = (sum[i][j] + sum[i - 1][j]) % 1000000007;
  }
  for (bt(1, 1, n); m--;) {
    while (op = getchar(), op != '=' && op != '?')
      ;
    x = F(), y = F(), k = F() % 1000000007;
    if (op == '?') {
      for (i = 0; i <= 5; i++) ans[i] = 0;
      query(1, 1, n);
      for (i = ret = 0, tmp = 1; i <= k;
           i++, tmp = tmp * (x - 1) % 1000000007, ret %= 1000000007)
        if (i & 1)
          ret += 1000000007 -
                 1LL * c[k][i] * tmp % 1000000007 * ans[k - i] % 1000000007;
        else
          ret += 1LL * c[k][i] * tmp % 1000000007 * ans[k - i] % 1000000007;
      ret %= 1000000007, ret < 0 ? ret += 1000000007 : 1;
      printf("%I64d\n", ret);
    } else
      update(1, 1, n);
  }
}