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 JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;

public class Main {
    static PrintWriter out;
    static Reader in;
    public static void main(String[] args) throws IOException {
        input_output();
        Main solver = new Main();
        solver.solve();
        out.close(); 
        out.flush(); 
    }

    static long INF = (long)1e18;
    static int MAXN = (int)2e7;
    static int mod = 998_244_353;
    static int n, m, q, t;
    static double pi = Math.PI;

    void solve() throws IOException{
    	n = in.nextInt();
    	m = in.nextInt();

    	int[] arr = new int[n+1];
    	FenwickTree bit = new FenwickTree(n);
    	for (int i = 1; i <= n; i++) {
    		arr[i] = in.nextInt();
    		bit.update(i, arr[i]);
    	}
    	SegTree st = new SegTree(1, n, arr);

    	int type, l, r, x;
    	for (int i = 0; i < m; i++) {
    		type = in.nextInt();

    		if (type == 1) {
    			l = in.nextInt();
    			r = in.nextInt();
    			out.println(bit.query(l, r));
    		} else if (type == 2) {
    			l = in.nextInt();
    			r = in.nextInt();
    			x = in.nextInt();

    			Node tmp = st.query(l, r);
    			while (tmp.val >= x) {
    				int nv = tmp.val%x;
    				st.pointUpdate(tmp.idx, nv);
    				bit.update(tmp.idx, nv-arr[tmp.idx]);
    				arr[tmp.idx] = nv;
    				tmp = st.query(l, r);
    			}
    		} else {
    			l = in.nextInt();
    			x = in.nextInt();
    			st.pointUpdate(l, x);
    			bit.update(l, x-arr[l]);
    			arr[l] = x;
    		}
    	}
   	}

    //<>

	static class FenwickTree {
	    long[] bit;

	    FenwickTree(int n) { bit = new long[n + 1]; }

	    long query(int l, int r) {
	        if(l > r)
	            return 0;
	        return query(r) - query(l - 1);
	    }

	    long query(int idx) {
	        long s = 0;
	        while(idx > 0) {
	            s += bit[idx];
	            idx ^= idx & -idx;
	        }
	        return s;
	    }

	    void update(int idx, long val) {
	        while(idx < bit.length) {
	            bit[idx] += val;
	            idx += idx & -idx;
	        }
	    }
	}


    static class SegTree {
        int leftmost, rightmost;
        SegTree lChild, rChild;
        Node val;

        public SegTree(int leftmost, int rightmost, int[] a) {
            this.leftmost=leftmost;
            this.rightmost=rightmost;
            if (leftmost!=rightmost) {
                int mid=(leftmost+rightmost)/2;
                lChild=new SegTree(leftmost, mid, a);
                rChild=new SegTree(mid+1, rightmost, a);
                recalc();
            } else init_leaf(a[leftmost]);
        }
        
        public void init_leaf(int value) {
        	val = new Node(value, leftmost);
        }

        public void recalc() {
        	if (lChild.val.val >= rChild.val.val) val = lChild.val;
        	else val = rChild.val;
        }
        
        public void pointUpdate(int position, int newValue) {
            if (leftmost==rightmost) {
                val.val = newValue;
                return;
            }
            if (position<=lChild.rightmost)
                lChild.pointUpdate(position, newValue);
            else
                rChild.pointUpdate(position, newValue);
            recalc();
        }

        public Node query(int l, int r) {
            if (l <= leftmost && rightmost <= r) return val;
            if (l > rightmost || r < leftmost) return new Node(-1, -1);

            Node left = lChild.query(l, r),
            	 right = rChild.query(l, r);
            if (left.val >= right.val) return left;
            else return right;
        }
    }

    static class Node {
    	int val, idx;

    	Node (int val, int idx) {
    		this.val = val;
    		this.idx = idx;
    	}
    }

    static class Reader {
 
        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
    
        public Reader() {
            this(System.in);
        }
    
        public Reader(InputStream is) {
            mIs = is;
        }
    
        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
    
        }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }
    
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
    
        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
    
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
    
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
    
        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
    
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    
        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
 
    }
    static void input_output() throws IOException {
        File f = new File("in.txt");
        if(f.exists() && !f.isDirectory()) { 
            in = new Reader(new FileInputStream("in.txt"));
        } else in = new Reader();
        f = new File("out.txt");
        if(f.exists() && !f.isDirectory()) {
            out = new PrintWriter(new File("out.txt"));
        } else out = new PrintWriter(System.out);
    }
}