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;
struct tree {
  int len, a[6], c;
} tr[100010 * 4];
int i, j, k, n, m, x, y, z;
int a[100010], po[100010][6], s[100010][6], C[10][10];
char p[10];
inline void update(tree &a, tree b, tree c) {
  int i, j;
  for (i = 0; i <= 5; i++) {
    a.a[i] = b.a[i];
    for (j = 0; j <= i; j++)
      a.a[i] =
          (1ll * C[i][j] * po[b.len][i - j] % 1000000007 * c.a[j] + a.a[i]) %
          1000000007;
  }
  a.len = b.len + c.len;
}
inline void Cov(int x, int y) {
  int i;
  for (i = 0; i <= 5; i++) tr[x].a[i] = 1ll * y * s[tr[x].len][i] % 1000000007;
  tr[x].c = y;
}
inline void renew(int x) {
  if (tr[x].c >= 0) Cov(x * 2, tr[x].c), Cov(x * 2 + 1, tr[x].c);
  tr[x].c = -1;
}
void build(int q, int x, int y) {
  tr[q].len = y - x + 1;
  tr[q].c = -1;
  if (x == y) {
    int i;
    for (i = 0; i <= 5; i++) tr[q].a[i] = a[x];
    return;
  }
  int mid = (x + y) / 2;
  build(q * 2, x, mid);
  build(q * 2 + 1, mid + 1, y);
  update(tr[q], tr[q * 2], tr[q * 2 + 1]);
}
void cover(int q, int x, int y, int l, int r, int k) {
  if (l <= x && y <= r) {
    Cov(q, k);
    return;
  }
  renew(q);
  int mid = (x + y) / 2;
  if (l <= mid) cover(q * 2, x, mid, l, r, k);
  if (mid < r) cover(q * 2 + 1, mid + 1, y, l, r, k);
  update(tr[q], tr[q * 2], tr[q * 2 + 1]);
}
tree cal(int q, int x, int y, int l, int r) {
  if (l <= x && y <= r) return tr[q];
  renew(q);
  int mid = (x + y) / 2;
  tree A;
  int F = 0;
  if (l <= mid) A = cal(q * 2, x, mid, l, r), F = 1;
  if (mid < r) {
    tree B = cal(q * 2 + 1, mid + 1, y, l, r), C;
    if (!F)
      A = B;
    else
      C = A, update(A, C, B);
  }
  return A;
}
int main() {
  for (i = 0; i <= 9; i++) {
    C[i][0] = 1;
    for (j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
  }
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    po[i][0] = 1;
    for (j = 1; j <= 5; j++) po[i][j] = 1ll * po[i][j - 1] * i % 1000000007;
    for (j = 0; j <= 5; j++) s[i][j] = (s[i - 1][j] + po[i][j]) % 1000000007;
  }
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  for (i = 1; i <= m; i++) {
    scanf("%s%d%d%d", p, &x, &y, &z);
    if (p[0] == '=')
      cover(1, 1, n, x, y, z);
    else {
      tree A = cal(1, 1, n, x, y);
      printf("%d\n", A.a[z]);
    }
  }
  return 0;
}