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;
const int N = 100010;
const long long MOD = 1000000007;
struct Seg_tree {
  int left, right;
  long long lazy, sum[6];
} T[N << 2];
int n, q, a[N];
long long i_pow_j[N][6];
long long sum[N][6] = {0};
long long C[6][6];
long long s[N][6];
void Init() {
  for (int i = 0; i < 6; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]);
  }
  for (int i = 1; i <= n; i++) {
    i_pow_j[i][0] = 1;
    sum[i][0] = i;
    s[i][0] = 1;
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j <= n; j++) {
      i_pow_j[j][i] = (i_pow_j[j][i - 1] * j) % MOD;
      sum[j][i] = (sum[j - 1][i] + i_pow_j[j][i]) % MOD;
      s[j][i] = ((s[j][i - 1] * (1 - j)) % MOD + MOD) % MOD;
    }
  }
}
void push_up(int id) {
  for (int i = 0; i < 6; i++)
    T[id].sum[i] = (T[(id << 1)].sum[i] + T[(id << 1 | 1)].sum[i]) % MOD;
}
void update(int id, int l, int r, int x);
void push_down(int id) {
  if (T[id].lazy != -1) {
    int l = T[id].left, r = T[id].right, m = (l + r) >> 1;
    update((id << 1), l, m, T[id].lazy);
    update((id << 1 | 1), m + 1, r, T[id].lazy);
    T[id].lazy = -1;
  }
}
void bulid(int id, int l, int r) {
  T[id].left = l;
  T[id].right = r;
  T[id].lazy = -1;
  if (l == r) {
    for (int i = 0; i <= 5; i++) T[id].sum[i] = (a[l] * i_pow_j[l][i]) % MOD;
    return;
  }
  int m = (l + r) >> 1;
  bulid((id << 1), l, m);
  bulid((id << 1 | 1), m + 1, r);
  push_up(id);
}
void update(int id, int L, int R, int x) {
  if (T[id].left == L && T[id].right == R) {
    T[id].lazy = x;
    for (int i = 0; i < 6; i++) {
      long long tmp = ((sum[R][i] - sum[L - 1][i]) % MOD + MOD) % MOD;
      T[id].sum[i] = (tmp * x) % MOD;
    }
    return;
  }
  push_down(id);
  int m = (T[id].left + T[id].right) >> 1;
  if (R <= m)
    update((id << 1), L, R, x);
  else if (L > m)
    update((id << 1 | 1), L, R, x);
  else {
    update((id << 1), L, m, x);
    update((id << 1 | 1), m + 1, R, x);
  }
  push_up(id);
}
long long query(int id, int l, int r, int k) {
  if (T[id].left == l && T[id].right == r) return T[id].sum[k];
  int m = (T[id].left + T[id].right) >> 1;
  push_down(id);
  if (r <= m)
    return query((id << 1), l, r, k);
  else if (l > m)
    return query((id << 1 | 1), l, r, k);
  else
    return (query((id << 1), l, m, k) + query((id << 1 | 1), m + 1, r, k)) %
           MOD;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  Init();
  bulid(1, 1, n);
  while (q--) {
    char ope[5];
    int l, r, k;
    scanf("%s%d%d%d", &ope, &l, &r, &k);
    if (ope[0] == '=')
      update(1, l, r, k);
    else {
      long long ans = 0;
      for (int i = 0; i <= k; i++)
        ans =
            ((((query(1, l, r, i) * C[k][i]) % MOD * s[l][k - i]) % MOD + ans) %
                 MOD +
             MOD) %
            MOD;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}