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 = 1e5;
const long long LIM = 1e18;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const double PI = atan(1.0) * 4;
const int mod = 1e9 + 7;
int n, m, a[N + 10];
long long c[6][6], fac[N + 10][6], sum[N + 10][6], s[N + 10][6];
long long tree[(N + 10) << 2][6], lazy[(N + 10) << 2];
void pushup(int x) {
  for (int i = 0; i < 6; i++)
    tree[x][i] = (tree[x << 1][i] + tree[x << 1 | 1][i]) % mod;
}
void update(int x, int l, int r, int L, int R, int v);
void pushdown(int x, int l, int r) {
  if (lazy[x] == -1) return;
  int mid = (l + r) / 2;
  update(x << 1, l, mid, l, mid, lazy[x]);
  update(x << 1 | 1, mid + 1, r, mid + 1, r, lazy[x]);
  lazy[x] = -1;
}
void build(int x, int l, int r) {
  lazy[x] = -1;
  if (l == r) {
    for (int i = 0; i < 6; i++) tree[x][i] = 1LL * a[l] * fac[l][i] % mod;
    return;
  }
  int mid = (l + r) / 2;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
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] = s[i][0] = 1;
    sum[i][0] = i;
  }
  for (int i = 1; i < 6; i++)
    for (int j = 1; j <= n; j++) {
      fac[j][i] = (fac[j][i - 1] * j) % mod;
      sum[j][i] = (sum[j - 1][i] + fac[j][i]) % mod;
      s[j][i] = (s[j][i - 1] * (1 - j) % mod + mod) % mod;
    }
  build(1, 1, n);
}
void update(int x, int l, int r, int L, int R, int v) {
  if (L == l && r == R) {
    lazy[x] = v;
    for (int i = 0; i < 6; i++) {
      int tmp = ((sum[r][i] - sum[l - 1][i]) % mod + mod) % mod;
      tree[x][i] = 1LL * tmp * v % mod;
    }
    return;
  }
  pushdown(x, l, r);
  int mid = (l + r) / 2;
  if (R <= mid)
    update(x << 1, l, mid, L, R, v);
  else if (L > mid)
    update(x << 1 | 1, mid + 1, r, L, R, v);
  else
    update(x << 1, l, mid, L, mid, v),
        update(x << 1 | 1, mid + 1, r, mid + 1, R, v);
  pushup(x);
}
int query(int x, int l, int r, int L, int R, int idx) {
  if (L == l && r == R) return tree[x][idx];
  pushdown(x, l, r);
  int mid = (l + r) / 2, res = 0;
  if (R <= mid)
    res = query(x << 1, l, mid, L, R, idx);
  else if (L > mid)
    res = query(x << 1 | 1, mid + 1, r, L, R, idx);
  else
    res = (query(x << 1, l, mid, L, mid, idx) +
           query(x << 1 | 1, mid + 1, r, mid + 1, R, idx)) %
          mod;
  return res;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  init();
  while (m--) {
    char opt[2];
    int l, r, x;
    cin >> opt >> l >> r >> x;
    if (opt[0] == '=')
      update(1, 1, n, l, r, x);
    else {
      int ans = 0;
      for (int i = 0; i <= x; i++) {
        int valu = query(1, 1, n, l, r, i);
        ans = ((1LL * valu * c[x][i] % mod * s[l][x - i] % mod + ans) % mod +
               mod) %
              mod;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}