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;
long long fpow(int a, int n) {
  long long tmp = a, ans = 1;
  while (n) {
    if (n & 1) ans = ans * tmp % 1000000007;
    tmp = tmp * tmp % 1000000007, n >>= 1;
  }
  return ans;
}
char s[2];
int n, m, c[6][6], t[6][1000000 + 5], lazy[1000000 + 5], sum[6][1000000 + 5],
    ss[6], a[1000000 + 5], ll, rr, d;
void update(int p) {
  for (int i = 0; i <= 5; i++)
    t[i][p] = t[i][((p) << 1)] + t[i][((p) << 1 | 1)], t[i][p] %= 1000000007;
}
void change(int p, int l, int r, int x) {
  lazy[p] = x;
  for (int i = 0; i <= 5; i++)
    t[i][p] = x * 1ll * (sum[i][r] - sum[i][l - 1]) % 1000000007;
}
void pushdown(int p, int l, int r) {
  if (lazy[p] != -1) {
    int mid = l + r >> 1;
    change(((p) << 1), l, mid, lazy[p]);
    change(((p) << 1 | 1), mid + 1, r, lazy[p]);
    lazy[p] = -1;
  }
}
void build(int l, int r, int p) {
  lazy[p] = -1;
  if (l == r) {
    for (int i = 0; i <= 5; i++)
      t[i][p] =
          i == 0 ? a[l] : a[l] * 1ll * (sum[i][l] - sum[i][l - 1]) % 1000000007;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, ((p) << 1));
  build(mid + 1, r, ((p) << 1 | 1));
  update(p);
}
void query(int l, int r, int p) {
  if (ll <= l && r <= rr) {
    for (int i = 0; i <= 5; i++) ss[i] += t[i][p], ss[i] %= 1000000007;
    return;
  }
  pushdown(p, l, r);
  int mid = l + r >> 1;
  if (ll <= mid) query(l, mid, ((p) << 1));
  if (rr > mid) query(mid + 1, r, ((p) << 1 | 1));
}
void modify(int l, int r, int p) {
  if (ll <= l && r <= rr) {
    change(p, l, r, d);
    return;
  }
  pushdown(p, l, r);
  int mid = l + r >> 1;
  if (ll <= mid) modify(l, mid, ((p) << 1));
  if (rr > mid) modify(mid + 1, r, ((p) << 1 | 1));
  update(p);
}
int main() {
  for (int i = 0; i <= 5; i++) {
    for (int j = 0; j <= i; j++) {
      if (!i) c[i][j] = 1;
      if (i) c[i][j] += c[i - 1][j];
      if (j) c[i][j] += c[i - 1][j - 1];
    }
  }
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) sum[0][i] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] = sum[i - 1][j] * 1ll * j % 1000000007;
  for (int i = 0; i <= 5; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] += sum[i][j - 1], sum[i][j] %= 1000000007;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  build(1, n, 1);
  while (m--) {
    scanf("%s", s);
    if (s[0] == '?') {
      scanf("%d%d%d", &ll, &rr, &d);
      memset(ss, 0, sizeof(ss));
      query(1, n, 1);
      int ans = 0;
      for (int i = 0; i <= d; i++) {
        ans += ss[i] * 1ll * c[d][i] % 1000000007 * fpow(1 - ll, d - i) %
               1000000007;
        ans %= 1000000007;
      }
      if (ans < 0) ans += 1000000007;
      printf("%d\n", ans);
    } else {
      scanf("%d%d%d", &ll, &rr, &d);
      modify(1, n, 1);
    }
  }
  return 0;
}