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 MAXN = 1e5 + 10;
const int XMK = 1e9 + 7;
struct node {
  int st, ed;
  long long m[6], lz;
  node *l, *r;
} * root;
long long power[MAXN][6], f[MAXN][6];
long long get(node *now, int p) { return now ? now->m[p] : 0; }
void update(node *now) {
  if (!now) return;
  now->st = now->l->st;
  now->ed = now->r->ed;
  for (int p = 0; p <= 5; ++p)
    now->m[p] = (get(now->l, p) + get(now->r, p)) % XMK;
}
long long n, m, a[MAXN];
node *build(int st, int ed) {
  node *ret = new node;
  ret->st = st;
  ret->ed = ed;
  ret->l = ret->r = 0;
  ret->lz = -1;
  if (st == ed) {
    for (int i = 0; i <= 5; ++i)
      ret->m[i] = 1ll * a[st] * power[st + 1][i] % XMK;
    return ret;
  }
  int mid = (st + ed) / 2;
  ret->l = build(st, mid);
  ret->r = build(mid + 1, ed);
  update(ret);
  return ret;
}
void change(node *now, long long x) {
  if (!now) return;
  for (int i = 0; i <= 5; ++i)
    now->m[i] = 1ll * x * (f[now->ed][i] - f[now->st - 1][i] + XMK) % XMK;
  now->lz = x;
}
void down(node *now) {
  if (now->lz != -1) {
    change(now->l, now->lz);
    change(now->r, now->lz);
    now->lz = -1;
  }
}
void cover(int st, int ed, long long x, node *now) {
  if (now->st == st && now->ed == ed) {
    change(now, x);
    return;
  }
  down(now);
  int mid = (now->st + now->ed) / 2;
  if (ed <= mid)
    cover(st, ed, x, now->l);
  else if (st > mid)
    cover(st, ed, x, now->r);
  else
    cover(st, mid, x, now->l), cover(mid + 1, ed, x, now->r);
  update(now);
}
node *merge(node *lch, node *rch) {
  node *ret = new node;
  ret->l = lch;
  ret->r = rch;
  ret->lz = -1;
  update(ret);
  return ret;
}
node *ask(int st, int ed, node *now) {
  if (now->st == st && now->ed == ed) return now;
  down(now);
  int mid = (now->st + now->ed) / 2;
  if (ed <= mid)
    return ask(st, ed, now->l);
  else if (st > mid)
    return ask(st, ed, now->r);
  else
    return merge(ask(st, mid, now->l), ask(mid + 1, ed, now->r));
}
long long tmp[6];
long long k[6][7] = {0, 1, 0,  0, 0,  0, 0, 0, 1, -1, 0,  0,   0, 0,
                     0, 1, -2, 1, 0,  0, 0, 0, 1, -3, 3,  -1,  0, 0,
                     0, 1, -4, 6, -4, 1, 0, 0, 1, -5, 10, -10, 5, -1};
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n + 1; ++i) {
    power[i][0] = 1;
    for (int p = 1; p <= 5; ++p) power[i][p] = power[i][p - 1] * i % XMK;
  }
  for (int p = 0; p <= 5; ++p)
    for (int i = 1; i <= n; ++i)
      f[i][p] = (f[i - 1][p] + power[i + 1][p]) % XMK;
  root = build(1, n);
  while (m--) {
    char op;
    long long l, r, x;
    cin >> op >> l >> r >> x;
    if (op == '=')
      cover(l, r, x, root);
    else {
      node *ret = ask(l, r, root);
      tmp[0] = 1;
      for (int i = 1; i <= 5; ++i) tmp[i] = tmp[i - 1] * l % XMK;
      long long ans = 0;
      for (int i = 1; i <= x + 1; ++i)
        (ans +=
         1ll * k[x][i] % XMK * ret->m[x - i + 1] % XMK * tmp[i - 1] % XMK +
         XMK) %= XMK;
      while (ans < 0) ans += XMK;
      cout << ans << endl;
    }
  }
  return 0;
}