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 MAXN = 1e5;
const int MAXK = 5;
const int MOD = 1e9 + 7;
const int UNSET = -1;
const int sign[] = {1, -1};
int a[MAXN + 1];
int sum[MAXK + 1][MAXN + 1];
int nCr[MAXK + 1][MAXK + 1];
int tree[MAXK + 1][4 * MAXN];
int lazy[4 * MAXN];
int tmp, x;
long long ans;
char c;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int binpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (1LL * ans * x) % MOD;
    x = (1LL * x * x) % MOD;
    y >>= 1;
  }
  return ans;
}
void pushup(int v, int l, int r) {
  for (int i = 0; i <= MAXK; i++) tree[i][v] = (tree[i][l] + tree[i][r]) % MOD;
}
void pushdown(int v, int l, int r) {
  if (lazy[v] == UNSET) return;
  for (int i = 0; i <= MAXK; i++)
    tree[i][v] =
        (1LL * (sum[i][r] - sum[i][l - 1] + MOD) % MOD * lazy[v]) % MOD;
  if (l != r) {
    int L = (v << 1), R = (L | 1);
    lazy[L] = lazy[R] = lazy[v];
  }
  lazy[v] = UNSET;
}
void build(int v, int l, int r) {
  lazy[v] = UNSET;
  if (l == r) {
    for (int i = 0; i <= MAXK; i++)
      tree[i][v] = (1LL * a[l] * binpow(l, i)) % MOD;
  } else {
    int mid = (l + r) >> 1;
    int L = (v << 1), R = (L | 1);
    build(L, l, mid);
    build(R, mid + 1, r);
    pushup(v, L, R);
  }
}
void update(int v, int tl, int tr, int l, int r, int val) {
  pushdown(v, tl, tr);
  if (l > tr or r < tl) return;
  if (l <= tl and r >= tr) {
    lazy[v] = val;
    pushdown(v, tl, tr);
  } else {
    int mid = (tl + tr) >> 1;
    int L = (v << 1), R = (L | 1);
    update(L, tl, mid, l, r, val);
    update(R, mid + 1, tr, l, r, val);
    pushup(v, L, R);
  }
}
int query(int v, int tl, int tr, int l, int r, int k) {
  pushdown(v, tl, tr);
  if (l > tr or r < tl) return 0;
  if (l <= tl and r >= tr) return tree[k][v];
  int mid = (tl + tr) >> 1;
  int L = (v << 1), R = (L | 1);
  return (query(L, tl, mid, l, r, k) + query(R, mid + 1, tr, l, r, k)) % MOD;
}
void prepare() {
  for (int i = 0; i <= MAXK; i++) {
    for (int j = 1; j <= MAXN; j++)
      sum[i][j] = (sum[i][j - 1] + binpow(j, i)) % MOD;
  }
  for (int i = 0; i <= MAXK; i++) {
    nCr[i][0] = 1;
  }
  for (int i = 1; i <= MAXK; i++) {
    for (int j = 1; j <= MAXK; j++)
      nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1];
  }
}
int main() {
  fast_io();
  prepare();
  int n, q, l, r;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  while (q--) {
    cin >> c >> l >> r >> x;
    if (c == '=')
      update(1, 1, n, l, r, x);
    else {
      ans = 0;
      for (int j = 0; j <= x; j++) {
        tmp = (1LL * (1LL * query(1, 1, n, l, r, j) * binpow(l - 1, x - j)) %
               MOD * nCr[x][j]) %
              MOD;
        tmp *= sign[(x - j) & 1];
        ans = (ans + tmp + MOD) % MOD;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}