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 = 100100;
const int MOD = 1000000007;
struct data {
  int l, r, mid, mark;
  long long sum[6];
};
int n, m, a[maxn];
data tr[maxn * 5];
long long G[maxn][6], C[6][6], ans[6];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("\n");
  C[0][0] = 1;
  for (int i = 1; i < 6; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  long long tmp;
  for (int i = 1; i <= n; ++i) {
    tmp = 1;
    for (int j = 0; j < 6; ++j) {
      G[i][j] = (G[i - 1][j] + tmp) % MOD;
      tmp = tmp * i % MOD;
    }
  }
}
void change(int id, int l, int r, int z) {
  for (int i = 0; i < 6; ++i)
    tr[id].sum[i] = ((G[r][i] - G[l - 1][i]) % MOD + MOD) % MOD * z % MOD;
}
void pushdown(int id) {
  if (tr[id].mark != -1) {
    tr[id * 2].mark = tr[id * 2 + 1].mark = tr[id].mark;
    change(id * 2, tr[id * 2].l, tr[id * 2].r, tr[id].mark);
    change(id * 2 + 1, tr[id * 2 + 1].l, tr[id * 2 + 1].r, tr[id].mark);
    tr[id].mark = -1;
  }
}
void pushup(int id) {
  for (int i = 0; i < 6; ++i)
    tr[id].sum[i] = (tr[id * 2].sum[i] + tr[id * 2 + 1].sum[i]) % MOD;
}
void build(int id, int l, int r) {
  int mid = (l + r) / 2;
  tr[id].l = l;
  tr[id].r = r;
  tr[id].mid = mid;
  tr[id].mark = -1;
  if (l == r) {
    change(id, l, r, a[l]);
    return;
  }
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  pushup(id);
}
void query(int id, int l, int r, long long dat[6]) {
  if ((tr[id].l == l) && (tr[id].r == r)) {
    for (int i = 0; i < 6; ++i) dat[i] = tr[id].sum[i];
    return;
  }
  pushdown(id);
  if (r <= tr[id].mid)
    query(id * 2, l, r, dat);
  else if (l > tr[id].mid)
    query(id * 2 + 1, l, r, dat);
  else {
    long long t1[6], t2[6];
    query(id * 2, l, tr[id].mid, t1);
    query(id * 2 + 1, tr[id].mid + 1, r, t2);
    for (int i = 0; i < 6; ++i) dat[i] = (t1[i] + t2[i]) % MOD;
  }
  pushup(id);
}
void ins(int id, int l, int r, int z) {
  if ((tr[id].l == l) && (tr[id].r == r)) {
    tr[id].mark = z;
    change(id, l, r, z);
    return;
  }
  pushdown(id);
  if (r <= tr[id].mid)
    ins(id * 2, l, r, z);
  else if (l > tr[id].mid)
    ins(id * 2 + 1, l, r, z);
  else {
    ins(id * 2, l, tr[id].mid, z);
    ins(id * 2 + 1, tr[id].mid + 1, r, z);
  }
  pushup(id);
}
void work() {
  int x, y, z;
  long long tmp[6], s;
  char ch;
  for (int i = 1; i <= m; ++i) {
    scanf("%c%d%d%d\n", &ch, &x, &y, &z);
    if (ch == '?') {
      query(1, x, y, tmp);
      for (int k = 0; k < 6; ++k) {
        ans[k] = tmp[k];
        s = 1;
        for (int i = 1; i <= k; ++i) {
          s = s * (x - 1) % MOD;
          ans[k] =
              ((ans[k] - C[k][i] * s % MOD * ans[k - i]) % MOD + MOD) % MOD;
        }
      }
      printf("%I64d\n", ans[z]);
    } else
      ins(1, x, y, z);
  }
}
int main() {
  init();
  build(1, 1, n);
  work();
}