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;
long long qp(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long sum[6][100000 + 8];
long long tre[6][(100000 << 2) + 8];
long long lazy[(100000 << 2) + 8];
int n, Q;
long long a[100000 + 8];
void pushup(int rt) {
  for (int i = 0; i <= 5; ++i)
    tre[i][rt] = (tre[i][rt << 1] + tre[i][rt << 1 | 1]) % mod;
}
void build(int rt, int l, int r) {
  lazy[rt] = -0x3f3f3f3f;
  if (l > r) return;
  if (l == r) {
    for (int i = 0; i <= 5; ++i) tre[i][rt] = qp(l, i) * a[l] % mod;
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
  return;
}
void pushdown(int rt, int l, int r) {
  if (lazy[rt] >= 0) {
    int mid = (l + r) >> 1;
    for (int i = 0; i <= 5; ++i) {
      tre[i][rt << 1] = lazy[rt] * (sum[i][mid] - sum[i][l - 1] + mod) % mod;
      tre[i][rt << 1 | 1] = lazy[rt] * (sum[i][r] - sum[i][mid] + mod) % mod;
    }
    lazy[rt << 1] = lazy[rt];
    lazy[rt << 1 | 1] = lazy[rt];
    lazy[rt] = -0x3f3f3f3f;
  }
}
void update(int rt, int l, int r, int L, int R, long long v) {
  if (L <= l && r <= R) {
    lazy[rt] = v;
    for (int i = 0; i <= 5; ++i) {
      tre[i][rt] = v * (sum[i][r] - sum[i][l - 1] + mod) % mod;
    }
    return;
  }
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  if (mid >= L) update(rt << 1, l, mid, L, R, v);
  if (mid + 1 <= R) update(rt << 1 | 1, mid + 1, r, L, R, v);
  pushup(rt);
  return;
}
long long query(int rt, int l, int r, int L, int R, int k) {
  if (L <= l && r <= R) return tre[k][rt];
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  long long ret = 0;
  if (mid >= L) ret = (ret + query(rt << 1, l, mid, L, R, k)) % mod;
  if (mid + 1 <= R) ret = (ret + query(rt << 1 | 1, mid + 1, r, L, R, k)) % mod;
  return ret;
}
long long C(long long n, long long m) {
  int fac[] = {1, 1, 2, 6, 24, 120, 720};
  return fac[n] / fac[m] / fac[n - m];
}
int main() {
  scanf("%d %d", &n, &Q);
  for (int k = 0; k <= 5; ++k)
    for (int i = 1; i <= 100000; ++i)
      sum[k][i] = (sum[k][i - 1] + qp(i, k)) % mod;
  for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
  build(1, 1, n);
  while (Q--) {
    char s[2];
    scanf("%s", s);
    if (s[0] == '?') {
      int l, r, k;
      scanf("%d %d %d", &l, &r, &k);
      long long ret = 0;
      for (int i = 0; i <= k; ++i) {
        ret = (ret + C(k, i) * qp(mod + 1 - l, i) % mod *
                         query(1, 1, n, l, r, k - i) % mod) %
              mod;
      }
      printf("%I64d\n", ret);
    } else {
      int l, r, x;
      scanf("%d %d %d", &l, &r, &x);
      update(1, 1, n, l, r, x);
    }
  }
}