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>
template <class Num>
void read(Num &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c - '0');
  x *= flag;
}
template <class Num>
void write(Num x) {
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  static char s[20];
  int sl = 0;
  while (x) s[sl++] = x % 10 + '0', x /= 10;
  while (sl) putchar(s[--sl]);
}
const int maxn = 1e5 + 20, Mod = 1e9 + 7, maxk = 10;
int n, m, a[maxn];
long long cnt[maxk][maxn << 2], tag[maxn << 2];
long long sum[maxk][maxn];
void pushdown(int x, int l, int r) {
  if (tag[x] == -1) return;
  int mid = (l + r) >> 1;
  for (int i = 0; i <= 5; i++) {
    cnt[i][((x) << 1)] =
        (sum[i][mid] - sum[i][l - 1] + Mod) % Mod * tag[x] % Mod;
    cnt[i][((x) << 1 | 1)] =
        (sum[i][r] - sum[i][mid] + Mod) % Mod * tag[x] % Mod;
  }
  tag[((x) << 1)] = tag[x], tag[((x) << 1 | 1)] = tag[x], tag[x] = -1;
}
void update(int x) {
  for (int i = 0; i <= 5; i++)
    cnt[i][x] = (cnt[i][((x) << 1)] + cnt[i][((x) << 1 | 1)]) % Mod;
}
void build(int l, int r, int s) {
  if (l == r) {
    for (int i = 0; i <= 5; i++)
      cnt[i][s] = (sum[i][r] - sum[i][l - 1] + Mod) % Mod * a[l] % Mod;
  } else {
    int mid = (l + r) >> 1;
    build(l, mid, ((s) << 1)), build(mid + 1, r, ((s) << 1 | 1));
    tag[s] = -1, update(s);
  }
}
void change(int l, int r, int v, int ll, int rr, int s) {
  if (ll == l && rr == r) {
    for (int i = 0; i <= 5; i++)
      cnt[i][s] = (sum[i][r] - sum[i][l - 1] + Mod) % Mod * v % Mod;
    tag[s] = v;
  } else {
    pushdown(s, ll, rr);
    int mid = (ll + rr) >> 1;
    if (r <= mid)
      change(l, r, v, ll, mid, ((s) << 1));
    else if (l > mid)
      change(l, r, v, mid + 1, rr, ((s) << 1 | 1));
    else {
      change(l, mid, v, ll, mid, ((s) << 1));
      change(mid + 1, r, v, mid + 1, rr, ((s) << 1 | 1));
    }
    update(s);
  }
}
void query(int l, int r, long long *ret, int ll, int rr, int s) {
  if (ll == l && rr == r) {
    for (int i = 0; i <= 5; i++) ret[i] += cnt[i][s], ret[i] %= Mod;
  } else {
    pushdown(s, ll, rr);
    int mid = (ll + rr) >> 1;
    if (r <= mid)
      query(l, r, ret, ll, mid, ((s) << 1));
    else if (l > mid)
      query(l, r, ret, mid + 1, rr, ((s) << 1 | 1));
    else {
      query(l, mid, ret, ll, mid, ((s) << 1));
      query(mid + 1, r, ret, mid + 1, rr, ((s) << 1 | 1));
    }
    update(s);
  }
}
long long power(int x, int y) {
  long long r = 1;
  while (y--) r = (r * x) % Mod;
  return r;
}
int choice(int y, int x) {
  int r = 1;
  for (int i = x + 1; i <= y; i++) r *= i;
  for (int i = 2; i <= y - x; i++) r /= i;
  return r;
}
void solve() {
  char ch[3];
  int x, y, k;
  scanf("%s", ch);
  read(x), read(y), read(k);
  if (ch[0] == '?') {
    long long g[maxk] = {0}, ans = 0;
    query(x, y, g, 1, n, 1);
    for (int i = 0; i <= k; i++)
      ans += g[i] * power(Mod - x + 1, k - i) % Mod * choice(k, i) % Mod;
    write(ans % Mod), puts("");
  } else
    change(x, y, k, 1, n, 1);
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int t = 0; t <= 5; t++)
    for (int i = 1; i <= n; i++)
      sum[t][i] = (sum[t][i - 1] + power(i, t)) % Mod;
  build(1, n, 1);
  for (int i = 1; i <= m; i++) solve();
  return 0;
}