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;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)((t).size()))); ++(i)) s << t[i] << " ";
  return s;
}
struct IntMin {
  int x;
  IntMin(int y = 1001001001) : x(y) {}
  inline IntMin operator+(const IntMin &s) const { return IntMin(min(x, s.x)); }
};
int currentX;
bool enough(IntMin a) { return a.x <= currentX; }
template <typename T, typename Aug>
struct AugTreap {
  struct Node {
    T v;
    int pr;
    Node *le, *ri;
    Aug al, ag;
  };
  Node *root;
  AugTreap() : root(0) {}
  inline static void recalc(Node *&n) {
    Aug left = n->le ? n->le->ag + n->al : n->al;
    n->ag = n->ri ? left + n->ri->ag : left;
  }
  inline void rotle(Node *&n) {
    Node *syn = n->le;
    n->le = syn->ri;
    syn->ri = n;
    n = syn;
    recalc(n->ri);
    recalc(n);
  }
  inline void rotri(Node *&n) {
    Node *syn = n->ri;
    n->ri = syn->le;
    syn->le = n;
    n = syn;
    recalc(n->le);
    recalc(n);
  }
  void insert_aux(Node *&n, const T &x, const Aug &aug) {
    if (!n) {
      n = new Node;
      n->v = x;
      n->pr = rand();
      n->le = n->ri = 0;
      n->al = n->ag = aug;
    } else if (x < n->v) {
      insert_aux(n->le, x, aug);
      if (n->pr > n->le->pr)
        rotle(n);
      else
        recalc(n);
    } else if (x > n->v) {
      insert_aux(n->ri, x, aug);
      if (n->pr > n->ri->pr)
        rotri(n);
      else
        recalc(n);
    } else {
      n->al = aug;
      recalc(n);
    }
  }
  void insert(const T &x, const Aug &aug) { insert_aux(root, x, aug); }
  bool remove(const T &x) { return remove_aux(root, x); }
  bool remove_aux(Node *&n, const T &x) {
    if (!n) return 0;
    if (x < n->v) {
      bool wyn = remove_aux(n->le, x);
      if (wyn) recalc(n);
      return wyn;
    }
    if (x > n->v) {
      bool wyn = remove_aux(n->ri, x);
      if (wyn) recalc(n);
      return wyn;
    }
    remove_node(n);
    return 1;
  }
  void remove_node(Node *&n) {
    if (!n->le) {
      Node *syn = n->ri;
      delete n;
      n = syn;
    } else if (!n->ri) {
      Node *syn = n->le;
      delete n;
      n = syn;
    } else if (n->le->pr < n->ri->pr) {
      rotle(n);
      remove_node(n->ri);
      recalc(n);
    } else {
      rotri(n);
      remove_node(n->le);
      recalc(n);
    }
  }
  Aug sumgeq_aux(const T &x, Node *n) {
    if (!n) return Aug();
    if (x > n->v) return sumgeq_aux(x, n->ri);
    if (x < n->v) {
      Aug left = sumgeq_aux(x, n->le) + n->al;
      return n->ri ? left + n->ri->ag : left;
    }
    return n->ri ? n->al + n->ri->ag : n->al;
  }
  Aug sumgeq(const T &x) { return sumgeq_aux(x, root); }
  Aug sumleq_aux(const T &x, Node *n) {
    if (!n) return Aug();
    if (x < n->v) return sumleq_aux(x, n->le);
    if (x > n->v) {
      Aug right = n->al + sumleq_aux(x, n->ri);
      return n->le ? n->le->ag + right : right;
    }
    return n->le ? n->le->ag + n->al : n->al;
  }
  Aug sumleq(const T &x) { return sumleq_aux(x, root); }
  Aug sumbetween_aux(const T &x, const T &y, Node *n) {
    if (!n) return Aug();
    if (y < n->v) return sumbetween_aux(x, y, n->le);
    if (x > n->v) return sumbetween_aux(x, y, n->ri);
    return sumgeq_aux(x, n->le) + n->al + sumleq_aux(y, n->ri);
  }
  Aug sumbetween(const T &x, const T &y) { return sumbetween_aux(x, y, root); }
  T minsubtreequery(Node *n, Aug sum) const {
    if (n->le) {
      Aug sum2 = sum + n->le->ag;
      if (enough(sum2)) {
        return minsubtreequery(n->le, sum);
      }
      sum = sum2;
    }
    sum = sum + n->al;
    if (enough(sum)) return n->v;
    return minsubtreequery(n->ri, sum);
  }
  mutable vector<Node *> roots;
  T minquery(const T &s) const {
    roots.clear();
    Node *n = root;
    while (n) {
      if (n->v < s) {
        n = n->ri;
      } else if (n->v > s) {
        roots.push_back(n);
        n = n->le;
      } else {
        roots.push_back(n);
        break;
      }
    }
    Aug sum;
    for (int(i) = (((int)((roots).size())) - 1); (i) >= (0); --i) {
      sum = sum + roots[i]->al;
      if (enough(sum)) {
        return roots[i]->v;
      }
      if (roots[i]->ri) {
        Aug sum2 = sum + roots[i]->ri->ag;
        if (enough(sum2)) {
          return minsubtreequery(roots[i]->ri, sum);
        }
        sum = sum2;
      }
    }
  }
};
vector<pair<int, int> > sets[200007];
vector<pair<int, pair<int, int> > > eventsAt[200007];
vector<pair<int, int> > addAt[200007], removeAt[200007];
int main() {
  int(n), (m);
  scanf("%d %d", &(n), &(m));
  for (int(i) = 1; (i) <= (n); ++(i)) {
    int(x);
    scanf("%d", &(x));
    sets[i].push_back(make_pair(i, x));
  }
  for (int(j) = 1; (j) <= (m); ++(j)) {
    int(ty);
    scanf("%d", &(ty));
    if (ty == 3) {
      int(k), (x);
      scanf("%d %d", &(k), &(x));
      sets[k].push_back(make_pair(n + j, x));
    } else if (ty == 1) {
      int(l), (r);
      scanf("%d %d", &(l), &(r));
      eventsAt[n + j].push_back(make_pair(0, make_pair(l, r)));
    } else {
      int(l), (r), (x);
      scanf("%d %d %d", &(l), &(r), &(x));
      addAt[l].push_back(make_pair(n + j, x));
      removeAt[r + 1].push_back(make_pair(n + j, x));
    }
  }
  AugTreap<int, IntMin> paski;
  paski.insert(1001001001, -1);
  for (int(i) = 1; (i) <= (n); ++(i)) {
    for (__typeof(addAt[i].begin()) it = addAt[i].begin(); it != addAt[i].end();
         it++)
      paski.insert(it->first, it->second);
    for (__typeof(removeAt[i].begin()) it = removeAt[i].begin();
         it != removeAt[i].end(); it++)
      paski.remove(it->first);
    for (__typeof(sets[i].begin()) it = sets[i].begin(); it != sets[i].end();
         it++) {
      int t = it->first, x = it->second;
      int next_t = next(it) == sets[i].end() ? 1001001001 : next(it)->first;
      eventsAt[t].push_back(make_pair(1, make_pair(i, x)));
      while (1) {
        currentX = x;
        t = paski.minquery(t);
        if (t >= next_t) break;
        x = x % paski.sumbetween(t, t).x;
        eventsAt[t].push_back(make_pair(1, make_pair(i, x)));
      }
    }
  }
  AugTreap<int, long long> sumator;
  for (int(t) = (1); (t) <= (n + m); ++t) {
    for (__typeof(eventsAt[t].begin()) it = eventsAt[t].begin();
         it != eventsAt[t].end(); it++) {
      if (it->first == 0) {
        printf("%lld\n",
               sumator.sumbetween(it->second.first, it->second.second));
      } else {
        sumator.insert(it->second.first, it->second.second);
      }
    }
  }
}