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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DTheChildAndSequence solver = new DTheChildAndSequence();
        solver.solve(1, in, out);
        out.close();
    }

    static class DTheChildAndSequence {
        int MAXN = 200005;
        PrintWriter out;
        InputReader in;
        int n;
        int sqrt;
        long[] segtree;
        long[] arr = new long[MAXN];
        TreeSet<Tuple>[] tset = new TreeSet[MAXN];
        final Comparator<Tuple> com = new Comparator<Tuple>() {
            public int compare(Tuple t1, Tuple t2) {
                if (t1.x != t2.x)
                    return Long.compare(t1.x, t2.x);
                else
                    return Long.compare(t1.y, t2.y);
            }
        };

        long merge(long x, long y) {
            return x + y;
        }

        void build_segtree() {
            int i = 0;
            for (i = n - 1; i > 0; i--)
                segtree[i] = merge(segtree[i << 1], segtree[i << 1 | 1]);
        }

        void segtree_update(int ind, long val) {
            for (segtree[ind += n] = val; ind > 1; ind >>= 1)
                segtree[ind >> 1] = merge(segtree[ind], segtree[ind ^ 1]);
        }

        long query(int l, int r) {
            long res = 0;
            for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
                if ((l & 1) == 1)
                    res = merge(res, segtree[l++]);
                if ((r & 1) == 1)
                    res = merge(res, segtree[--r]);
            }
            return res;
        }

        void build_sqrt() {
            int i = 0, blk_ind = -1;
            for (i = 0; i < n; i++) {
                if (i % sqrt == 0)
                    blk_ind++;
                tset[blk_ind].add(new Tuple(arr[i], i));
            }
        }

        void sqrt_update(int l, int r, long X) {
            int ind = l / sqrt;
            while (l < r && l % sqrt != 0 && l != 0) {
                if (arr[l] >= X) {
                    tset[ind].remove(new Tuple(arr[l], l));
                    arr[l] %= X;
                    segtree_update(l, arr[l]);
                    tset[ind].add(new Tuple(arr[l], l));
                }
                l++;
            }
            while (l + sqrt <= r) {
                while (tset[l / sqrt].last().x >= X) {
                    Tuple curr = tset[l / sqrt].pollLast();
                    arr[(int) curr.y] %= X;
                    segtree_update((int) curr.y, arr[(int) curr.y]);
                    tset[l / sqrt].add(new Tuple(arr[(int) curr.y], curr.y));
                }
                l += sqrt;
            }
            ind = l / sqrt;
            while (l <= r) {
                if (arr[l] >= X) {
                    tset[ind].remove(new Tuple(arr[l], l));
                    arr[l] %= X;
                    segtree_update(l, arr[l]);
                    tset[ind].add(new Tuple(arr[l], l));
                }
                l++;
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            sqrt = (int) Math.sqrt(n);
            int m = ni();
            segtree = new long[2 * n];
            int i = 0;
            for (i = 0; i < n; i++) {
                tset[i] = new TreeSet<>(com);
                arr[i] = nl();
                segtree[n + i] = arr[i];
            }
            build_segtree();
            build_sqrt();
            while (m-- > 0) {
                int type = ni();
                if (type == 1) {
                    pn(query(ni() - 1, ni()));
                } else if (type == 2) {
                    sqrt_update(ni() - 1, ni() - 1, nl());
                } else {
                    int ind = ni() - 1;
                    long x = nl();
                    tset[ind / sqrt].remove(new Tuple(arr[ind], ind));
                    segtree_update(ind, x);
                    arr[ind] = x;
                    tset[ind / sqrt].add(new Tuple(arr[ind], ind));
                }
            }
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

        class Tuple {
            long x;
            long y;

            Tuple(long a, long b) {
                x = a;
                y = b;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}