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 double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const int hinf = 0x3f3f3f3f;
const long long mod = 1000000007;
struct node {
  int l, r;
  long long sum[6], add;
} sgt[100010 << 2];
int dat[100010];
int n, m;
int cm[6][6];
long long p[100010][6];
long long s[100010][6];
void up(int root) {
  for (int i = 0; i < 6; i++)
    sgt[root].sum[i] = sgt[root << 1].sum[i] + sgt[root << 1 | 1].sum[i];
}
void down(int root) {
  if (sgt[root].add == -1) return;
  for (int i = 0; i < 6; i++) {
    sgt[root << 1].sum[i] =
        (sgt[root].add *
             ((s[sgt[root << 1].r][i] - s[sgt[root << 1].l - 1][i] + mod) %
              mod) +
         mod) %
        mod;
    sgt[root << 1 | 1].sum[i] =
        (sgt[root].add * ((s[sgt[root << 1 | 1].r][i] -
                           s[sgt[root << 1 | 1].l - 1][i] + mod) %
                          mod) +
         mod) %
        mod;
  }
  sgt[root << 1].add = sgt[root].add;
  sgt[root << 1 | 1].add = sgt[root].add;
  sgt[root].add = -1;
}
void build(int l, int r, int root) {
  sgt[root].l = l;
  sgt[root].r = r;
  sgt[root].add = -1;
  if (l == r) {
    for (int i = 0; i < 6; i++)
      sgt[root].sum[i] = (1ll * dat[l] * p[l][i]) % mod;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, root << 1);
  build(mid + 1, r, root << 1 | 1);
  up(root);
}
long long pm(int i, int j) {
  long long ans = 1;
  for (int k = 1; k <= j; k++) {
    ans = (ans * 1ll * i) % mod;
  }
  return ans;
}
void init() {
  memset(cm, 0, sizeof(cm));
  memset(p, 0, sizeof(p));
  memset(s, 0, sizeof(s));
  for (int i = 0; i <= 5; i++) cm[i][i] = cm[i][0] = 1;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j < i; j++) cm[i][j] = cm[i - 1][j] + cm[i - 1][j - 1];
  for (int i = 0; i <= 100000; i++) {
    for (int j = 0; j <= 5; j++) {
      p[i][j] = pm(i, j);
    }
  }
  for (int j = 0; j < 6; j++) {
    for (int i = 1; i <= 100000; i++) {
      s[i][j] = (s[i - 1][j] + p[i][j]) % mod;
    }
  }
}
void upd(int l, int r, int val, int root) {
  if (sgt[root].l >= l && sgt[root].r <= r) {
    sgt[root].add = val;
    for (int i = 0; i < 6; i++) {
      sgt[root].sum[i] =
          (1ll * val *
               ((s[sgt[root].r][i] - s[sgt[root].l - 1][i] + mod) % mod) +
           mod) %
          mod;
    }
    return;
  }
  down(root);
  int mid = (sgt[root].l + sgt[root].r) >> 1;
  if (l <= mid) upd(l, r, val, root << 1);
  if (r > mid) upd(l, r, val, root << 1 | 1);
  up(root);
}
long long check(int l, int r, int root, int cifang) {
  if (sgt[root].l >= l && sgt[root].r <= r) return sgt[root].sum[cifang];
  down(root);
  long long ret = 0;
  int mid = (sgt[root].l + sgt[root].r) >> 1;
  if (l <= mid) ret = (ret + check(l, r, root << 1, cifang) + mod) % mod;
  if (r > mid) ret = (ret + check(l, r, root << 1 | 1, cifang) + mod) % mod;
  return ret;
}
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &dat[i]);
  build(1, n, 1);
  char choose[5];
  int a, b, c;
  while (m--) {
    scanf("%s %d%d%d", choose, &a, &b, &c);
    if (choose[0] == '=') {
      upd(a, b, c, 1);
    } else if (choose[0] == '?') {
      long long ans;
      long long ttt = 1ll;
      long long output = 0ll;
      for (int i = 0; i <= c; i++) {
        ans = check(a, b, 1, c - i);
        output = (output + ans * cm[c][i] % mod * ttt % mod + mod) % mod;
        ttt = ttt * (1 - a) % mod;
      }
      cout << output << '\n';
    }
  }
}