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;
int n, m;
int a[100005];
struct node {
  int l, r;
  int data;
  long long int sum;
} tree[6][100005 << 2];
long long f[100005][6], g[100005][6];
void build(int P, int p, int l, int r) {
  tree[P][p].l = l;
  tree[P][p].r = r;
  if (l == r) {
    tree[P][p].data = a[l];
    tree[P][p].sum = (g[l][P] * a[l]) % 1000000007;
    return;
  }
  int mid = (l + r) >> 1;
  build(P, p << 1, l, mid);
  build(P, p << 1 | 1, mid + 1, r);
  tree[P][p].sum = (tree[P][p << 1].sum + tree[P][p << 1 | 1].sum) % 1000000007;
  if (tree[P][p << 1].data == tree[P][p << 1 | 1].data)
    tree[P][p].data = tree[P][p << 1].data;
  else
    tree[P][p].data = -1;
}
void updata(int P, int p, int l, int r) {
  tree[P][p << 1].data = tree[P][p << 1 | 1].data = tree[P][p].data;
  int mid = (l + r) >> 1;
  tree[P][p << 1].sum =
      (f[mid][P] - f[l - 1][P]) * tree[P][p].data % 1000000007;
  tree[P][p << 1 | 1].sum =
      (f[r][P] - f[mid][P]) * tree[P][p].data % 1000000007;
}
void insert(int P, int p, int l, int r, int data) {
  if (tree[P][p].l == l && tree[P][p].r == r) {
    tree[P][p].data = data;
    tree[P][p].sum = (f[r][P] - f[l - 1][P]) * data % 1000000007;
    return;
  }
  if (tree[P][p].data >= 0) {
    updata(P, p, tree[P][p].l, tree[P][p].r);
    tree[P][p].data = -1;
  }
  int mid = (tree[P][p].l + tree[P][p].r) >> 1;
  if (mid >= r)
    insert(P, p << 1, l, r, data);
  else if (mid < l)
    insert(P, p << 1 | 1, l, r, data);
  else {
    insert(P, p << 1, l, mid, data);
    insert(P, p << 1 | 1, mid + 1, r, data);
  }
  tree[P][p].sum = (tree[P][p << 1].sum + tree[P][p << 1 | 1].sum) % 1000000007;
}
long long cal(int P, int p, int l, int r) {
  if (tree[P][p].l == l && tree[P][p].r == r) return tree[P][p].sum;
  if (tree[P][p].data >= 0) updata(P, p, tree[P][p].l, tree[P][p].r);
  int mid = (tree[P][p].l + tree[P][p].r) >> 1;
  if (mid >= r)
    return cal(P, p << 1, l, r);
  else if (mid < l)
    return cal(P, p << 1 | 1, l, r);
  else {
    long long tmp1 = cal(P, p << 1, l, mid);
    long long tmp2 = cal(P, p << 1 | 1, mid + 1, r);
    return (tmp1 + tmp2) % 1000000007;
  }
}
int c[6][6];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int j = 0; j <= 100000; j++) {
    g[j][0] = 1;
    for (int i = 1; i <= 5; i++) g[j][i] = g[j][i - 1] * j % 1000000007;
  }
  for (int i = 0; i <= 5; i++)
    for (int j = 1; j <= 100000; j++)
      f[j][i] = (f[j - 1][i] + g[j][i]) % 1000000007;
  for (int i = 0; i <= 5; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  for (int i = 0; i <= 5; i++) build(i, 1, 1, n);
  char st[5];
  int l, r, k;
  while (m--) {
    scanf("%s%d%d%d", st, &l, &r, &k);
    if (st[0] == '=') {
      for (int i = 0; i <= 5; i++) insert(i, 1, l, r, k);
    } else {
      long long ans = 0, t = 1;
      for (int i = k; i >= 0; i--) {
        ans = (ans + cal(i, 1, l, r) * t % 1000000007 * c[k][i] % 1000000007) %
              1000000007;
        t = t * (1 - l) % 1000000007;
      }
      if (ans < 0) ans += 1000000007;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}