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 mod = 1e9 + 7;
struct node {
  int l, r, flag, sum[6];
} t[MAXN << 2];
int cnt[6];
int fact[6][MAXN];
int a[MAXN], n, m;
void change(int k, int val) {
  int l = t[k].l, r = t[k].r;
  for (int i = 0; i <= 5; i++) {
    t[k].sum[i] = (long long)(fact[i][r] - fact[i][l - 1]) * val % mod;
    t[k].sum[i] = (t[k].sum[i] % mod + mod) % mod;
  }
  t[k].flag = val;
}
void push_down(int k) {
  if (t[k].flag != -1) {
    change(k << 1, t[k].flag);
    change(k << 1 | 1, t[k].flag);
    t[k].flag = -1;
  }
}
void push_up(int k) {
  for (int i = 0; i <= 5; i++) {
    t[k].sum[i] = (t[k << 1].sum[i] + t[k << 1 | 1].sum[i]) % mod;
  }
}
void build(int l, int r, int k) {
  t[k].l = l;
  t[k].r = r;
  t[k].flag = -1;
  if (l == r) {
    change(k, a[l]);
    return;
  }
  int mid = t[k].l + t[k].r >> 1;
  build(l, mid, k << 1);
  build(mid + 1, r, k << 1 | 1);
  push_up(k);
}
void update(int l, int r, int val, int k) {
  if (l <= t[k].l && t[k].r <= r) {
    change(k, val);
    return;
  }
  push_down(k);
  int mid = t[k].l + t[k].r >> 1;
  if (l <= mid) update(l, r, val, k << 1);
  if (r > mid) update(l, r, val, k << 1 | 1);
  push_up(k);
}
void query(int l, int r, int k) {
  if (l <= t[k].l && t[k].r <= r) {
    for (int i = 0; i <= 5; i++) {
      cnt[i] += t[k].sum[i];
      if (cnt[i] >= mod) cnt[i] -= mod;
    }
    return;
  }
  push_down(k);
  int mid = t[k].l + t[k].r >> 1;
  if (l <= mid) query(l, r, k << 1);
  if (r > mid) query(l, r, k << 1 | 1);
}
char op[5];
int x, y, z;
int c[6][6];
int power[6];
int main() {
  scanf("%d%d", &n, &m);
  c[0][0] = 1;
  c[1][0] = c[1][1] = 1;
  for (int i = 2; i <= 5; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int k = 0; k <= 5; k++) {
    fact[k][0] = 0;
    for (int i = 1; i <= n; i++) {
      int te = 1;
      for (int j = 1; j <= k; j++) te = (long long)te * i % mod;
      fact[k][i] = fact[k][i - 1] + te;
      if (fact[k][i] >= mod) fact[k][i] -= mod;
    }
  }
  build(1, n, 1);
  while (m--) {
    scanf("%s", op);
    scanf("%d%d%d", &x, &y, &z);
    if (op[0] != '?') {
      update(x, y, z, 1);
    } else {
      for (int i = 0; i <= z; i++) cnt[i] = 0;
      power[0] = 1;
      for (int i = 1; i <= z; i++)
        power[i] = (long long)power[i - 1] * (1 - x) % mod;
      query(x, y, 1);
      long long ans = 0;
      for (int x = 0; x <= z; x++) {
        ans = ans + (long long)power[x] * cnt[z - x] % mod * c[z][x] % mod;
        ans = (ans % mod + mod) % mod;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}