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 s[100010][6];
long long sum[400010][6];
long long num[400010];
long long ans[6];
int n, m;
int x, k;
char ch[3];
int l, r;
long long calc(int l, int r, int k) {
  return ((s[r][k] - s[l - 1][k]) % 1000000007 + 1000000007) % 1000000007;
}
void pushup(int rt) {
  for (int i = 0; i <= 5; i++) {
    sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i];
  }
}
void pushdown(int rt, int l, int r) {
  if (num[rt] != -1) {
    int mid = (l + r) >> 1;
    num[rt << 1] = num[rt];
    num[rt << 1 | 1] = num[rt];
    for (int i = 0; i <= 5; i++) {
      sum[rt << 1][i] = num[rt] * calc(l, mid, i) % 1000000007;
      sum[rt << 1 | 1][i] = num[rt] * calc(mid + 1, r, i) % 1000000007;
    }
    num[rt] = -1;
  }
}
void build(int rt, int l, int r) {
  num[rt] = -1;
  if (l == r) {
    scanf("%d", &x);
    for (int i = 0; i <= 5; i++) {
      sum[rt][i] = 1ll * x * calc(l, l, i) % 1000000007;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
void change(int rt, int l, int r, int L, int R, int k) {
  if (L <= l && r <= R) {
    num[rt] = 1ll * k;
    for (int i = 0; i <= 5; i++) {
      sum[rt][i] = 1ll * k * calc(l, r, i) % 1000000007;
    }
    return;
  }
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) {
    change(rt << 1, l, mid, L, R, k);
  }
  if (R > mid) {
    change(rt << 1 | 1, mid + 1, r, L, R, k);
  }
  pushup(rt);
}
void query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    for (int i = 0; i <= 5; i++) {
      ans[i] += sum[rt][i];
      ans[i] %= 1000000007;
    }
    return;
  }
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) {
    query(rt << 1, l, mid, L, R);
  }
  if (R > mid) {
    query(rt << 1 | 1, mid + 1, r, L, R);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    s[i][0] = 1ll;
    for (int j = 1; j <= 5; j++) {
      s[i][j] = s[i][j - 1] * i % 1000000007;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 5; j++) {
      s[i][j] += s[i - 1][j];
      s[i][j] %= 1000000007;
    }
  }
  build(1, 1, n);
  while (m--) {
    scanf("%s%d%d%d", ch, &l, &r, &k);
    if (ch[0] == '=') {
      change(1, 1, n, l, r, k);
    } else {
      memset(ans, 0, sizeof(ans));
      query(1, 1, n, l, r);
      long long res = 0;
      if (k == 0) {
        res += ans[0], res %= 1000000007;
      } else if (k == 1) {
        res += ans[1], res %= 1000000007;
        res -= 1ll * (l - 1) * ans[0] % 1000000007, res %= 1000000007;
      } else if (k == 2) {
        res += ans[2], res %= 1000000007;
        res -= 2ll * (l - 1) * ans[1] % 1000000007, res %= 1000000007;
        res += 1ll * (l - 1) * (l - 1) % 1000000007 * ans[0] % 1000000007,
            res %= 1000000007;
      } else if (k == 3) {
        res += ans[3], res %= 1000000007;
        res -= 3ll * (l - 1) * ans[2] % 1000000007, res %= 1000000007;
        res += 3ll * (l - 1) * (l - 1) % 1000000007 * ans[1] % 1000000007,
            res %= 1000000007;
        res -= 1ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               ans[0] % 1000000007,
            res %= 1000000007;
      } else if (k == 4) {
        res += ans[4], res %= 1000000007;
        res -= 4ll * (l - 1) * ans[3] % 1000000007, res %= 1000000007;
        res += 6ll * (l - 1) * (l - 1) % 1000000007 * ans[2] % 1000000007,
            res %= 1000000007;
        res -= 4ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               ans[1] % 1000000007,
            res %= 1000000007;
        res += 1ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               (l - 1) % 1000000007 * ans[0] % 1000000007,
            res %= 1000000007;
      } else {
        res += ans[5], res %= 1000000007;
        res -= 5ll * (l - 1) * ans[4] % 1000000007, res %= 1000000007;
        res += 10ll * (l - 1) * (l - 1) % 1000000007 * ans[3] % 1000000007,
            res %= 1000000007;
        res -= 10ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               ans[2] % 1000000007,
            res %= 1000000007;
        res += 5ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               (l - 1) % 1000000007 * ans[1] % 1000000007,
            res %= 1000000007;
        res -= 1ll * (l - 1) * (l - 1) % 1000000007 * (l - 1) % 1000000007 *
               (l - 1) % 1000000007 * (l - 1) % 1000000007 * ans[0] %
               1000000007,
            res %= 1000000007;
      }
      res = (res % 1000000007 + 1000000007) % 1000000007;
      printf("%lld\n", res);
    }
  }
}