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;
#pragma comment(linker, "/STACK:1024000000,1024000000")
long long c[10][10], s[100020][6];
void init() {
  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];
  }
  for (int i = 0; i < 100020; ++i) {
    for (int j = 0; j < 6; ++j) {
      s[i][j] = 1;
      for (int k = 0; k < j; ++k) s[i][j] = s[i][j] * i % 1000000007;
    }
  }
  for (int i = 1; i < 100020; ++i)
    for (int j = 0; j < 6; ++j) s[i][j] = (s[i][j] + s[i - 1][j]) % 1000000007;
}
long long sum[100020 << 2][6];
int down[100020 << 2];
void f(int v, int ll, int rr, int i) {
  down[i] = v;
  for (int j = 0; j < 6; ++j)
    sum[i][j] =
        (s[rr][j] - s[ll - 1][j] + 1000000007) % 1000000007 * v % 1000000007;
}
void push_down(int i, int ll, int rr) {
  if (~down[i]) {
    f(down[i], ll, ((ll + rr) >> 1), (i << 1));
    f(down[i], ((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
    down[i] = -1;
  }
}
void push_up(int i) {
  for (int j = 0; j < 6; ++j)
    sum[i][j] = (sum[(i << 1)][j] + sum[((i << 1) | 1)][j]) % 1000000007;
}
void build(int ll, int rr, int i) {
  down[i] = -1;
  if (ll == rr) {
    int v;
    scanf("%d", &v);
    for (int j = 0; j < 6; ++j)
      sum[i][j] =
          (s[rr][j] - s[rr - 1][j] + 1000000007) % 1000000007 * v % 1000000007;
    return;
  }
  build(ll, ((ll + rr) >> 1), (i << 1)),
      build(((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
  push_up(i);
}
void update(int l, int r, int v, int ll, int rr, int i) {
  if (l == ll && r == rr) {
    f(v, ll, rr, i);
    return;
  }
  push_down(i, ll, rr);
  if (r <= ((ll + rr) >> 1))
    update(l, r, v, ll, ((ll + rr) >> 1), (i << 1));
  else if (l > ((ll + rr) >> 1))
    update(l, r, v, ((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
  else
    update(l, ((ll + rr) >> 1), v, ll, ((ll + rr) >> 1), (i << 1)),
        update(((ll + rr) >> 1) + 1, r, v, ((ll + rr) >> 1) + 1, rr,
               ((i << 1) | 1));
  push_up(i);
}
long long query(int l, int r, int p, int v, int ll, int rr, int i) {
  if (l == ll && r == rr) {
    long long ret = 0, tmp = 1;
    for (int j = v; j >= 0; --j) {
      ret = (ret + sum[i][j] * c[v][j] % 1000000007 * tmp % 1000000007 +
             1000000007) %
            1000000007;
      tmp = tmp * (1 - p) % 1000000007;
    }
    return ret;
  }
  push_down(i, ll, rr);
  long long ret;
  if (r <= ((ll + rr) >> 1))
    ret = query(l, r, p, v, ll, ((ll + rr) >> 1), (i << 1));
  else if (l > ((ll + rr) >> 1))
    ret = query(l, r, p, v, ((ll + rr) >> 1) + 1, rr, ((i << 1) | 1));
  else
    ret = (query(l, ((ll + rr) >> 1), p, v, ll, ((ll + rr) >> 1), (i << 1)) +
           query(((ll + rr) >> 1) + 1, r, p, v, ((ll + rr) >> 1) + 1, rr,
                 ((i << 1) | 1))) %
          1000000007;
  push_up(i);
  return ret;
}
int main() {
  init();
  int n, m;
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  while (m--) {
    int L, R, k;
    char ch[5];
    scanf("%s%d%d%d", &ch, &L, &R, &k);
    if (ch[0] == '=')
      update(L, R, k, 1, n, 1);
    else
      printf("%I64d\n", query(L, R, L, k, 1, n, 1));
  }
  return 0;
}