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;
int C[10][10], a[100005], i, j, k, l, s, n, m, x, y, z;
int F[2 * 100005][10];
struct node {
  int s[6][6], x[6][6], d;
} f[100005 * 4];
inline void doit() {
  for (i = 0; i <= 5; i++)
    for (C[i][0] = 1, j = 1; j <= i; j++)
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}
inline int quick(int o, int p) {
  int s = 1;
  while (p) {
    if (p & 1) s = 1ll * s * o % 1000000007;
    o = 1ll * o * o % 1000000007;
    p >>= 1;
  }
  return s;
}
inline void Up(int o) {
  for (int i = 0; i <= 5; i++)
    for (j = 0; j <= i; j++)
      f[o].s[i][j] = (f[o * 2].s[i][j] + f[o * 2 + 1].s[i][j]) % 1000000007,
      f[o].x[i][j] = (f[o * 2].x[i][j] + f[o * 2 + 1].x[i][j]) % 1000000007;
}
inline void up(int o) {
  for (int i = 0; i <= 5; i++)
    for (j = 0; j <= i; j++)
      f[o].s[i][j] = (f[o * 2].s[i][j] + f[o * 2 + 1].s[i][j]) % 1000000007;
}
inline void build(int o, int l, int r) {
  f[o].d = -1;
  if (l == r) {
    for (int i = 0; i <= 5; i++)
      for (int j = 0; j <= i; j++) {
        if (!F[l + 100005][i - j]) F[l + 100005][i - j] = quick(l, i - j);
        f[o].x[i][j] = (1ll * F[l + 100005][i - j] * C[i][j]) % 1000000007,
        f[o].s[i][j] = (1ll * f[o].x[i][j] * a[l]) % 1000000007;
      }
    return;
  }
  int mid = (l + r) >> 1;
  build(o * 2, l, mid), build(o * 2 + 1, mid + 1, r);
  Up(o);
}
inline void down(int o, int l, int r) {
  int mid = (l + r) >> 1;
  for (int i = 0; i <= 5; i++)
    for (int j = 0; j <= i; j++)
      f[o * 2].s[i][j] = (1ll * f[o].d * f[o * 2].x[i][j]) % 1000000007,
            f[o * 2 + 1].s[i][j] =
                (1ll * f[o].d * f[o * 2 + 1].x[i][j]) % 1000000007;
  f[o * 2].d = f[o * 2 + 1].d = f[o].d;
  f[o].d = -1;
}
inline void change(int o, int l, int r, int ll, int rr, int p) {
  if (l == ll && r == rr) {
    for (int i = 0; i <= 5; i++)
      for (int j = 0; j <= i; j++)
        f[o].s[i][j] = (1ll * p * f[o].x[i][j]) % 1000000007;
    f[o].d = p;
    return;
  }
  if (f[o].d != -1) down(o, l, r);
  int mid = (l + r) >> 1;
  if (rr <= mid)
    change(o * 2, l, mid, ll, rr, p);
  else if (ll > mid)
    change(o * 2 + 1, mid + 1, r, ll, rr, p);
  else
    change(o * 2, l, mid, ll, mid, p),
        change(o * 2 + 1, mid + 1, r, mid + 1, rr, p);
  up(o);
}
inline int ask(int o, int l, int r, int ll, int rr, int L, int p) {
  if (l == ll && r == rr) {
    int s = 0;
    for (int j = 0; j <= p; j++) {
      if (!F[L + 100005][j]) F[L + 100005][j] = quick(L, j);
      s = (s + 1ll * f[o].s[p][j] * F[L + 100005][j]) % 1000000007;
    }
    return s;
  }
  int mid = (l + r) >> 1;
  int s = 0;
  if (f[o].d != -1) down(o, l, r);
  if (rr <= mid)
    s = ask(o * 2, l, mid, ll, rr, L, p);
  else if (ll > mid)
    s = ask(o * 2 + 1, mid + 1, r, ll, rr, L, p);
  else
    s = (ask(o * 2, l, mid, ll, mid, L, p) +
         ask(o * 2 + 1, mid + 1, r, mid + 1, rr, L, p)) %
        1000000007;
  return s;
}
inline int in() {
  char c = getchar();
  int s = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') s = s * 10 + c - 48, c = getchar();
  return s;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) a[i] = in();
  doit();
  build(1, 1, n);
  for (i = 1; i <= m; i++) {
    char c = getchar();
    while (c != '=' && c != '?') c = getchar();
    if (c == '=') {
      x = in(), y = in(), z = in();
      change(1, 1, n, x, y, z);
    } else {
      x = in(), y = in(), z = in();
      printf("%d\n", (ask(1, 1, n, x, y, 1 - x, z) + 1000000007) % 1000000007);
    }
  }
}