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;
long long read() {
  long long res(0), sign(1);
  char c;
  while (1) {
    c = getchar();
    if ('0' <= c && c <= '9') {
      res = c - '0';
      break;
    } else if (c == '-') {
      sign = -1;
      break;
    }
  }
  while (1) {
    c = getchar();
    if ('0' <= c && c <= '9')
      res = res * 10 + c - '0';
    else
      break;
  }
  return res * sign;
}
class segment {
 public:
  long long val;
  long long k[6];
  segment() { memset(k, 0, sizeof k); }
} ST[262145];
long long M, N;
long long T[6][100003];
long long comb[6][6];
long long C(long long n, long long r) {
  long long &ret = comb[n][r];
  if (ret) return ret;
  if (n == r || !r) return ret = 1;
  return ret = C(n - 1, r) + C(n - 1, r - 1);
}
long long pow(long long a, long long b) {
  if (!b) return 1;
  long long t = pow(a, b >> 1);
  t = (t * t) % 1000000007ll;
  return (b & 1) ? (t * a) % 1000000007ll : t;
}
long long H(long long a, long long b, long long k) {
  return (T[k][b] - T[k][a - 1] + 1000000007ll) % 1000000007ll;
}
void upd(long long pos, long long second, long long e, long long val) {
  long long i;
  ST[pos].val = val;
  for (i = 0; i <= 6 - 1; i++)
    ST[pos].k[i] = (val * H(second, e, i)) % 1000000007ll;
}
void push(long long pos, long long second, long long e) {
  if (ST[pos].val == -1) return;
  long long m = (second + e) >> 1;
  long long sol = pos << 1;
  long long sag = sol | 1;
  upd(sol, second, m, ST[pos].val);
  upd(sag, m + 1, e, ST[pos].val);
  ST[pos].val = -1;
}
void init(long long pos, long long second, long long e) {
  ST[pos].val = -1;
  if (second == e) {
    upd(pos, second, e, read());
    return;
  }
  long long m = (second + e) >> 1;
  long long sol = pos << 1;
  long long sag = sol | 1;
  init(sol, second, m);
  init(sag, m + 1, e);
  long long i;
  for (i = 0; i <= 6 - 1; i++)
    ST[pos].k[i] = (ST[sol].k[i] + ST[sag].k[i]) % 1000000007ll;
}
void update(long long pos, long long second, long long e, long long a,
            long long b, long long val) {
  if (a > e || b < second) return;
  if (a <= second && e <= b) {
    upd(pos, second, e, val);
    return;
  }
  long long m = (second + e) >> 1;
  long long sol = pos << 1;
  long long sag = sol | 1;
  push(pos, second, e);
  update(sol, second, m, a, b, val);
  update(sag, m + 1, e, a, b, val);
  long long i;
  for (i = 0; i <= 6 - 1; i++)
    ST[pos].k[i] = (ST[sol].k[i] + ST[sag].k[i]) % 1000000007ll;
}
long long find(long long pos, long long second, long long e, long long a,
               long long b, long long k) {
  if (a > e || b < second) return 0;
  if (a <= second && e <= b) return ST[pos].k[k];
  long long m = (second + e) >> 1;
  long long sol = pos << 1;
  long long sag = sol | 1;
  push(pos, second, e);
  return (find(sol, second, m, a, b, k) + find(sag, m + 1, e, a, b, k)) %
         1000000007ll;
}
int main() {
  long long sum, t;
  long long a, b, i, k;
  char c;
  N = read();
  M = read();
  for (k = 0; k <= 6 - 1; k++)
    for (i = 1; i <= N; i++) T[k][i] = (T[k][i - 1] + pow(i, k)) % 1000000007ll;
  init(1, 1, N);
  while (M--) {
    scanf(" %c", &c);
    a = read();
    b = read();
    k = read();
    if (c == '?') {
      sum = 0;
      for (i = 0; i <= k; i++) {
        t = (pow(1 - a, i) * find(1, 1, N, a, b, k - i) +
             (1000000007ll * 1000000007ll)) %
            1000000007ll;
        sum = (sum + t * C(k, i)) % 1000000007ll;
      }
      printf("%lld\n", sum);
    } else
      update(1, 1, N, a, b, k);
  }
  return 0;
}