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 long long int N = 1e5 + 3;
const long long int M = 6;
const long long int LOG = 20;
const int MOD = 1e9 + 7;
const long long int INF = 1e18 + 5;
struct node {
  int lazy = -1;
  int pw[M] = {0, 0, 0, 0, 0, 0};
  int sum[M] = {0, 0, 0, 0, 0, 0};
} seg[4 * N];
int n, q, a[N], C[M][M];
inline node merge(node u, node v) {
  node nini;
  for (int i = 0; i <= 5; i++) {
    nini.pw[i] = (u.pw[i] + v.pw[i]) % MOD;
    nini.sum[i] = (u.sum[i] + v.sum[i]) % MOD;
  }
  return nini;
}
void Build(int b = 0, int e = n, int ind = 1) {
  if (b + 1 == e) {
    long long int v = b + 1;
    seg[ind].pw[0] = 1;
    seg[ind].pw[1] = v % MOD;
    seg[ind].pw[2] = v * v % MOD;
    seg[ind].pw[3] = v * v * v % MOD;
    seg[ind].pw[4] = v * v * v % MOD * v % MOD;
    seg[ind].pw[5] = v * v * v % MOD * v % MOD * v % MOD;
    for (int i = 0; i <= 5; i++) {
      seg[ind].sum[i] = 1ll * seg[ind].pw[i] * a[b] % MOD;
    }
    return;
  }
  Build(b, ((b + e) >> 1), (ind << 1));
  Build(((b + e) >> 1), e, ((ind << 1) | 1));
  seg[ind] = merge(seg[(ind << 1)], seg[((ind << 1) | 1)]);
  return;
}
inline void Shift(int ind) {
  if (seg[ind].lazy == -1) return;
  seg[(ind << 1)].lazy = seg[ind].lazy;
  seg[((ind << 1) | 1)].lazy = seg[ind].lazy;
  for (int i = 0; i <= 5; i++) {
    seg[(ind << 1)].sum[i] = 1ll * seg[(ind << 1)].pw[i] * seg[ind].lazy % MOD;
    seg[((ind << 1) | 1)].sum[i] =
        1ll * seg[((ind << 1) | 1)].pw[i] * seg[ind].lazy % MOD;
  }
  seg[ind].lazy = -1;
  return;
}
void Add(int l, int r, int val, int b = 0, int e = n, int ind = 1) {
  if (l <= b && e <= r) {
    seg[ind].lazy = val;
    for (int i = 0; i <= 5; i++) {
      seg[ind].sum[i] = 1ll * seg[ind].pw[i] * val % MOD;
    }
    return;
  }
  Shift(ind);
  if (l < ((b + e) >> 1)) Add(l, r, val, b, ((b + e) >> 1), (ind << 1));
  if (((b + e) >> 1) < r) Add(l, r, val, ((b + e) >> 1), e, ((ind << 1) | 1));
  seg[ind] = merge(seg[(ind << 1)], seg[((ind << 1) | 1)]);
  return;
}
node Get(int l, int r, int b = 0, int e = n, int ind = 1) {
  if (l <= b && e <= r) return seg[ind];
  Shift(ind);
  node L, R;
  if (l < ((b + e) >> 1) && r <= ((b + e) >> 1)) {
    L = Get(l, r, b, ((b + e) >> 1), (ind << 1));
    seg[ind] = merge(seg[(ind << 1)], seg[((ind << 1) | 1)]);
    return L;
  }
  if (((b + e) >> 1) <= l && ((b + e) >> 1) < r) {
    R = Get(l, r, ((b + e) >> 1), e, ((ind << 1) | 1));
    seg[ind] = merge(seg[(ind << 1)], seg[((ind << 1) | 1)]);
    return R;
  }
  L = Get(l, r, b, ((b + e) >> 1), (ind << 1));
  R = Get(l, r, ((b + e) >> 1), e, ((ind << 1) | 1));
  seg[ind] = merge(seg[(ind << 1)], seg[((ind << 1) | 1)]);
  return merge(L, R);
}
inline void Pre() {
  C[0][0] = 1;
  for (int i = 1; i < M; i++) {
    C[0][i] = 1;
    for (int j = 1; j <= i; j++) {
      C[j][i] = (C[j - 1][i - 1] + C[j][i - 1]) % MOD;
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  Pre();
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  Build();
  while (q--) {
    char type;
    long long int l, r, x;
    cin >> type >> l >> r >> x;
    l--;
    if (type == '=') {
      Add(l, r, x);
    } else {
      node res = Get(l, r);
      long long int ans = 0;
      l++;
      for (int i = 0; i <= x; i++) {
        for (int j = 0; i + j <= x; j++) {
          long long int add = 0;
          if (i == 0)
            add = 1;
          else if (i == 1)
            add = l;
          else if (i == 2)
            add = l * l;
          else if (i == 3)
            add = l * l * l % MOD;
          else if (i == 4)
            add = l * l * l % MOD * l % MOD;
          else if (i == 5)
            add = l * l * l % MOD * l % MOD * l % MOD;
          if (i & 1)
            ans = (ans - 1ll * C[i][x] * C[j][x - i] % MOD * add % MOD *
                             res.sum[j] % MOD) %
                  MOD;
          else
            ans = (ans + 1ll * C[i][x] * C[j][x - i] % MOD * add % MOD *
                             res.sum[j] % MOD) %
                  MOD;
        }
      }
      ans = (ans + MOD) % MOD;
      cout << ans << '\n';
    }
  }
  return 0;
}