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;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long maxn = 1e5 + 5, N = 512 + 5, SQ = 600, base = 800287,
                mod = 1e9 + 7, INF = 1e12 + 5, lg = 20;
const long double eps = 1e-4;
struct node {
  long long sum, z, lazy;
};
node seg[6][4 * maxn];
long long n, m, a[maxn], C[10][10];
long long power(long long a, long long b) {
  long long res = 1;
  a = (a + mod) % mod;
  for (long long i = 0; i < b; ++i) {
    res = (res * a) % mod;
  }
  return res;
}
inline node merge(node a, node b) {
  node res;
  res.lazy = -1;
  res.sum = (a.sum + b.sum) % mod;
  res.z = (a.z + b.z) % mod;
  return res;
}
inline void shift(long long k, long long v) {
  if (seg[k][v].lazy == -1) {
    return;
  }
  long long x = seg[k][v].lazy;
  seg[k][2 * v].lazy = seg[k][2 * v + 1].lazy = x;
  seg[k][2 * v].sum = (x * seg[k][2 * v].z) % mod;
  seg[k][2 * v + 1].sum = (x * seg[k][2 * v + 1].z) % mod;
  seg[k][v].lazy = -1;
}
void build(long long k, long long v = 1, long long s = 0, long long e = n) {
  if (e - s == 1) {
    seg[k][v].lazy = -1;
    seg[k][v].z = power(s + 1, k);
    seg[k][v].sum = (a[s] * seg[k][v].z) % mod;
    return;
  }
  build(k, 2 * v, s, (s + e) / 2);
  build(k, 2 * v + 1, (s + e) / 2, e);
  seg[k][v] = merge(seg[k][2 * v], seg[k][2 * v + 1]);
}
void modify(long long k, long long l, long long r, long long x, long long v = 1,
            long long s = 0, long long e = n) {
  if (l >= e || s >= r) {
    return;
  }
  if (l <= s && e <= r) {
    seg[k][v].lazy = x;
    seg[k][v].sum = (x * seg[k][v].z) % mod;
    return;
  }
  shift(k, v);
  modify(k, l, r, x, 2 * v, s, (s + e) / 2);
  modify(k, l, r, x, 2 * v + 1, (s + e) / 2, e);
  seg[k][v] = merge(seg[k][2 * v], seg[k][2 * v + 1]);
}
long long get(long long k, long long j, long long l, long long r,
              long long v = 1, long long s = 0, long long e = n) {
  if (l >= e || s >= r) {
    return 0;
  }
  if (l <= s && e <= r) {
    return (((C[k][j] * seg[j][v].sum) % mod) * power(-l, k - j)) % mod;
  }
  shift(j, v);
  return (get(k, j, l, r, 2 * v, s, (s + e) / 2) +
          get(k, j, l, r, 2 * v + 1, (s + e) / 2, e)) %
         mod;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < 6; ++i) {
    build(i);
  }
  for (long long i = 0; i < 10; ++i) {
    C[i][0] = 1;
  }
  for (long long i = 0; i < 10; ++i) {
    for (long long j = 1; j <= i; ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
  }
  for (long long i = 0; i < m; ++i) {
    char type;
    long long l, r, x, k;
    cin >> type;
    if (type == '=') {
      cin >> l >> r >> x;
      l--;
      for (long long i = 0; i < 6; ++i) {
        modify(i, l, r, x);
      }
    } else {
      cin >> l >> r >> k;
      l--;
      long long res = 0;
      for (long long j = 0; j <= k; ++j) {
        res = (res + get(k, j, l, r)) % mod;
      }
      cout << res << '\n';
    }
  }
}