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 mod = 1000000007;
int n, m, C[6][6], mark[6][600002];
long long sum[6][600002], sf[6][100001];
long long quickpow(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) ret = ret * x % mod;
  return ret;
}
void setmark(int d, int ind, int l, int r, int v) {
  mark[d][ind] = v;
  sum[d][ind] = v * (sf[d][r] - sf[d][l - 1]) % mod;
}
void pushdown(int d, int ind, int l, int r) {
  if (mark[d][ind] == -1) return;
  setmark(d, ind << 1, l, l + r >> 1, mark[d][ind]);
  setmark(d, ind << 1 ^ 1, (l + r >> 1) + 1, r, mark[d][ind]);
  mark[d][ind] = -1;
}
void modify(int d, int ind, int l, int r, int left, int right, int v) {
  if (l >= left && r <= right) {
    setmark(d, ind, l, r, v);
    return;
  }
  if (l > right || r < left) return;
  pushdown(d, ind, l, r);
  modify(d, ind << 1, l, l + r >> 1, left, right, v);
  modify(d, ind << 1 ^ 1, (l + r >> 1) + 1, r, left, right, v);
  sum[d][ind] = (sum[d][ind << 1] + sum[d][ind << 1 ^ 1]) % mod;
}
long long ask(int d, int ind, int l, int r, int left, int right) {
  if (l >= left && r <= right) return sum[d][ind];
  if (l > right || r < left) return 0;
  pushdown(d, ind, l, r);
  return (ask(d, ind << 1, l, l + r >> 1, left, right) +
          ask(d, ind << 1 ^ 1, (l + r >> 1) + 1, r, left, right)) %
         mod;
}
int main() {
  for (int i = 0; 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];
  }
  for (int i = 0; i <= 5; i++)
    for (int j = 1; j <= 100000; j++)
      sf[i][j] = (sf[i][j - 1] + quickpow(j, i)) % mod;
  memset(mark, -1, sizeof(mark));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    for (int j = 0; j <= 5; j++) modify(j, 1, 1, n, i, i, a);
  }
  while (m--) {
    int l, r, v;
    char type[3];
    scanf("%s%d%d%d", type, &l, &r, &v);
    if (type[0] == '=')
      for (int j = 0; j <= 5; j++) modify(j, 1, 1, n, l, r, v);
    else {
      long long ans = 0;
      for (int j = 0; j <= v; j++)
        ans += C[v][j] * quickpow(-l + 1 + mod, v - j) % mod *
               ask(j, 1, 1, n, l, r) % mod;
      cout << (ans % mod + mod) % mod << endl;
    }
  }
}