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 modd = 1e9 + 7;
const int maxn = 100000 + 15;
int plu(int g) {
  if (g >= modd) g -= modd;
  return g;
}
struct Node {
  int delt, ans[6];
} tree[4 * maxn];
int n, m, xx, ll, rr;
int c[6][6];
long long sum[6][maxn];
int up(int root) {
  for (int i = 0; i < 6; i++)
    tree[root].ans[i] =
        plu(tree[root << 1].ans[i] + tree[root << 1 | 1].ans[i]);
  return 0;
}
int dam(int root, int l, int r, int delt) {
  tree[root].delt = delt;
  for (int i = 0; i < 6; i++)
    tree[root].ans[i] = (sum[i][r] + modd - sum[i][l - 1]) * delt % modd;
  return 0;
}
int down(int root, int l, int r) {
  if (tree[root].delt == -1) return 0;
  int delt = tree[root].delt;
  tree[root].delt = -1;
  int mid = (l + r) >> 1;
  int nt = root << 1, nl = l, nr = mid;
  dam(nt, nl, nr, delt);
  nt++;
  nl = mid + 1, nr = r;
  dam(nt, nl, nr, delt);
  return 0;
}
int build(int root, int l, int r) {
  tree[root].delt = -1;
  if (l == r) {
    scanf("%d", &xx);
    for (int i = 0; i < 6; i++)
      tree[root].ans[i] = (sum[i][r] + modd - sum[i][l - 1]) * xx % modd;
    return 0;
  }
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
  up(root);
  return 0;
}
char ch;
int change(int root, int l, int r, int x, int y, int z) {
  if (l > y || r < x) return 0;
  if (x <= l && r <= y) {
    tree[root].delt = z;
    for (int i = 0; i < 6; i++)
      tree[root].ans[i] = (sum[i][r] + modd - sum[i][l - 1]) * z % modd;
    return 0;
  }
  down(root, l, r);
  int mid = (l + r) >> 1;
  change(root << 1, l, mid, x, y, z);
  change(root << 1 | 1, mid + 1, r, x, y, z);
  up(root);
  return 0;
}
int ask(int root, int l, int r, int x, int y, int z) {
  if (l > y || r < x) return 0;
  if (x <= l && r <= y) return tree[root].ans[z];
  down(root, l, r);
  int mid = (l + r) >> 1;
  return plu(ask(root << 1, l, mid, x, y, z) +
             ask(root << 1 | 1, mid + 1, r, x, y, z));
}
char cc;
int mgx;
int getint() {
  for (cc = getchar(); cc < '0' || cc > '9'; cc = getchar())
    ;
  for (mgx = 0; cc >= '0' && cc <= '9';
       mgx = mgx * 10 + cc - '0', cc = getchar())
    ;
  return mgx;
}
int main() {
  n = getint();
  m = getint();
  for (int i = 0, j; i < 6; i++)
    for (j = c[i][0] = 1; j <= i; j++)
      c[i][j] = plu(c[i - 1][j - 1] + c[i - 1][j]);
  for (int i = 1; i <= n; i++) {
    sum[0][i] = 1;
    for (int j = 1; j < 6; j++) sum[j][i] = sum[j - 1][i] * i % modd;
  }
  for (int i = 0; i < 6; i++)
    for (int j = 1; j <= n; j++) sum[i][j] = plu(sum[i][j] + sum[i][j - 1]);
  build(1, 1, n);
  while (m--) {
    for (ch = getchar(); ch != '=' && ch != '?'; ch = getchar())
      ;
    ll = getint();
    rr = getint();
    xx = getint();
    if (ch == '=')
      change(1, 1, n, ll, rr, xx);
    else if (ch == '?') {
      int ans = 0;
      long long tt = 1;
      for (int i = 0; i <= xx; i++, tt = tt * (1 - ll) % modd)
        ans =
            (ans + tt * ask(1, 1, n, ll, rr, xx - i) % modd * c[xx][i]) % modd;
      ans = plu(ans + modd);
      printf("%d\n", ans);
    }
  }
  return 0;
}