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;
long long st[101010 * 4][6], lazy[101010 * 4], sum[6][101010], mod = 1e9 + 7,
                                                               escolhe[11][11];
void upd_lazy(int b, int l, int r) {
  if (lazy[b] == -1) return;
  for (int(i) = (0); (i) < (6); (i)++)
    st[b][i] = lazy[b] * (sum[i][r] - sum[i][l - 1] + mod) % mod;
  if (l != r) {
    int fe = b << 1, fd = fe | 1;
    lazy[fe] = lazy[fd] = lazy[b];
  }
  lazy[b] = -1;
}
void upd(int b, int l, int r, int first, int second, int v) {
  upd_lazy(b, l, r);
  if (r < first || second < l) return;
  if (first <= l && r <= second) {
    lazy[b] = v;
    upd_lazy(b, l, r);
    return;
  }
  int fe = b << 1, fd = fe | 1, mid = (l + r) >> 1;
  upd(fe, l, mid, first, second, v);
  upd(fd, mid + 1, r, first, second, v);
  for (int(i) = (0); (i) < (6); (i)++) {
    st[b][i] = st[fe][i] + st[fd][i];
    if (st[b][i] >= mod) st[b][i] -= mod;
  }
}
long long query(int b, int l, int r, int first, int second, int k) {
  if (r < first || second < l) return 0;
  upd_lazy(b, l, r);
  if (first <= l && r <= second) return st[b][k];
  int fe = b << 1, fd = fe | 1, mid = (l + r) >> 1;
  long long ret = query(fe, l, mid, first, second, k) +
                  query(fd, mid + 1, r, first, second, k);
  if (ret >= mod) ret -= mod;
  return ret;
}
int n, m;
long long modpow(long long b, long long e) {
  long long ret = 1;
  while (e) {
    if (e & 1) ret = ret * b % mod;
    b = b * b % mod;
    e >>= 1;
  }
  return ret;
}
int main() {
  memset(lazy, -1, sizeof(lazy));
  for (int(i) = (0); (i) < (6); (i)++)
    for (int(j) = (1); (j) < (101010); (j)++)
      sum[i][j] = (sum[i][j - 1] + modpow(j, i)) % mod;
  escolhe[0][0] = 1;
  for (int(i) = (1); (i) < (11); (i)++) {
    escolhe[i][0] = 1;
    for (int(j) = (1); (j) < (i + 1); (j)++)
      escolhe[i][j] = (escolhe[i - 1][j] + escolhe[i - 1][j - 1]) % mod;
  }
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    int v;
    scanf("%d", &v);
    upd(1, 1, n, i, i, v);
  }
  while (m--) {
    char op;
    int l, r, k;
    scanf(" %c %d %d %d", &op, &l, &r, &k);
    if (op == '=')
      upd(1, 1, n, l, r, k);
    else {
      long long ans = 0;
      for (int(i) = (0); (i) < (k + 1); (i)++)
        ans = (ans + ((escolhe[k][i] * modpow(1 - l + mod, k - i)) % mod) *
                         query(1, 1, n, l, r, i)) %
              mod;
      printf("%lld\n", ans);
    }
  }
}