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;
long long a[100005], Sum[6][100005], C[10][10];
int n, m;
struct INTERVAL {
  long long T[4 * 100005], C[4 * 100005];
  INTERVAL() { memset(T, -1, sizeof(T)); }
  void Build(int node, int l, int r, int num) {
    if (l == r) {
      C[node] = a[l] * (Sum[num][l] - Sum[num][l - 1]) % 1000000007;
      return;
    }
    int g = (l + r) / 2;
    Build(node * 2, l, g, num);
    Build(node * 2 + 1, g + 1, r, num);
    C[node] = (C[2 * node] + C[2 * node + 1]) % 1000000007;
  }
  void Down(int node, int l, int r, int num) {
    int g = (l + r) / 2;
    if (T[node] == -1) return;
    T[2 * node] = T[2 * node + 1] = T[node];
    C[2 * node] = T[node] * (Sum[num][g] - Sum[num][l - 1]) % 1000000007;
    C[2 * node + 1] = T[node] * (Sum[num][r] - Sum[num][g]) % 1000000007;
    T[node] = -1;
  }
  void Up(int node, int l, int r, int d, int c, int Val, int num) {
    if (d <= l && r <= c) {
      T[node] = Val;
      C[node] = (Sum[num][r] - Sum[num][l - 1]) * Val % 1000000007;
      return;
    }
    if (d > r || l > c) return;
    Down(node, l, r, num);
    int g = (l + r) / 2;
    Up(node * 2, l, g, d, c, Val, num);
    Up(node * 2 + 1, g + 1, r, d, c, Val, num);
    C[node] = (C[2 * node] + C[2 * node + 1]) % 1000000007;
  }
  int Get(int node, int l, int r, int d, int c, int num) {
    if (d <= l && r <= c) return C[node];
    if (d > r || l > c) return 0;
    Down(node, l, r, num);
    int g = (l + r) / 2;
    int u = Get(2 * node, l, g, d, c, num);
    int v = Get(2 * node + 1, g + 1, r, d, c, num);
    return (u + v) % 1000000007;
  }
};
INTERVAL Tree[6];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) Sum[0][i] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= n; j++) Sum[i][j] = Sum[i - 1][j] * j % 1000000007;
  for (int i = 0; i <= 5; i++)
    for (int j = 1; j <= n; j++) (Sum[i][j] += Sum[i][j - 1]) %= 1000000007;
  for (int i = 0; i <= 5; i++) Tree[i].Build(1, 1, n, i);
  C[0][0] = 1;
  for (int i = 1; i <= 5; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
  char type;
  int l, r, x;
  for (int i = 1; i <= m; i++) {
    cin >> type >> l >> r >> x;
    if (type == '=')
      for (int j = 0; j <= 5; j++) Tree[j].Up(1, 1, n, l, r, x, j);
    if (type == '?') {
      long long Pow = 1, Ans = 0;
      for (int j = 0; j <= x; j++) {
        Ans = (Ans + Tree[x - j].Get(1, 1, n, l, r, x - j) * Pow % 1000000007 *
                         C[x][j] % 1000000007) %
              1000000007;
        Pow = Pow * (1 - l) % 1000000007;
      }
      cout << (Ans + 1000000007) % 1000000007 << endl;
    }
  }
}