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 mN = 1e5 + 100, mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mul(int a, int b) { return (1LL * a * b) % mod; }
struct node {
  int sum[6];
  int hasL, lz, s, e;
};
node tree[4 * mN];
int arr[mN], helper[6][mN], nCr[6][6];
void upd(int idx, int s, int e, int val) {
  tree[idx].hasL = 1;
  tree[idx].lz = val;
  for (int i = 0; i < 6; ++i) tree[idx].sum[i] = mul(val, helper[i][e - s + 1]);
}
void shift(int idx, int s, int e) {
  if (!tree[idx].hasL) return;
  tree[idx].hasL = 0;
  int m = s + ((e - s) >> 1), L = (idx << 1) + 1, R = L + 1;
  upd(L, s, m, tree[idx].lz);
  upd(R, m + 1, e, tree[idx].lz);
}
int w[6];
void merge(node &r, node &L, node &R) {
  r.hasL = 0;
  r.s = L.s;
  r.e = R.e;
  w[0] = 1;
  for (int i = 0; i < 5; ++i) w[i + 1] = mul(w[i], L.e - L.s + 1);
  for (int i = 0; i < 6; ++i) {
    r.sum[i] = L.sum[i];
    for (int xp = i, wp = 0; xp >= 0; --xp, ++wp) {
      add(r.sum[i], mul(w[wp], mul(nCr[i][xp], R.sum[xp])));
    }
  }
}
void build(int idx, int s, int e) {
  if (s == e) {
    upd(idx, s, e, arr[s]);
    tree[idx].s = s;
    tree[idx].e = e;
    tree[idx].hasL = 0;
    return;
  }
  int m = s + ((e - s) >> 1), L = (idx << 1) + 1, R = L + 1;
  build(L, s, m);
  build(R, m + 1, e);
  merge(tree[idx], tree[L], tree[R]);
}
void assign(int idx, int s, int e, int a, int b, int val) {
  if (s >= a && e <= b) {
    upd(idx, s, e, val);
    return;
  }
  if (e < a || s > b) return;
  shift(idx, s, e);
  int m = s + ((e - s) >> 1), L = (idx << 1) + 1, R = L + 1;
  assign(L, s, m, a, b, val);
  assign(R, m + 1, e, a, b, val);
  merge(tree[idx], tree[L], tree[R]);
}
node get(int idx, int s, int e, int a, int b) {
  if (s >= a && e <= b) return tree[idx];
  shift(idx, s, e);
  int m = s + ((e - s) >> 1), L = (idx << 1) + 1, R = L + 1;
  if (a >= m + 1) return get(R, m + 1, e, a, b);
  if (b <= m) return get(L, s, m, a, b);
  node res, Lr, Rr;
  Lr = get(L, s, m, a, b);
  Rr = get(R, m + 1, e, a, b);
  merge(res, Lr, Rr);
  return res;
}
void pre() {
  for (int i = 0; i < 6; ++i) {
    for (int j = 1; j < mN; ++j) {
      helper[i][j] = 1;
      for (int k = 0; k < i; ++k) {
        helper[i][j] = (1LL * helper[i][j] * j) % mod;
      }
      add(helper[i][j], helper[i][j - 1]);
    }
  }
  for (int i = 0; i < 6; ++i) nCr[i][i] = nCr[i][0] = 1;
  for (int i = 1; i < 6; ++i)
    for (int j = 1; j < i; ++j) nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1];
}
int n, q, a, b, val;
char type;
int main() {
  pre();
  scanf("%d", &n), scanf("%d", &q);
  for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
  build(0, 0, n - 1);
  for (int i = 0; i < q; ++i) {
    scanf(" %c", &type);
    scanf("%d", &a), scanf("%d", &b), scanf("%d", &val);
    --a, --b;
    if (type == '=') {
      assign(0, 0, n - 1, a, b, val);
    } else {
      node res = get(0, 0, n - 1, a, b);
      printf("%d\n", res.sum[val]);
    }
  }
}