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 N = 100005;
struct Seg_tree {
  int left, right;
  long long lazy, sum[6];
} L[N << 2];
int n, q, a[N];
long long fac[N][6];
long long sum[N][6] = {0};
long long c[6][6];
long long s[N][6];
void Init() {
  for (int i = 0; i < 6; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]);
  }
  for (int i = 1; i <= n; i++) {
    fac[i][0] = 1;
    sum[i][0] = i;
    s[i][0] = 1;
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j <= n; j++) {
      fac[j][i] = (fac[j][i - 1] * j) % 1000000007;
      sum[j][i] = (sum[j - 1][i] + fac[j][i]) % 1000000007;
      s[j][i] =
          ((s[j][i - 1] * (1 - j)) % 1000000007 + 1000000007) % 1000000007;
    }
  }
}
void push_up(int step) {
  for (int i = 0; i < 6; i++)
    L[step].sum[i] =
        (L[(step << 1)].sum[i] + L[(step << 1 | 1)].sum[i]) % 1000000007;
}
void update(int step, int l, int r, int x);
void push_down(int step) {
  if (L[step].lazy != -1) {
    int l = L[step].left, r = L[step].right, m = (l + r) >> 1;
    update((step << 1), l, m, L[step].lazy);
    update((step << 1 | 1), m + 1, r, L[step].lazy);
    L[step].lazy = -1;
  }
}
void bulid(int step, int l, int r) {
  L[step].left = l;
  L[step].right = r;
  L[step].lazy = -1;
  if (l == r) {
    for (int i = 0; i < 6; i++)
      L[step].sum[i] = (a[l] * fac[l][i]) % 1000000007;
    return;
  }
  int m = (l + r) >> 1;
  bulid((step << 1), l, m);
  bulid((step << 1 | 1), m + 1, r);
  push_up(step);
}
void update(int step, int l, int r, int x) {
  if (L[step].left == l && L[step].right == r) {
    L[step].lazy = x;
    for (int i = 0; i < 6; i++) {
      long long tmp =
          ((sum[r][i] - sum[l - 1][i]) % 1000000007 + 1000000007) % 1000000007;
      L[step].sum[i] = (tmp * x) % 1000000007;
    }
    return;
  }
  push_down(step);
  int m = (L[step].left + L[step].right) >> 1;
  if (r <= m)
    update((step << 1), l, r, x);
  else if (l > m)
    update((step << 1 | 1), l, r, x);
  else {
    update((step << 1), l, m, x);
    update((step << 1 | 1), m + 1, r, x);
  }
  push_up(step);
}
long long query(int step, int l, int r, int k) {
  if (L[step].left == l && L[step].right == r) return L[step].sum[k];
  int m = (L[step].left + L[step].right) >> 1;
  push_down(step);
  if (r <= m)
    return query((step << 1), l, r, k);
  else if (l > m)
    return query((step << 1 | 1), l, r, k);
  else
    return (query((step << 1), l, m, k) + query((step << 1 | 1), m + 1, r, k)) %
           1000000007;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  Init();
  bulid(1, 1, n);
  while (q--) {
    char ope[5];
    int l, r, k;
    scanf("%s%d%d%d", &ope, &l, &r, &k);
    if (ope[0] == '=')
      update(1, l, r, k);
    else {
      long long ans = 0;
      for (int i = 0; i <= k; i++)
        ans = ((((query(1, l, r, i) * c[k][i]) % 1000000007 * s[l][k - i]) %
                    1000000007 +
                ans) %
                   1000000007 +
               1000000007) %
              1000000007;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}