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;
const int MAXN = 100001;
const int MAXNODE = MAXN << 2;
const int MOD = 1000000007;
int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
int mul(int a, int b) {
  return !b || a < MOD / b ? a * b : (long long)a * b % MOD;
}
int C[6][6], matrix[6][6], accsum[6][MAXN];
void init() {
  for (int i = 0; i < 6; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) {
      C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
    }
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k <= j; k++) {
        matrix[i][i - 1 - k] = add(matrix[i][i - 1 - k], C[j][k]);
      }
    }
  }
  for (int j = 1; j < MAXN; j++) {
    accsum[0][j] = 1;
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < MAXN; j++) {
      accsum[i][j] = mul(accsum[i - 1][j], j);
    }
  }
  for (int i = 0; i < 6; i++) {
    for (int j = 1; j < MAXN; j++) {
      accsum[i][j] = add(accsum[i][j], accsum[i][j - 1]);
    }
  }
}
class Segment {
 public:
  int size, value, sum[6];
  bool tag;
  Segment() {
    size = value = 0;
    tag = false;
    for (int i = 0; i < 6; i++) {
      sum[i] = 0;
    }
  }
  Segment(int size, int value, bool tag) : size(size), value(value), tag(tag) {
    for (int i = 0; i < 6; i++) {
      sum[i] = tag ? mul(value, accsum[i][size]) : 0;
    }
  }
  Segment operator+(const Segment &rhs) const {
    Segment res = Segment(size + rhs.size, 0, false);
    for (int i = 0; i < 6; i++) {
      res.sum[i] = add(sum[i], rhs.sum[i]);
      int l = 1;
      for (int j = i - 1; j >= 0; j--) {
        l = mul(l, size);
        res.sum[i] = add(res.sum[i], mul(rhs.sum[j], mul(matrix[i][j], l)));
      }
    }
    return res;
  }
};
int a[MAXN];
class SegTree {
 public:
  int n;
  Segment seg[MAXNODE];
  static int LEFT(int idx) { return idx << 1; }
  static int RIGHT(int idx) { return (idx << 1) | 1; }
  void _build(int idx, int lower, int upper) {
    if (lower == upper) {
      seg[idx] = Segment(1, a[lower], true);
      return;
    }
    int middle = (lower + upper) >> 1;
    _build(LEFT(idx), lower, middle);
    _build(RIGHT(idx), middle + 1, upper);
    seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];
  }
  void init(int n) {
    this->n = n;
    _build(1, 0, n - 1);
  }
  void pushDown(int idx) {
    if (seg[idx].tag) {
      seg[LEFT(idx)] = Segment(seg[LEFT(idx)].size, seg[idx].value, true);
      seg[RIGHT(idx)] = Segment(seg[RIGHT(idx)].size, seg[idx].value, true);
      seg[idx].tag = false;
    }
  }
  int l, r, v;
  void _modify(int idx, int lower, int upper) {
    if (r < lower || upper < l) {
      return;
    }
    if (l <= lower && upper <= r) {
      seg[idx] = Segment(upper - lower + 1, v, true);
      return;
    }
    pushDown(idx);
    int middle = (lower + upper) >> 1;
    _modify(LEFT(idx), lower, middle);
    _modify(RIGHT(idx), middle + 1, upper);
    seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];
  }
  void modify(int l, int r, int value) {
    this->l = l;
    this->r = r;
    this->v = value;
    _modify(1, 0, n - 1);
  }
  Segment _calc(int idx, int lower, int upper) {
    if (r < lower || upper < l) {
      return Segment();
    }
    if (l <= lower && upper <= r) {
      return seg[idx];
    }
    pushDown(idx);
    int middle = (lower + upper) >> 1;
    return _calc(LEFT(idx), lower, middle) +
           _calc(RIGHT(idx), middle + 1, upper);
  }
  Segment calc(int l, int r) {
    this->l = l;
    this->r = r;
    return _calc(1, 0, n - 1);
  }
};
int n, m;
SegTree st;
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  st.init(n);
  for (int i = 0; i < m; i++) {
    char op[4];
    int l, r, x;
    scanf("%s%d%d%d", op, &l, &r, &x);
    if (op[0] == '?') {
      Segment sg = st.calc(l - 1, r - 1);
      printf("%d\n", sg.sum[x]);
    } else {
      st.modify(l - 1, r - 1, x);
    }
  }
  return 0;
}