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;
int n, m, a[200005], ql, qr, qv, binom[6][6];
int pre[200005][6];
struct node {
  node* c[2];
  int setv, sum[6], seted, len;
  void maintain() {
    if (c[0]) {
      sum[0] = c[0]->sum[0] + c[1]->sum[0];
      sum[0] %= MOD;
      int t = c[0]->len;
      for (int k = 1; k <= 5; k++) {
        sum[k] = c[0]->sum[k];
        for (int j = k, tmp = 1; j >= 0; j--) {
          (sum[k] += (long long)binom[k][j] * tmp % MOD *
                     (long long)c[1]->sum[j] % MOD) %= MOD;
          tmp = (long long)tmp * t % MOD;
        }
      }
    }
  }
  void set(int w) {
    setv = w;
    seted = 1;
    for (int i = 0; i <= 5; i++) sum[i] = (long long)w * pre[len][i] % MOD;
  }
  void push() {
    if (seted && c[0]) {
      seted = 0;
      c[0]->set(setv);
      c[1]->set(setv);
    }
  }
} pool[200005], *stp = pool, *root;
node* build(int l, int r) {
  node* o = stp++;
  o->len = r - l + 1;
  if (l == r)
    o->set(a[l]);
  else
    o->c[0] = build(l, ((l + r) >> 1)), o->c[1] = build(((l + r) >> 1) + 1, r),
    o->maintain();
  return o;
}
void modify(node* o, int l, int r) {
  o->push();
  if (l >= ql && r <= qr)
    o->set(qv);
  else {
    if (ql <= ((l + r) >> 1)) modify(o->c[0], l, ((l + r) >> 1));
    if (qr > ((l + r) >> 1)) modify(o->c[1], ((l + r) >> 1) + 1, r);
    o->maintain();
  }
}
node query(node* o, int l, int r) {
  o->push();
  if (l >= ql && r <= qr) return *o;
  if (ql <= ((l + r) >> 1)) {
    if (qr > ((l + r) >> 1)) {
      node a, b = query(o->c[0], l, ((l + r) >> 1)),
              c = query(o->c[1], ((l + r) >> 1) + 1, r);
      a.c[0] = &b;
      a.c[1] = &c;
      a.len = b.len + c.len;
      a.maintain();
      return a;
    } else
      return query(o->c[0], l, ((l + r) >> 1));
  } else
    return query(o->c[1], ((l + r) >> 1) + 1, r);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int tmp = 1;
    for (int j = 0; j <= 5; j++)
      pre[i][j] = (tmp + pre[i - 1][j]) % MOD, tmp = (long long)tmp * i % MOD;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i <= 5; i++)
    for (int j = 0; j <= i; j++)
      (binom[i][j] = (i && j) ? (binom[i - 1][j] + binom[i - 1][j - 1]) : 1) %=
          MOD;
  root = build(1, n);
  while (m--) {
    char st[2];
    scanf("%s%d%d%d", st, &ql, &qr, &qv);
    if (st[0] == '?')
      printf("%d\n", query(root, 1, n).sum[qv]);
    else
      modify(root, 1, n);
  }
}