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 <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
T POW(T B, T printf) {
  if (printf == 0) return 1;
  if (printf & 1)
    return B * POW(B, printf - 1);
  else
    return (POW(B, printf / 2) * POW(B, printf / 2));
}
template <typename T>
T Bigmod(T b, T p, T m) {
  if (p == 0)
    return 1;
  else if (!(p & 1))
    return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;
  else
    return ((b % m) * Bigmod(b, p - 1, m)) % m;
}
template <typename T>
T Dis(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));
}
template <typename T>
T Angle(T x1, T y1, T x2, T y2) {
  return atan(double(y1 - y2) / double(x1 - x2));
}
template <typename T>
T DIFF(T a, T b) {
  T d = a - b;
  if (d < 0)
    return -d;
  else
    return d;
}
template <typename T>
T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <typename T>
T euclide(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclide(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclide(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclide(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <typename T>
void ia(T a[], int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void pa(T a[], int n) {
  for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
template <typename T>
long long int isLeft(T a, T b, T c) {
  return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T, class first>
inline T togglebit(T a, first i) {
  T t = 1;
  return (a ^ (t << i));
}
double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }
double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }
long long int Tree[6][4 * 100007];
long long int Lazy[4 * 100007];
long long int pwSum[6][100007];
long long int nCr[6][6];
void Propagate(int idx, int l, int r, long long int x) {
  Lazy[idx] = x;
  for (int i = 0; i < 6; i++) {
    Tree[i][idx] = x * (pwSum[i][r] - pwSum[i][l - 1]);
    Tree[i][idx] %= 1000000007;
    if (Tree[i][idx] < 0) {
      Tree[i][idx] += 1000000007;
      Tree[i][idx] %= 1000000007;
    }
  }
}
void Update(int idx, int l, int r, int s, int e, int v) {
  if (l == s && r == e) {
    Propagate(idx, l, r, v);
    return;
  }
  if (Lazy[idx] != -1) {
    Propagate((idx << 1), l, ((l + r) >> 1), Lazy[idx]);
    Propagate(((idx << 1) | 1), ((l + r) >> 1) + 1, r, Lazy[idx]);
    Lazy[idx] = -1;
  }
  if (e <= ((l + r) >> 1))
    Update((idx << 1), l, ((l + r) >> 1), s, e, v);
  else if (s > ((l + r) >> 1))
    Update(((idx << 1) | 1), ((l + r) >> 1) + 1, r, s, e, v);
  else
    Update((idx << 1), l, ((l + r) >> 1), s, ((l + r) >> 1), v),
        Update(((idx << 1) | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, e,
               v);
  for (int i = 0; i < 6; i++) {
    Tree[i][idx] = Tree[i][(idx << 1)] + Tree[i][((idx << 1) | 1)];
    if (Tree[i][idx] > 1000000007) Tree[i][idx] -= 1000000007;
  }
}
long long int Query(int f, int idx, int l, int r, int s, int e) {
  if (l == s && r == e) return Tree[f][idx];
  if (Lazy[idx] != -1) {
    Propagate((idx << 1), l, ((l + r) >> 1), Lazy[idx]);
    Propagate(((idx << 1) | 1), ((l + r) >> 1) + 1, r, Lazy[idx]);
    Lazy[idx] = -1;
  }
  if (e <= ((l + r) >> 1))
    return Query(f, (idx << 1), l, ((l + r) >> 1), s, e);
  else if (s > ((l + r) >> 1))
    return Query(f, ((idx << 1) | 1), ((l + r) >> 1) + 1, r, s, e);
  else
    return (Query(f, (idx << 1), l, ((l + r) >> 1), s, ((l + r) >> 1)) +
            Query(f, ((idx << 1) | 1), ((l + r) >> 1) + 1, r,
                  ((l + r) >> 1) + 1, e)) %
           1000000007;
}
void Init(int n) {
  for (int i = 0; i < 6; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == 0)
        pwSum[i][j] = 1;
      else
        pwSum[i][j] = (pwSum[i - 1][j] * j) % 1000000007;
    }
  }
  for (int i = 0; i < 6; i++)
    for (int j = 1; j <= n; j++)
      pwSum[i][j] = (pwSum[i][j - 1] + pwSum[i][j]) % 1000000007;
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 6; j++) {
      if (j == 0 || i == j)
        nCr[i][j] = 1;
      else
        nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % 1000000007;
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  Init(n);
  for (int i = 1; i <= n; i++) {
    int(x);
    scanf("%d", &x);
    Update(1, 1, n, i, i, x);
  }
  char s[10];
  while (m--) {
    scanf("%s", s);
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    if (s[0] == '=')
      Update(1, 1, n, l, r, x);
    else {
      long long int ans = 0;
      long long int pw = 1;
      for (int i = 0; i <= x; i++) {
        long long int y = Query(x - i, 1, 1, n, l, r);
        y *= pw;
        y %= 1000000007;
        y *= nCr[x][i];
        y %= 1000000007;
        ans += y;
        ans %= 1000000007;
        pw *= (1 - l);
        pw %= 1000000007;
        pw += 1000000007;
        pw %= 1000000007;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}