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>
const long long Mod = 1000000007;
long long N, M, Ans;
long long tag[500010];
long long f[500010][6];
long long q[500010][6];
char s[2];
long long L, R, K;
long long C[6][6];
void Up(long long k) {
  for (long long o = 0; o <= 5; ++o)
    f[k][o] = (f[k << 1][o] + f[(k << 1) + 1][o]) % Mod;
}
void Build(long long l, long long r, long long k) {
  tag[k] = -1;
  if (l == r) {
    long long P;
    scanf("%I64d", &P);
    q[k][0] = 1;
    f[k][0] = P;
    for (long long o = 1; o <= 5; ++o)
      q[k][o] = (q[k][o - 1] * l) % Mod, f[k][o] = (q[k][o] * P) % Mod;
    return;
  }
  long long mid = l + r >> 1;
  Build(l, mid, k << 1);
  Build(mid + 1, r, (k << 1) + 1);
  Up(k);
  for (long long o = 0; o <= 5; ++o)
    q[k][o] = (q[k << 1][o] + q[(k << 1) + 1][o]) % Mod;
}
void Down(long long k) {
  if (tag[k] < 0) return;
  for (long long o = 0; o <= 5; ++o) {
    f[k << 1][o] = (q[k << 1][o] * tag[k]) % Mod;
    f[(k << 1) + 1][o] = (q[(k << 1) + 1][o] * tag[k]) % Mod;
  }
  tag[k << 1] = tag[(k << 1) + 1] = tag[k];
  tag[k] = -1;
}
void Change(long long l, long long r, long long k) {
  if (l > R || L > r) return;
  if (L <= l && r <= R) {
    tag[k] = K % Mod;
    for (long long o = 0; o <= 5; ++o) f[k][o] = (q[k][o] * tag[k]) % Mod;
    return;
  }
  long long mid = l + r >> 1;
  Down(k);
  Change(l, mid, k << 1);
  Change(mid + 1, r, (k << 1) + 1);
  Up(k);
}
long long pow(long long x, long long k) {
  if (k == 0) return 1;
  if (k == 1) return x;
  long long tmp = pow(x, k / 2);
  tmp = tmp * tmp % Mod;
  if (k % 2) tmp = tmp * x % Mod;
  return tmp;
}
void Query(long long l, long long r, long long k) {
  if (l > R || L > r) return;
  if (L <= l && r <= R) {
    for (long long o = 0; o <= K; ++o)
      Ans = (Ans + f[k][o] * C[o][K] % Mod * pow(-L + 1, K - o) % Mod) % Mod;
    return;
  }
  long long mid = l + r >> 1;
  Down(k);
  Query(l, mid, k << 1);
  Query(mid + 1, r, (k << 1) + 1);
  Up(k);
}
void PreTreatment() {
  for (long long i = 0; i <= 5; ++i) C[0][i] = 1;
  for (long long i = 1; i <= 5; ++i)
    for (long long j = i; j <= 5; ++j) C[i][j] = C[i - 1][j - 1] + C[i][j - 1];
}
int main() {
  PreTreatment();
  scanf("%d%d", &N, &M);
  Build(1, N, 1);
  for (long long i = 1; i <= M; ++i) {
    scanf("%s", s);
    long long x, y, k;
    scanf("%I64d%I64d%I64d", &x, &y, &k);
    L = x, R = y, K = k;
    Ans = 0;
    if (s[0] == '?') {
      Query(1, N, 1);
      Ans = (Ans + Mod) % Mod;
      printf("%I64d\n", Ans);
    } else
      Change(1, N, 1);
  }
}