Problem: At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks.

Fortunately, Picks remembers how to repair the sequence. Initially he should create an integer array a[1], a[2], ..., a[n]. Then he should perform a sequence of m operations. An operation can be one of the following:

  1. Print operation l, r. Picks should write down the value of <image>. 
  2. Modulo operation l, r, x. Picks should perform assignment a[i] = a[i] mod x for each i (l ≤ i ≤ r). 
  3. Set operation k, x. Picks should set the value of a[k] to x (in other words perform an assignment a[k] = x). 



Can you help Picks to perform the whole sequence of operations?

Input

The first line of input contains two integer: n, m (1 ≤ n, m ≤ 105). The second line contains n integers, separated by space: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — initial value of array elements.

Each of the next m lines begins with a number type <image>. 

  * If type = 1, there will be two integers more in the line: l, r (1 ≤ l ≤ r ≤ n), which correspond the operation 1. 
  * If type = 2, there will be three integers more in the line: l, r, x (1 ≤ l ≤ r ≤ n; 1 ≤ x ≤ 109), which correspond the operation 2. 
  * If type = 3, there will be two integers more in the line: k, x (1 ≤ k ≤ n; 1 ≤ x ≤ 109), which correspond the operation 3. 

Output

For each operation 1, please print a line containing the answer. Notice that the answer may exceed the 32-bit integer.

Examples

Input

5 5
1 2 3 4 5
2 3 5 4
3 3 5
1 2 5
2 1 3 3
1 1 3


Output

8
5


Input

10 10
6 9 6 7 6 1 10 10 9 5
1 3 9
2 7 10 9
2 5 10 8
1 4 7
3 3 7
2 7 9 9
1 2 4
1 6 6
1 5 9
3 1 10


Output

49
15
23
1
9

Note

Consider the first testcase:

  * At first, a = {1, 2, 3, 4, 5}. 
  * After operation 1, a = {1, 2, 3, 0, 1}. 
  * After operation 2, a = {1, 2, 5, 0, 1}. 
  * At operation 3, 2 + 5 + 0 + 1 = 8. 
  * After operation 4, a = {1, 2, 2, 0, 1}. 
  * At operation 5, 1 + 2 + 2 = 5. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct node {
  long long mx, sm, idx;
  node() {
    mx = 0;
    sm = 0;
    idx = 0;
  }
};
struct segTree {
  long long n;
  vector<node> st;
  segTree(long long n) {
    this->n = n;
    st.resize(4 * n + 5);
  }
  void combine(long long pos, long long lc, long long rc) {
    st[pos].sm = st[lc].sm + st[rc].sm;
    if (st[lc].mx >= st[rc].mx)
      st[pos].mx = st[lc].mx, st[pos].idx = st[lc].idx;
    else
      st[pos].mx = st[rc].mx, st[pos].idx = st[rc].idx;
  }
  void _build(long long l, long long r, long long pos, long long *arr) {
    if (l == r) {
      st[pos].mx = arr[l];
      st[pos].sm = arr[l];
      st[pos].idx = l;
      return;
    }
    long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;
    _build(l, mid, lc, arr);
    _build(mid + 1, r, rc, arr);
    combine(pos, lc, rc);
  }
  void _upd(long long id, long long val, long long l, long long r,
            long long pos) {
    if (l == r) {
      st[pos].mx = val;
      st[pos].sm = val;
      st[pos].idx = l;
      return;
    }
    long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;
    if (id <= mid)
      _upd(id, val, l, mid, lc);
    else
      _upd(id, val, mid + 1, r, rc);
    combine(pos, lc, rc);
  }
  pair<long long, long long> _qrymax(long long ql, long long qr, long long l,
                                     long long r, long long pos) {
    if (qr < l || ql > r)
      return make_pair(-LONG_LONG_MAX, -1);
    else if (ql <= l && qr >= r)
      return make_pair(st[pos].mx, st[pos].idx);
    long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;
    pair<long long, long long> lef = _qrymax(ql, qr, l, mid, lc),
                               rig = _qrymax(ql, qr, mid + 1, r, rc);
    if (lef.first >= rig.first) return lef;
    return rig;
  }
  long long _qrysm(long long ql, long long qr, long long l, long long r,
                   long long pos) {
    if (qr < l || ql > r)
      return 0;
    else if (ql <= l && qr >= r)
      return st[pos].sm;
    long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;
    return _qrysm(ql, qr, l, mid, lc) + _qrysm(ql, qr, mid + 1, r, rc);
  }
  pair<long long, long long> qry_max(long long ql, long long qr) {
    return _qrymax(ql, qr, 1, n, 1);
  }
  void upd(long long idx, long long val) { _upd(idx, val, 1, n, 1); }
  long long qry_sum(long long ql, long long qr) {
    return _qrysm(ql, qr, 1, n, 1);
  }
  void build(long long *arr) { _build(1, n, 1, arr); }
};
const long long N = 1e5 + 5;
long long n, m, a[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  segTree S(n);
  S.build(a);
  while (m--) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long l, r;
      cin >> l >> r;
      cout << S.qry_sum(l, r) << "\n";
    } else if (type == 2) {
      long long l, r, x;
      cin >> l >> r >> x;
      pair<long long, long long> pp = S.qry_max(l, r);
      while (pp.first >= x) {
        long long newval = pp.first % x, idx = pp.second;
        S.upd(idx, newval);
        pp = S.qry_max(l, r);
      }
    } else {
      long long idx, val;
      cin >> idx >> val;
      S.upd(idx, val);
    }
  }
  return 0;
}