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;
int n, m;
int conf[6][100111];
struct seg {
  int length;
  vector<vector<int> > arr;
  vector<bool> arrt;
  seg(int height) {
    length = 1 << height;
    arr.resize(length * 2, vector<int>(6));
    arrt.resize(length * 2, false);
  }
  void range_as(int l, int r, int loc, int len, int &val) {
    if (loc * len >= l && (loc + 1) * len <= r) {
      arr[loc][0] = val;
      arrt[loc] = true;
    } else if (loc * len < r && (loc + 1) * len > l) {
      if (arrt[loc]) {
        arrt[loc] = false;
        int val2 = arr[loc][0];
        if (loc * len < l) {
          range_as(loc * len, l, loc, len, val2);
        }
        if ((loc + 1) * len > r) {
          range_as(r, (loc + 1) * len, loc, len, val2);
        }
      }
      range_as(l, r, loc * 2, len / 2, val);
      range_as(l, r, loc * 2 + 1, len / 2, val);
      for (int i = 0; i < 6; ++i) {
        if (arrt[loc * 2]) {
          arr[loc][i] =
              ((long long)(conf[i][(loc * 2 + 1) * (len / 2) - length] -
                           conf[i][loc * len - length]) *
               arr[loc * 2][0]) %
              1000000007;
        } else {
          arr[loc][i] = arr[loc * 2][i];
        }
        if (arrt[loc * 2 + 1]) {
          arr[loc][i] =
              ((long long)(conf[i][(loc + 1) * len - length] -
                           conf[i][(loc * 2 + 1) * (len / 2) - length]) *
                   arr[loc * 2 + 1][0] +
               arr[loc][i]) %
              1000000007;
        } else {
          arr[loc][i] = (arr[loc][i] + arr[loc * 2 + 1][i]) % 1000000007;
        }
      }
    }
  }
  void range_assign(int l, int r, int val) {
    range_as(l + length, r + length, 1, length, val);
  }
  void range_sum(int l, int r, int loc, int len, int &ra, int &res) {
    if (arrt[loc]) {
      if (min(r, (loc + 1) * len) > max(l, loc * len)) {
        res = ((long long)(conf[ra][min(r, (loc + 1) * len) - length] -
                           conf[ra][max(l, loc * len) - length]) *
                   arr[loc][0] +
               res) %
              1000000007;
      }
    } else {
      if (loc * len >= l && (loc + 1) * len <= r) {
        res = (res + arr[loc][ra]) % 1000000007;
      } else if (loc * len < r && (loc + 1) * len > l) {
        range_sum(l, r, loc * 2, len / 2, ra, res);
        range_sum(l, r, loc * 2 + 1, len / 2, ra, res);
      }
    }
  }
  int querry(int l, int r, int ra) {
    int res = 0;
    range_sum(l + length, r + length, 1, length, ra, res);
    return (res + 1000000007) % 1000000007;
  }
};
int combs[11][11];
int main() {
  combs[0][0] = 1;
  for (int i = 1; i < 9; ++i) {
    combs[i][0] = 1;
    for (int j = 1; j < 9; ++j) {
      combs[i][j] = combs[i - 1][j] + combs[i - 1][j - 1];
    }
  }
  for (int i = 0; i < 9; ++i) {
    for (int j = 0; j < 9; ++j) {
      if (j % 2) {
        combs[i][j] = -combs[i][j];
      }
    }
  }
  scanf("%d %d", &n, &m);
  for (int j = 0; j <= n; ++j) {
    conf[0][j] = j;
  }
  for (int i = 1; i < 6; ++i) {
    for (int j = 1; j <= n; ++j) {
      conf[i][j] = ((long long)(conf[i - 1][j] - conf[i - 1][j - 1]) * j +
                    conf[i][j - 1]) %
                   1000000007;
    }
  }
  seg tree(17);
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    tree.range_assign(i, i + 1, a);
  }
  for (int i = 0; i < m; ++i) {
    char type;
    int l, r, x;
    scanf(" %c %d %d %d", &type, &l, &r, &x);
    if (type == '=') {
      tree.range_assign(l - 1, r, x);
    } else {
      int res = 0;
      int pos = 1;
      for (int i = 0; i <= x; ++i) {
        res = ((long long)pos * combs[x][i] % 1000000007 *
                   tree.querry(l - 1, r, x - i) +
               res) %
              1000000007;
        pos = ((long long)pos * (l - 1)) % 1000000007;
      }
      res = (res + 1000000007) % 1000000007;
      printf("%d\n", res);
    }
  }
  return 0;
}