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 = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
long long P[N][6];
int a[N];
int c[6][6];
long long pow(int x, int n) {
  long long ans = 1;
  for (int i = 0; i < n; ++i) ans = (ans * (long long)x) % MOD;
  return ans;
}
void init(int n) {
  memset(c, 0, sizeof(c));
  c[0][0] = 1;
  for (int i = 1; i < 6; ++i) {
    for (int j = 0; j <= i; ++j) {
      c[i][j] = j == 0 ? 1 : (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
    }
  }
  for (int j = 0; j < 6; ++j) P[0][j] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 6; ++j) {
      P[i][j] = (P[i - 1][j] + pow(i, j)) % MOD;
    }
  }
}
struct node {
  int flag;
  long long v[6];
  int l, r;
  void go(int val) {
    flag = val;
    for (int i = 0; i < 6; ++i)
      v[i] = ((((P[r][i] - P[l - 1][i]) % MOD + MOD) % MOD) * flag) % MOD;
  }
};
node tree[N << 2];
void pushup(int rt) {
  for (int i = 0; i < 6; ++i)
    tree[rt].v[i] = (tree[rt << 1].v[i] + tree[rt << 1 | 1].v[i]) % MOD;
}
void pushdown(int rt) {
  if (tree[rt].flag != -1) {
    tree[rt << 1].go(tree[rt].flag);
    tree[rt << 1 | 1].go(tree[rt].flag);
    tree[rt].flag = -1;
  }
}
void build(int rt, int l, int r) {
  tree[rt].flag = -1;
  tree[rt].l = l, tree[rt].r = r;
  if (l == r) {
    for (int i = 0; i < 6; ++i) tree[rt].v[i] = (a[l] * pow(l, i)) % MOD;
  } else {
    int mid = l + r >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid + 1, r);
    pushup(rt);
  }
}
void update(int rt, int l, int r, int s, int e, int val) {
  if (s <= l && r <= e)
    tree[rt].go(val);
  else {
    pushdown(rt);
    int mid = l + r >> 1;
    if (s <= mid) update(rt << 1, l, mid, s, e, val);
    if (e > mid) update(rt << 1 | 1, mid + 1, r, s, e, val);
    pushup(rt);
  }
}
long long query(int rt, int l, int r, int s, int e, int k) {
  if (s <= l && r <= e)
    return tree[rt].v[k];
  else {
    pushdown(rt);
    long long sum = 0;
    int mid = l + r >> 1;
    if (s <= mid) sum = (sum + query(rt << 1, l, mid, s, e, k)) % MOD;
    if (e > mid) sum = (sum + query(rt << 1 | 1, mid + 1, r, s, e, k)) % MOD;
    pushup(rt);
    return sum;
  }
}
int main() {
  int n, m;
  init(N - 1);
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
    build(1, 1, n);
    while (m--) {
      char op[5];
      int l, r, k;
      scanf("%s%d%d%d", op, &l, &r, &k);
      if (op[0] == '=')
        update(1, 1, n, l, r, k);
      else {
        long long ans = 0, fac = 1;
        for (int i = 0; i <= k; ++i) {
          ans = (ans +
                 ((query(1, 1, n, l, r, k - i) * c[k][i]) % MOD * fac) % MOD +
                 MOD) %
                MOD;
          fac = (fac * (1 - l)) % MOD;
        }
        printf("%I64d\n", ans);
      }
    }
  }
  return 0;
}