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;
template <const int mod>
struct modint {
  int x;
  modint<mod>(int o = 0) { x = (o % mod + mod) % mod; }
  modint<mod> &operator=(int o) { return x = o, *this; }
  modint<mod> &operator+=(modint<mod> o) {
    return x = x + o.x >= mod ? x + o.x - mod : x + o.x, *this;
  }
  modint<mod> &operator-=(modint<mod> o) {
    return x = x - o.x < 0 ? x - o.x + mod : x - o.x, *this;
  }
  modint<mod> &operator*=(modint<mod> o) {
    return x = 1ll * x * o.x % mod, *this;
  }
  modint<mod> &operator+=(int o) {
    return x = x + o >= mod ? x + o - mod : x + o, *this;
  }
  modint<mod> &operator-=(int o) {
    return x = x - o < 0 ? x - o + mod : x - o, *this;
  }
  modint<mod> &operator*=(int o) { return x = 1ll * x * o % mod, *this; }
  template <class I>
  friend modint<mod> operator+(modint<mod> a, I b) {
    return a += b;
  }
  template <class I>
  friend modint<mod> operator-(modint<mod> a, I b) {
    return a -= b;
  }
  template <class I>
  friend modint<mod> operator*(modint<mod> a, I b) {
    return a *= b;
  }
};
const int N = 1e5 + 10;
int n, m, a[N];
modint<1000000007> c[6][6], s[6][N];
void pre() {
  c[0][0] = 1;
  for (int i = 1; i <= 5; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  for (int i = 1; i <= n; i++) s[0][i] = 1;
  for (int j = 1; j <= 5; j++)
    for (int i = 1; i <= n; i++) s[j][i] = s[j - 1][i] * i;
  for (int j = 0; j <= 5; j++)
    for (int i = 1; i <= n; i++) s[j][i] += s[j][i - 1];
}
int l[N << 2], r[N << 2], tag[N << 2];
modint<1000000007> val[6][N << 2];
void down(int x) {
  if (tag[x] != -1) {
    tag[(x << 1)] = tag[x];
    for (int i = 0; i <= 5; i++)
      val[i][(x << 1)] = (s[i][r[(x << 1)]] - s[i][l[(x << 1)] - 1]) * tag[x];
    tag[(x << 1 | 1)] = tag[x];
    for (int i = 0; i <= 5; i++)
      val[i][(x << 1 | 1)] =
          (s[i][r[(x << 1 | 1)]] - s[i][l[(x << 1 | 1)] - 1]) * tag[x];
    tag[x] = -1;
  }
}
void up(int x) {
  for (int i = 0; i <= 5; i++)
    val[i][x] = val[i][(x << 1)] + val[i][(x << 1 | 1)];
}
void build(int x, int l, int r) {
  ::l[x] = l, ::r[x] = r, ::tag[x] = -1;
  if (l == r) {
    for (int i = 0; i <= 5; i++)
      val[i][x] = modint<1000000007>(a[l]) * (s[i][l] - s[i][l - 1]);
    return;
  }
  build((x << 1), l, (l + r >> 1));
  build((x << 1 | 1), (l + r >> 1) + 1, r);
  up(x);
}
void upd(int x, int ql, int qr, int v) {
  if (ql <= l[x] && r[x] <= qr) {
    tag[x] = v;
    for (int i = 0; i <= 5; i++) val[i][x] = (s[i][r[x]] - s[i][l[x] - 1]) * v;
    return;
  }
  down(x);
  if (ql <= (l[x] + r[x] >> 1)) upd((x << 1), ql, qr, v);
  if ((l[x] + r[x] >> 1) < qr) upd((x << 1 | 1), ql, qr, v);
  up(x);
}
modint<1000000007> qry(int x, int ql, int qr, int k) {
  if (ql <= l[x] && r[x] <= qr) return val[k][x];
  if (r[x] < ql || l[x] > qr) return 0;
  down(x);
  return qry((x << 1), ql, qr, k) + qry((x << 1 | 1), ql, qr, k);
}
signed main() {
  scanf("%d%d", &n, &m);
  pre();
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  while (m--) {
    char op = getchar();
    while (op != '?' && op != '=') op = getchar();
    if (op == '=') {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      upd(1, l, r, x);
    } else {
      int l, r, k;
      scanf("%d%d%d", &l, &r, &k);
      modint<1000000007> a = (1 - l), ans = 0, kk = 1;
      for (int i = 0; i <= k; i++)
        ans += c[k][i] * qry(1, l, r, k - i) * kk, kk *= a;
      printf("%d\n", ans);
    }
  }
}