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 n, m;
int C[10][10], Sum[100010][10], tong[10];
int Key[5 * 100010][10], dw[5 * 100010];
void Cover(int node, int l, int r, int gt) {
  dw[node] = gt;
  for (int i = 0; i <= 5; i++)
    Key[node][i] = (1ll * Sum[r][i] - Sum[l - 1][i]) * gt % 1000000007;
}
void Down(int node, int l, int r) {
  if (l < r && dw[node] >= 0) {
    int mid = (l + r) >> 1;
    Cover(node * 2, l, mid, dw[node]);
    Cover(node * 2 + 1, mid + 1, r, dw[node]);
    dw[node] = -1;
  }
}
void Gan(int node, int dau, int cuoi, int l, int r, int gt) {
  Down(node, dau, cuoi);
  if (dau >= l && cuoi <= r) {
    Cover(node, dau, cuoi, gt);
    return;
  }
  int mid = (dau + cuoi) / 2;
  if (mid >= l) Gan(node * 2, dau, mid, l, r, gt);
  if (mid < r) Gan(node * 2 + 1, mid + 1, cuoi, l, r, gt);
  for (int i = 0; i <= 5; i++)
    Key[node][i] = (1ll * Key[node * 2][i] + Key[node * 2 + 1][i]) % 1000000007;
}
void nhap() {
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 1; i <= 4 * 100010; i++)
    for (int j = 0; j <= 5; j++) Key[i][j] = 0;
}
void chuanbi() {
  for (int i = 0; i <= 5; i++) C[i][i] = C[i][0] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= i - 1; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  for (int i = 1; i <= n; i++) Sum[i][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++)
      Sum[i][j] = (1ll * Sum[i][j - 1] * i) % 1000000007;
    for (int j = 0; j <= 5; j++)
      Sum[i][j] = (Sum[i - 1][j] + Sum[i][j]) % 1000000007;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    Gan(1, 1, n, i, i, x);
  }
}
void Tinh(int node, int dau, int cuoi, int l, int r) {
  Down(node, dau, cuoi);
  if (l <= dau && cuoi <= r) {
    for (int i = 0; i <= 5; i++)
      tong[i] = (1ll * tong[i] + Key[node][i]) % 1000000007;
  } else {
    int mid = (cuoi + dau) / 2;
    if (mid >= l) Tinh(node * 2, dau, mid, l, r);
    if (mid < r) Tinh(node * 2 + 1, mid + 1, cuoi, l, r);
  }
}
void xuli() {
  for (int i = 1; i <= m; i++) {
    char yeucau;
    int l, r, k;
    cin >> yeucau;
    scanf("%d", &l), scanf("%d", &r), scanf("%d", &k);
    if (yeucau == '=')
      Gan(1, 1, n, l, r, k);
    else {
      memset(tong, 0, sizeof(tong));
      Tinh(1, 1, n, l, r);
      int kq = 0, t = 1;
      for (int i = k; i >= 0; i--) {
        kq = (1ll * kq + 1ll * tong[i] * C[k][i] % 1000000007 * t) % 1000000007;
        t = 1ll * t * (1 - l) % 1000000007;
      }
      printf("%d\n", (kq + 1000000007) % 1000000007);
    }
  }
}
void inkq() {}
int main() {
  for (int i = 1; i <= 5 * 100010 - 10; i++) dw[i] = -1;
  nhap();
  chuanbi();
  xuli();
  inkq();
  return 0;
}