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;
struct node {
  int sum[6], cov;
} tr[110000 << 2], now;
char op[5];
int sum[110000][6], C[6][6];
int pow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = (long long)ret * x % 1000000007;
    x = (long long)x * x % 1000000007;
    y >>= 1;
  }
  return ret;
}
void init(int n) {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    for (j = 0, k = 1; j <= 5; j++, k = (long long)k * (i + 1) % 1000000007) {
      sum[i][j] = (sum[i - 1][j] + k) % 1000000007;
    }
  }
  for (i = 0; i <= 5; i++) {
    C[i][0] = 1;
    for (j = 1; j <= 5; j++) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
    }
  }
}
void Change(node &a, int l, int r, int val) {
  for (int i = 0; i <= 5; i++) {
    a.sum[i] =
        (long long)val * (sum[r][i] - sum[l - 1][i] + 1000000007) % 1000000007;
  }
  a.cov = val;
}
node operator+(const node &a, const node &b) {
  static node ret;
  for (int i = 0; i <= 5; i++) ret.sum[i] = (a.sum[i] + b.sum[i]) % 1000000007;
  ret.cov = -1;
  return ret;
}
void Pushdown(int no, int l, int r) {
  if (tr[no].cov != -1) {
    int mid = l + r >> 1;
    Change(tr[no << 1], l, mid, tr[no].cov);
    Change(tr[no << 1 | 1], mid + 1, r, tr[no].cov);
    tr[no].cov = -1;
  }
}
void Build(int l, int r, int no) {
  if (l == r) {
    scanf("%d", &tr[no].sum[0]);
    tr[no].sum[1] = (long long)tr[no].sum[0] * (l + 1) % 1000000007;
    tr[no].sum[2] = (long long)tr[no].sum[1] * (l + 1) % 1000000007;
    tr[no].sum[3] = (long long)tr[no].sum[2] * (l + 1) % 1000000007;
    tr[no].sum[4] = (long long)tr[no].sum[3] * (l + 1) % 1000000007;
    tr[no].sum[5] = (long long)tr[no].sum[4] * (l + 1) % 1000000007;
    tr[no].cov = -1;
  } else {
    int mid = l + r >> 1;
    Build(l, mid, no << 1);
    Build(mid + 1, r, no << 1 | 1);
    tr[no] = tr[no << 1] + tr[no << 1 | 1];
  }
}
void update(int l, int r, int no, int st, int en, int val) {
  if (st <= l && r <= en)
    Change(tr[no], l, r, val);
  else {
    int mid = l + r >> 1;
    Pushdown(no, l, r);
    if (en <= mid)
      update(l, mid, no << 1, st, en, val);
    else if (st > mid)
      update(mid + 1, r, no << 1 | 1, st, en, val);
    else
      update(l, mid, no << 1, st, en, val),
          update(mid + 1, r, no << 1 | 1, st, en, val);
    tr[no] = tr[no << 1] + tr[no << 1 | 1];
  }
}
node query(int l, int r, int no, int st, int en) {
  if (st <= l && r <= en)
    return tr[no];
  else {
    int mid = l + r >> 1;
    Pushdown(no, l, r);
    if (en <= mid)
      return query(l, mid, no << 1, st, en);
    else if (st > mid)
      return query(mid + 1, r, no << 1 | 1, st, en);
    else
      return query(l, mid, no << 1, st, en) +
             query(mid + 1, r, no << 1 | 1, st, en);
  }
}
int main() {
  int n, m, i, j, k, l, r, x, ans;
  scanf("%d%d", &n, &m);
  init(n);
  Build(1, n, 1);
  for (i = 1; i <= m; i++) {
    scanf("%s%d%d%d", op, &l, &r, &x);
    if (op[0] == '=') {
      update(1, n, 1, l, r, x);
    } else {
      now = query(1, n, 1, l, r);
      for (j = 0, ans = 0; j <= x; j++) {
        ans = (ans +
               ((long long)C[x][j] * pow(-l, x - j) % 1000000007 + 1000000007) *
                   now.sum[j] % 1000000007) %
              1000000007;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}