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 int maxn = 1e5 + 233;
const int T = 1e9 + 7;
bool flag[maxn * 4];
long long ch[6][maxn * 4], sum[6][maxn * 4];
int a[maxn], val[maxn * 4], c[6][6];
void build(int l, int r, int cur) {
  if (l == r) {
    long long buf = 1;
    for (int i = 0; i <= 5; i++) {
      sum[i][cur] = buf;
      ch[i][cur] = buf * a[l] % T;
      buf *= l;
      buf %= T;
    }
    return;
  }
  int lc = cur << 1, rc = lc | 1, mid = (l + r) >> 1;
  build(l, mid, lc);
  build(mid + 1, r, rc);
  for (int i = 0; i <= 5; i++) {
    ch[i][cur] = (ch[i][lc] + ch[i][rc]) % T;
    sum[i][cur] = (sum[i][lc] + sum[i][rc]) % T;
  }
  return;
}
void Push_down(int cur) {
  int lc = cur << 1, rc = lc | 1;
  flag[cur] = 0;
  flag[lc] = flag[rc] = 1;
  val[lc] = val[rc] = val[cur];
  for (int i = 0; i <= 5; i++) {
    ch[i][lc] = sum[i][lc] * val[lc] % T;
    ch[i][rc] = sum[i][rc] * val[rc] % T;
    ch[i][cur] = (ch[i][lc] + ch[i][rc]) % T;
  }
  return;
}
void update(int l, int r, int cur, int x, int y, int v) {
  if (l > y || r < x) return;
  if (x <= l && r <= y) {
    flag[cur] = 1;
    val[cur] = v;
    for (int i = 0; i <= 5; i++) ch[i][cur] = sum[i][cur] * v % T;
    return;
  }
  if (flag[cur]) Push_down(cur);
  int lc = cur << 1, rc = lc | 1, mid = (l + r) >> 1;
  update(l, mid, lc, x, y, v);
  update(mid + 1, r, rc, x, y, v);
  for (int i = 0; i <= 5; i++) ch[i][cur] = (ch[i][lc] + ch[i][rc]) % T;
  return;
}
int query(int i, int l, int r, int cur, int x, int y) {
  if (l > y || r < x) return 0;
  if (x <= l && r <= y) return ch[i][cur];
  if (flag[cur]) Push_down(cur);
  int lc = cur << 1, rc = lc | 1, mid = (l + r) >> 1;
  return (query(i, l, mid, lc, x, y) + query(i, mid + 1, r, rc, x, y)) % T;
}
int main() {
  for (int i = 0; i <= 5; i++) c[i][0] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, n, 1);
  getchar();
  for (int i = 1; i <= m; i++) {
    char op = getchar();
    if (op == '=') {
      int l, r, v;
      scanf("%d%d%d", &l, &r, &v);
      update(1, n, 1, l, r, v);
    } else {
      int l, r, k;
      int ans = 0;
      long long buf = 1;
      scanf("%d%d%d", &l, &r, &k);
      for (int j = k; j >= 0; j--) {
        ans += (query(j, 1, n, 1, l, r) * buf % T) * c[k][j] % T;
        ans %= T;
        buf *= (1 - l);
        buf %= T;
      }
      if (ans < 0) ans += T;
      printf("%d\n", ans);
    }
    getchar();
  }
  return 0;
}