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 n, m;
long long a[100005], sum[100005][6], C[6][6];
char op[5];
class segment_tree {
 public:
  int l, r;
  long long sum[6], set;
} st[1 << 18];
void push_up(int i) {
  for (int j = 0; j < 6; ++j)
    st[i].sum[j] = (st[i << 1].sum[j] + st[i << 1 | 1].sum[j]) % 1000000007;
}
void init_st(int i, int l, int r) {
  st[i].l = l;
  st[i].r = r;
  st[i].set = -1;
  if (l < r) {
    int mid = (l + r) >> 1;
    init_st(i << 1, l, mid);
    init_st(i << 1 | 1, mid + 1, r);
    push_up(i);
  } else
    for (int j = 0; j < 6; ++j)
      st[i].sum[j] =
          ((a[l] * (sum[l][j] - sum[l - 1][j])) % 1000000007 + 1000000007) %
          1000000007;
}
void push_down(int i) {
  if (st[i].set >= 0) {
    st[i << 1].set = st[i << 1 | 1].set = st[i].set;
    for (int j = 0; j < 6; ++j) {
      st[i << 1].sum[j] =
          ((st[i].set * (sum[st[i << 1].r][j] - sum[st[i << 1].l - 1][j])) %
               1000000007 +
           1000000007) %
          1000000007;
      st[i << 1 | 1].sum[j] = ((st[i].set * (sum[st[i << 1 | 1].r][j] -
                                             sum[st[i << 1 | 1].l - 1][j])) %
                                   1000000007 +
                               1000000007) %
                              1000000007;
    }
    st[i].set = -1;
  }
}
void update(int i, int l, int r, long long x) {
  if (st[i].l >= l && st[i].r <= r) {
    st[i].set = x;
    for (int j = 0; j < 6; ++j)
      st[i].sum[j] =
          ((x * (sum[st[i].r][j] - sum[st[i].l - 1][j])) % 1000000007 +
           1000000007) %
          1000000007;
    return;
  }
  push_down(i);
  int mid = (st[i].l + st[i].r) >> 1;
  if (l <= mid) update(i << 1, l, r, x);
  if (r > mid) update(i << 1 | 1, l, r, x);
  push_up(i);
}
long long query(int i, int l, int r, int k) {
  long long res = 0;
  if (st[i].l >= l && st[i].r <= r) {
    long long t = 1;
    for (int j = 0; j <= k; ++j) {
      res = ((res +
              ((C[k][j] * st[i].sum[k - j]) % 1000000007 * t) % 1000000007) %
                 1000000007 +
             1000000007) %
            1000000007;
      t = (t * (long long)(-l + 1) % 1000000007 + 1000000007) % 1000000007;
    }
    return res;
  }
  push_down(i);
  int mid = (st[i].l + st[i].r) >> 1;
  if (l <= mid) res = (res + query(i << 1, l, r, k)) % 1000000007;
  if (r > mid) res = (res + query(i << 1 | 1, l, r, k)) % 1000000007;
  return res;
}
int main() {
  for (int i = 1; i < 100005; ++i) {
    long long t = 1;
    sum[i][0] = (sum[i - 1][0] + 1) % 1000000007;
    for (int j = 1; j <= 5; ++j) {
      t = (t * (long long)i) % 1000000007;
      sum[i][j] = (sum[i - 1][j] + t) % 1000000007;
    }
  }
  C[0][0] = 1;
  for (int i = 1; i <= 5; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%I64d", a + i);
  init_st(1, 1, n);
  for (int i = 0, l, r, x; i < m; ++i) {
    scanf("%s%d%d%d", op, &l, &r, &x);
    if (op[0] == '=')
      update(1, l, r, x);
    else
      printf("%I64d\n", query(1, l, r, x));
  }
  return 0;
}