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 P = 1000000007;
int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }
int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = res * (long long)a % P;
    a = (long long)a * a % P;
    b >>= 1;
  }
  return res;
}
int inv(int x) { return qpow(x, P - 2); }
const int N = 100010;
int n, m, a[N];
int sum[N << 2][6], tag[N << 2], pwk[N][6];
void up(int p) {
  for (int i = 0; i <= 5; ++i)
    sum[p][i] = add(sum[p << 1][i], sum[p << 1 | 1][i]);
}
void change(int p, int v, int l, int r) {
  tag[p] = v;
  for (int i = 0; i <= 5; ++i)
    sum[p][i] = (long long)v * (pwk[r][i] - pwk[l - 1][i] + P) % P;
}
void push(int p, int l, int r) {
  if (tag[p] != -1) {
    int mid = (l + r) >> 1;
    change(p << 1, tag[p], l, mid);
    change(p << 1 | 1, tag[p], mid + 1, r);
    tag[p] = -1;
  }
}
void build(int p, int l, int r) {
  tag[p] = -1;
  if (l == r) {
    for (int i = 0; i <= 5; ++i) sum[p][i] = (long long)a[l] * qpow(l, i) % P;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  up(p);
}
void update(int p, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    change(p, v, l, r);
    return;
  }
  push(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(p << 1, l, mid, L, R, v);
  if (R > mid) update(p << 1 | 1, mid + 1, r, L, R, v);
  up(p);
}
int qry(int p, int l, int r, int L, int R, int t) {
  if (L <= l && r <= R) return sum[p][t];
  push(p, l, r);
  int mid = (l + r) >> 1, res = 0;
  if (L <= mid) res = add(res, qry(p << 1, l, mid, L, R, t));
  if (R > mid) res = add(res, qry(p << 1 | 1, mid + 1, r, L, R, t));
  up(p);
  return res;
}
int c[10][10];
int main() {
  cout << fixed;
  scanf("%d%d", &n, &m);
  for (int j = 0; j <= 5; ++j) pwk[0][j] = qpow(0, j);
  c[0][0] = 1;
  for (int i = 1; i <= 5; ++i) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; ++j) c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= 5; ++j) pwk[i][j] = add(pwk[i - 1][j], qpow(i, j));
  build(1, 1, n);
  for (int q = 1; q <= m; ++q) {
    char op[3];
    int l, r, k;
    scanf("%s%d%d%d", op, &l, &r, &k);
    if (op[0] == '=')
      update(1, 1, n, l, r, k);
    else if (op[0] == '?') {
      int res = 0;
      for (int j = 0; j <= k; ++j) {
        int ans = (long long)c[k][j] * qpow((1 - l + P) % P, k - j) % P *
                  qry(1, 1, n, l, r, j) % P;
        res = add(res, ans);
      }
      printf("%d\n", res);
    }
  }
  return 0;
}