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 mod = 1000000007;
inline int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
inline int mul(int a, int b) { return (a * (long long)b) % mod; }
inline int reg(int c) {
  c %= mod;
  if (c < 0) c += mod;
  return c;
}
int pob[6][110000];
int tre[6][540000];
int cov[6][540000];
bool covd[6][540000];
int pobs[6][110000];
inline int sumd(int x, int y, int k) { return sub(pobs[k][y], pobs[k][x - 1]); }
inline void down(int k, int np, int l, int r) {
  if (covd[k][np]) {
    int c = cov[k][np];
    int m = (l + r) / 2;
    covd[k][np] = 0;
    covd[k][np * 2] = covd[k][np * 2 + 1] = 1;
    cov[k][np * 2] = cov[k][np * 2 + 1] = c;
    tre[k][np * 2] = mul(sumd(l, m, k), c);
    tre[k][np * 2 + 1] = mul(sumd(m + 1, r, k), c);
  }
}
inline void up(int k, int np) {
  tre[k][np] = add(tre[k][np * 2], tre[k][np * 2 + 1]);
}
inline int que(int np, int l, int r, int x, int y, int k) {
  if (l == x && r == y) {
    return tre[k][np];
  }
  int m = (l + r) / 2;
  down(k, np, l, r);
  if (x <= m && y > m) {
    return add(que(np * 2, l, m, x, m, k),
               que(np * 2 + 1, m + 1, r, m + 1, y, k));
  } else if (x > m) {
    return que(np * 2 + 1, m + 1, r, x, y, k);
  } else {
    return que(np * 2, l, m, x, y, k);
  }
}
inline void covf(int np, int l, int r, int x, int y, int k, int c) {
  if (l == x && r == y) {
    cov[k][np] = c;
    covd[k][np] = 1;
    tre[k][np] = mul(sumd(l, r, k), c);
    return;
  }
  down(k, np, l, r);
  int m = (l + r) / 2;
  if (x <= m && y > m) {
    covf(np * 2, l, m, x, m, k, c);
    covf(np * 2 + 1, m + 1, r, m + 1, y, k, c);
  } else if (x > m) {
    covf(np * 2 + 1, m + 1, r, x, y, k, c);
  } else {
    covf(np * 2, l, m, x, y, k, c);
  }
  up(k, np);
}
char in[100];
int s[6];
int bin[6][6];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  ;
  for (int k = 0; k < (6); k++) {
    pobs[k][0] = 0;
    for (int i = (1); i <= (n); i++) {
      int x = 1;
      for (int kk = 0; kk < (k); kk++) x = mul(x, i);
      pob[k][i] = x;
      pobs[k][i] = add(pobs[k][i - 1], pob[k][i]);
    }
  }
  bin[0][0] = 1;
  for (int k = (1); k <= (5); k++) {
    bin[k][0] = bin[k][k] = 1;
    for (int i = (1); i <= (k - 1); i++)
      bin[k][i] = add(bin[k - 1][i], bin[k - 1][i - 1]);
  }
  for (int i = (1); i <= (n); i++) {
    int a;
    scanf("%d", &a);
    a = reg(a);
    for (int k = 0; k < (6); k++) {
      covf(1, 1, n, i, i, k, a);
    }
  }
  while (m--) {
    scanf("%s", in);
    ;
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    ;
    if (in[0] == '=') {
      x = reg(x);
      for (int k = 0; k < (6); k++) {
        covf(1, 1, n, l, r, k, x);
      }
    } else {
      for (int k = 0; k < (6); k++) s[k] = que(1, 1, n, l, r, k);
      int c = reg(-l + 1);
      int su = 0;
      int cp = 1;
      for (int i = (0); i <= (x); i++) {
        int r = reg(bin[x][i]);
        r = mul(r, s[x - i]);
        r = mul(r, cp);
        cp = mul(cp, c);
        su = add(su, r);
      }
      printf("%d\n", su);
    }
  }
}