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 mul(long long a1, long long a2) { return (a1 * a2) % 1000000007; }
long long add(long long a1, long long a2) { return (a1 + a2) % 1000000007; }
struct segt {
  int len;
  long long value[6];
  long long lz;
};
segt tree[262192];
long long a[262192 >> 1];
long long prefix[262192][6];
long long pw[262192][6];
long long c[6][6];
void precompute() {
  int i, j;
  c[0][0] = 1;
  c[1][0] = 1;
  c[1][1] = 1;
  for (i = 2; i < 6; i++) {
    c[i][0] = 1;
    for (j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
  for (i = 1; i < 262192; i++) {
    long long curr = 1;
    for (j = 0; j < 6; j++) {
      prefix[i][j] = add(prefix[i - 1][j], curr);
      pw[i][j] = curr;
      curr = mul(curr, i);
    }
  }
}
segt pullup(segt t1, segt t2) {
  segt ret;
  int i, j;
  ret.lz = -1;
  ret.len = t1.len + t2.len;
  for (i = 0; i < 6; i++) {
    ret.value[i] = t1.value[i];
    for (j = 0; j <= i; j++) {
      ret.value[i] =
          add(ret.value[i], mul(c[i][j], mul(pw[t1.len][i - j], t2.value[j])));
    }
  }
  return ret;
}
void pushdown(int index) {
  if (tree[index].lz != -1) {
    if (tree[index].len > 1) {
      tree[index * 2].lz = tree[index].lz;
      tree[index * 2 + 1].lz = tree[index].lz;
      int i;
      for (i = 0; i < 6; i++) {
        tree[index * 2].value[i] =
            mul(tree[index].lz, prefix[tree[index * 2].len][i]);
        tree[index * 2 + 1].value[i] =
            mul(tree[index].lz, prefix[tree[index * 2 + 1].len][i]);
      }
    }
    tree[index].lz = -1;
  }
}
void build(int l, int r, int index) {
  if (l > r) return;
  if (l == r) {
    int i;
    for (i = 0; i < 6; i++) {
      tree[index].value[i] = a[l];
    }
    tree[index].len = 1;
    tree[index].lz = -1;
    return;
  }
  int mid = l + (r - l) / 2;
  build(l, mid, index * 2);
  build(mid + 1, r, index * 2 + 1);
  tree[index] = pullup(tree[index * 2], tree[index * 2 + 1]);
}
void update(int start, int end, int l, int r, int index, long long val) {
  if (start > end || l > r) return;
  pushdown(index);
  if (start <= l && r <= end) {
    tree[index].lz = val;
    for (int i = 0; i < 6; i++) {
      tree[index].value[i] = mul(val, prefix[tree[index].len][i]);
    }
    return;
  }
  int mid = l + (r - l) / 2;
  if (end <= mid) {
    update(start, end, l, mid, index * 2, val);
  } else if (start >= mid + 1) {
    update(start, end, mid + 1, r, index * 2 + 1, val);
  } else {
    update(start, end, l, mid, index * 2, val);
    update(start, end, mid + 1, r, index * 2 + 1, val);
  }
  tree[index] = pullup(tree[index * 2], tree[index * 2 + 1]);
}
segt query(int start, int end, int l, int r, int index) {
  if (start > end || l > r) return tree[0];
  pushdown(index);
  if (start <= l && r <= end) return tree[index];
  int mid = l + (r - l) / 2;
  if (end <= mid) return query(start, end, l, mid, index * 2);
  if (start >= mid + 1) return query(start, end, mid + 1, r, index * 2 + 1);
  return pullup(query(start, end, l, mid, index * 2),
                query(start, end, mid + 1, r, index * 2 + 1));
}
char st[4];
int main() {
  precompute();
  int n, m, i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  build(1, n, 1);
  for (i = 0; i < m; i++) {
    int l, r, val;
    scanf("%s%d%d%d", st, &l, &r, &val);
    if (st[0] == '?') {
      printf("%lld\n", query(l, r, 1, n, 1).value[val]);
    } else {
      update(l, r, 1, n, 1, (long long)val);
    }
  }
  return 0;
}