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 MAXN = 100000 + 86;
const int MOD = 1000000007;
int C[6][6];
int p[MAXN][6];
int s[MAXN][6];
inline int sgn(const int x) { return x & 1 ? -1 : 1; }
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]) % MOD;
  }
  p[0][0] = 1;
  for (int i = 1; i < MAXN; i++) {
    p[i][0] = 1;
    for (int j = 1; j < 6; j++) p[i][j] = (long long)i * p[i][j - 1] % MOD;
    for (int j = 0; j < 6; j++) s[i][j] = (s[i - 1][j] + p[i][j]) % MOD;
  }
}
struct seg_tree {
  int x[MAXN << 2][6];
  int v[MAXN << 2];
  void init() { memset(v, -1, sizeof(v)); }
  void pushup(int rt) {
    for (int i = 0; i < 6; i++)
      x[rt][i] = (x[rt << 1][i] + x[rt << 1 | 1][i]) % MOD;
  }
  void pushdown(int rt, int l, int r) {
    if (v[rt] == -1) return;
    int mid = (l + r) >> 1;
    v[rt << 1] = v[rt << 1 | 1] = v[rt];
    for (int i = 0; i < 6; i++) {
      x[rt << 1][i] = (long long)v[rt] * (s[mid][i] - s[l - 1][i]) % MOD;
      if (x[rt << 1][i] < 0) x[rt << 1][i] += MOD;
      x[rt << 1 | 1][i] = (long long)v[rt] * (s[r][i] - s[mid][i]) % MOD;
      if (x[rt << 1 | 1][i] < 0) x[rt << 1 | 1][i] += MOD;
    }
    v[rt] = -1;
  }
  void modify(int rt, int l, int r, const int L, const int R, const int k) {
    if (L <= l && r <= R) {
      v[rt] = k;
      for (int i = 0; i < 6; i++) {
        x[rt][i] = (long long)k * (s[r][i] - s[l - 1][i]) % MOD;
        if (x[rt][i] < 0) x[rt][i] += MOD;
      }
      return;
    }
    pushdown(rt, l, r);
    int mid = (l + r) >> 1;
    if (L <= mid) modify(rt << 1, l, mid, L, R, k);
    if (R > mid) modify(rt << 1 | 1, mid + 1, r, L, R, k);
    pushup(rt);
  }
  int query(int rt, int l, int r, const int L, const int R, const int k) {
    if (L <= l && r <= R) {
      int tot = 0, off = L - 1;
      for (int j = 0; j <= k; j++) {
        int cc = (long long)C[k][j] * p[off][k - j] % MOD;
        cc = (long long)cc * x[rt][j] * sgn(k - j) % MOD;
        tot = (tot + cc) % MOD;
        if (tot < 0) tot += MOD;
      }
      return tot;
    }
    pushdown(rt, l, r);
    int mid = (l + r) >> 1;
    int c1 = 0, c2 = 0;
    if (L <= mid) c1 = query(rt << 1, l, mid, L, R, k);
    if (R > mid) c2 = query(rt << 1 | 1, mid + 1, r, L, R, k);
    return (c1 + c2) % MOD;
  }
} T;
int main() {
  init();
  T.init();
  int n, m;
  int L, R, x;
  char op[5];
  scanf("%d%d", &n, &m);
  for (int i = 1, j; i <= n; i++) {
    scanf("%d", &j);
    T.modify(1, 1, n, i, i, j);
  }
  while (m--) {
    scanf("%s%d%d%d", op, &L, &R, &x);
    if (op[0] == '=')
      T.modify(1, 1, n, L, R, x);
    else
      printf("%d\n", T.query(1, 1, n, L, R, x));
  }
  return 0;
}