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>
const int N = 1e5;
const int P = 1e9 + 7;
struct Node {
  int sum[6], tag;
};
Node t[(N << 2) + 10];
int a[N + 10], n, m, s[N + 10][6], C[6][6];
inline int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }
inline int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1LL * res * a % P;
    a = 1LL * a * a % P;
    b >>= 1;
  }
  return res;
}
inline void pushUp(int i) {
  for (int j = 0; j < 6; j++)
    t[i].sum[j] = add(t[(i << 1)].sum[j], t[(i << 1 | 1)].sum[j]);
}
inline void pushTag(int i, int l, int r, int tag) {
  t[i].tag = tag;
  for (int j = 0; j < 6; j++)
    t[i].sum[j] = 1LL * tag * (s[r][j] - s[l - 1][j] + P) % P;
}
inline void pushDown(int i, int l, int r) {
  if (t[i].tag != -1) {
    int mid = (l + r) >> 1;
    pushTag((i << 1), l, mid, t[i].tag);
    pushTag((i << 1 | 1), mid + 1, r, t[i].tag);
    t[i].tag = -1;
  }
}
void build(int i, int l, int r) {
  t[i].tag = -1;
  if (l == r) {
    for (int j = 0; j < 6; j++) t[i].sum[j] = 1LL * a[l] * qpow(l, j) % P;
    return;
  }
  int mid = (l + r) >> 1;
  build((i << 1), l, mid);
  build((i << 1 | 1), mid + 1, r);
  pushUp(i);
}
void modify(int i, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) return pushTag(i, l, r, v);
  int mid = (l + r) >> 1;
  pushDown(i, l, r);
  if (ql <= mid) modify((i << 1), l, mid, ql, qr, v);
  if (qr > mid) modify((i << 1 | 1), mid + 1, r, ql, qr, v);
  pushUp(i);
}
int query(int i, int l, int r, int ql, int qr, int k) {
  if (ql <= l && r <= qr) return t[i].sum[k];
  int mid = (l + r) >> 1;
  pushDown(i, l, r);
  int res = 0;
  if (ql <= mid) res = add(res, query((i << 1), l, mid, ql, qr, k));
  if (qr > mid) res = add(res, query((i << 1 | 1), mid + 1, r, ql, qr, k));
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int j = 0; j <= 5; j++) s[0][j] = qpow(0, j);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 6; j++) s[i][j] = add(s[i - 1][j], qpow(i, 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]);
  }
  build(1, 1, n);
  while (m--) {
    char opt[5];
    int l, r, v;
    scanf("%s%d%d%d", opt, &l, &r, &v);
    if (opt[0] == '=')
      modify(1, 1, n, l, r, v);
    else {
      int ans = 0;
      for (int j = 0; j <= v; j++) {
        int res = 1LL * C[v][j] * qpow((1 - l + P) % P, v - j) % P *
                  query(1, 1, n, l, r, j) % P;
        ans = add(ans, res);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}