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 modn = (int)1e9 + 7, N = (int)1e5 + 10;
int a[N], p[N][6], q[N], c[6][6][6], n, m;
inline void add(int &x, int y) {
  x += y;
  if (x >= modn) x %= modn;
}
struct zz {
  int power, x, s, t, tot;
  int v[N << 2], ls[N << 2], rs[N << 2], b[N << 2];
  void build(int l, int r, int now) {
    b[now] = -1;
    if (l == r) {
      v[now] = (long long)a[l] * p[l][power] % modn;
      return;
    }
    int mid = (l + r) >> 1;
    ls[now] = ++tot;
    rs[now] = ++tot;
    build(l, mid, ls[now]);
    build(mid + 1, r, rs[now]);
    add(v[now], v[ls[now]]);
    add(v[now], v[rs[now]]);
  }
  void push(int l, int r, int now) {
    if (b[now] != -1 && l != r) {
      int mid = (l + r) >> 1;
      v[ls[now]] =
          (long long)b[now] * (p[mid][power] - p[l - 1][power] + modn) % modn;
      v[rs[now]] =
          (long long)b[now] * (p[r][power] - p[mid][power] + modn) % modn;
      b[rs[now]] = b[ls[now]] = b[now];
      b[now] = -1;
    }
  }
  void make(int l, int r, int now) {
    if (l >= s && r <= t) {
      b[now] = x;
      v[now] = (long long)x * (p[r][power] - p[l - 1][power] + modn) % modn;
      return;
    }
    push(l, r, now);
    int mid = (l + r) >> 1;
    if (mid >= s) make(l, mid, ls[now]);
    if (mid < t) make(mid + 1, r, rs[now]);
    v[now] = 0;
    add(v[now], v[ls[now]]);
    add(v[now], v[rs[now]]);
  }
  int ask(int l, int r, int now) {
    if (l >= s && r <= t) return v[now];
    push(l, r, now);
    int mid = (l + r) >> 1, ret = 0;
    if (mid >= s) add(ret, ask(l, mid, ls[now]));
    if (mid < t) add(ret, ask(mid + 1, r, rs[now]));
    v[now] = 0;
    add(v[now], v[ls[now]]);
    add(v[now], v[rs[now]]);
    return ret;
  }
} T[6];
inline void read(int &ret) {
  ret = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    ret = ret * 10 + x - '0';
    x = getchar();
  }
}
inline int spj() {
  static int l, r, k, ch[6], pp[6];
  int ret = 0;
  read(l);
  read(r);
  read(k);
  pp[0] = 1;
  for (int i = 0; i <= k; ++i) {
    if (i != 0) pp[i] = (long long)pp[i - 1] * (modn - l) % modn;
    T[i].s = l;
    T[i].t = r;
    ch[i] = T[i].ask(1, n, 0);
  }
  for (int i = 0; i <= k; ++i)
    for (int j = 0; i + j <= k; ++j)
      add(ret, (long long)ch[i] * c[i][j][k - i - j] % modn * pp[j] % modn);
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i <= n; ++i) {
    p[i][0] = 1;
    for (int j = 1; j < 6; ++j) p[i][j] = (long long)p[i][j - 1] * i % modn;
  }
  for (int i = 0; i < 6; ++i) T[i].power = i;
  for (int i = 0; i < 6; ++i) T[i].build(1, n, 0);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 6; ++j) add(p[i][j], p[i - 1][j]);
  q[0] = 1;
  for (int i = 1; i < 6; ++i) q[i] = q[i - 1] * i;
  for (int i = 0; i < 6; ++i)
    for (int j = 0; j < 6; ++j)
      for (int k = 0; k < 6; ++k)
        if (i + j + k < 6) c[i][j][k] = q[i + j + k] / q[i] / q[j] / q[k];
  for (int i = 1; i <= m; ++i) {
    int l, r, x;
    char cc = getchar();
    while (cc != '?' && cc != '=') cc = getchar();
    if (cc == '=') {
      read(l);
      read(r);
      read(x);
      for (int i = 0; i < 6; ++i) {
        T[i].s = l;
        T[i].t = r;
        T[i].x = x;
        T[i].make(1, n, 0);
      }
    } else
      printf("%d\n", spj());
  }
}