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.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D438 {
    public static void main(String[] args) {
        input();
        solve();
    }

    static void solve() {
        StringBuilder res = new StringBuilder();
        SegmentTree s = new SegmentTree(a);
        //System.out.println(s.getSum(1, 3));
        for (int i = 0; i < m; i++) {
            int type = nextInt();
            if (type == 1) {
                int l = nextInt();
                int r = nextInt();
                res.append(s.getSum(l - 1, r - 1) + "\n");
            }
            if (type == 2) {
                int l = nextInt();
                int r = nextInt();
                int x = nextInt();
                s.mod(l - 1, r - 1, x);
            }
            if (type == 3) {
                int k = nextInt();
                int x = nextInt();
                s.update(k - 1, x);
            }
        }
        System.out.print(res);
    }

    /************************************************************************************/
    static int n;
    static int m;
    static int[] a;

    static void input() {
        n = nextInt();
        m = nextInt();
        a = nextAi(n);
    }

    /************************************************************************************/
    static InputStream is = System.in;
    static private byte[] buffer = new byte[1024];
    static private int lenbuf = 0, ptrbuf = 0;

    static private int readByte() {
        if (lenbuf == -1)
            throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(buffer);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0)
                return -1;
        }
        return buffer[ptrbuf++];
    }

    static private boolean isSpace(int c) {
        return !(c >= 33 && c <= 126);
    }

    static private int read() {
        int b;
        while ((b = readByte()) != -1 && isSpace(b))
            ;
        return b;
    }

    static private double nextDouble() {
        return Double.parseDouble(nextString());
    }

    static private char nextChar() {
        return (char) read();
    }

    static private String nextString() {
        int b = read();
        StringBuilder sb = new StringBuilder();
        while (!(isSpace(b))) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    static private char[] nextString(int n) {
        char[] buf = new char[n];
        int b = read(), p = 0;
        while (p < n && !(isSpace(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    static private int nextInt() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
            ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    static private long nextLong() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
            ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    static private int[] nextAi(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    static private Integer[] nextAi1(int n) {
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

}

class SegmentTree {
    private static int[] data;
    private static long[] sum;
    private static int[] max;
    static int n;

    static private int left(int root) {
        return (root << 1);
    }

    static private int right(int root) {
        return (root << 1) + 1;
    }

    public SegmentTree(int[] data) {
        this.data = data;
        n = data.length;
        sum = new long[4 * n + 10];
        max = new int[4 * n + 10];
        buildTree(1, 0, n - 1);
    }

    private void buildTree(int root, int rl, int rr) {
        if (rl == rr) {
            sum[root] = max[root] = data[rl];
        } else {
            int rm = (rl + rr) >> 1;
            buildTree(left(root), rl, rm);
            buildTree(right(root), rm + 1, rr);
            sum[root] = sum[left(root)] + sum[right(root)];
            max[root] = Math.max(max[left(root)], max[right(root)]);
        }
    }

    public long getSum(int l, int r) {
        return getSum(1, 0, n - 1, l, r);
    }

    private long getSum(int root, int rl, int rr, int l, int r) {
        if (l > r) {
            return 0;
        }
        if (rl == l && rr == r) {
            return sum[root];
        }
        int rm = (rl + rr) >> 1;
        long r1 = getSum(left(root), rl, rm, l, Math.min(rm, r));
        long r2 = getSum(right(root), rm + 1, rr, Math.max(l, rm + 1), r);
        return r1 + r2;
    }

    public void mod(int l, int r, int x) {
        mod(1, 0, n - 1, l, r, x);
    }

    private void mod(int root, int rl, int rr, int l, int r, int x) {
        if (l > r) {
            return;
        }
        if (max[root] < x)
            return;
        if (rl == rr) {
            data[rl] %= x;
            sum[root] = max[root] = data[rl];
            return;
        }
        int rm = (rl + rr) >> 1;
        mod(left(root), rl, rm, l, Math.min(rm, r), x);
        mod(right(root), rm + 1, rr, Math.max(l, rm + 1), r, x);
        max[root] = Math.max(max[left(root)], max[right(root)]);
        sum[root] = sum[left(root)] + sum[right(root)];
    }

    public void update(int k, int x) {
        update(1, 0, n - 1, k, x);
    }

    private void update(int root, int rl, int rr, int k, int x) {
        if (rl == rr) {
            data[rl] = x;
            sum[root] = max[root] = data[rl];
            return;
        }
        int rm = (rl + rr) >> 1;
        if (k <= rm)
            update(left(root), rl, rm, k, x);
        else
            update(right(root), rm + 1, rr, k, x);
        max[root] = Math.max(max[left(root)], max[right(root)]);
        sum[root] = sum[left(root)] + sum[right(root)];
    }
}