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.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DTheChildAndSequence solver = new DTheChildAndSequence();
        solver.solve(1, in, out);
        out.close();
    }

    static class DTheChildAndSequence {
        int n;
        int m;
        int[] arr;

        public void readInput(Scanner sc) {
            n = sc.nextInt();
            m = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
        }

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            readInput(sc);
            int N = 1;
            while (N < n)
                N <<= 1;
            SegmentTree st = new SegmentTree(N);
            for (int i = 0; i < n; i++)
                st.update_point(i + 1, arr[i]);
            for (int i = n + 1; i <= N; i++)
                st.update_point(i, 0);
            for (int i = 0; i < m; i++) {
                int type = sc.nextInt();
                if (type == 1) {
                    pw.println(st.query(sc.nextInt(), sc.nextInt()));
                } else if (type == 2) {
                    int l = sc.nextInt(), r = sc.nextInt();
                    st.update_range(l, r, sc.nextInt());
                } else {
                    st.update_point(sc.nextInt(), sc.nextInt());
                }
            }
        }

        public class SegmentTree {
            int N;
            Node[] sTree;
            int[] lazy;

            SegmentTree(int N) {
                this.N = N;
                sTree = new Node[N << 1];        //no. of nodes = 2*N - 1, we add one to cross out index zero
                lazy = new int[N << 1];
                Arrays.fill(sTree, new Node(0, 0, 0));
                Arrays.fill(lazy, -1);
            }

            public Node merge(Node first, Node second) {
                long sum = first.sum + second.sum;
                int max = Math.max(first.max, second.max);
                int min = Math.min(first.min, second.min);
                return new Node(sum, max, min);
            }

            void update_point(int index, int val) {
                update_point(1, 1, N, index, index, val);
            }

            private void update_point(int node, int b, int e, int i, int j, int val) {
                if (i > e || b > j)
                    return;
                if (b >= i && e <= j) {
                    sTree[node] = new Node(val, val, val);
                    return;
                }
                int mid = b + e >> 1;
                propagate(node, b, mid, e);
                update_point(node << 1, b, mid, i, j, val);
                update_point(node << 1 | 1, mid + 1, e, i, j, val);
                sTree[node] = merge(sTree[node << 1], sTree[node << 1 | 1]);
            }

            void update_range(int i, int j, int val) {
                update_range(1, 1, N, i, j, val);
            }

            void update_range(int node, int b, int e, int i, int j, int val) {
                if (i > e || j < b || sTree[node].max < val)
                    return;
                if (b >= i && e <= j && sTree[node].max == sTree[node].min) {
                    int max = sTree[node].max % val;
                    sTree[node].sum = 1l * (e - b + 1) * max;
                    sTree[node].max = max;
                    sTree[node].min = max;
                    lazy[node] = val;
                } else {
                    int mid = b + e >> 1;
                    propagate(node, b, mid, e);
                    update_range(node << 1, b, mid, i, j, val);
                    update_range(node << 1 | 1, mid + 1, e, i, j, val);
                    sTree[node] = merge(sTree[node << 1], sTree[node << 1 | 1]);
                }
            }

            void propagate(int node, int b, int mid, int e) {
                if (lazy[node] != -1) {
                    lazy[node << 1] = lazy[node];
                    lazy[node << 1 | 1] = lazy[node];
                    sTree[node << 1].sum = 1l * (mid - b + 1) * sTree[node].max;
                    sTree[node << 1 | 1].sum = 1l * (e - mid) * sTree[node].max;
                    sTree[node << 1].max = sTree[node].max;
                    sTree[node << 1].min = sTree[node].max;
                    sTree[node << 1 | 1].max = sTree[node].max;
                    sTree[node << 1 | 1].min = sTree[node].max;
                }
                lazy[node] = -1;
            }

            long query(int i, int j) {
                return query(1, 1, N, i, j);
            }

            long query(int node, int b, int e, int i, int j) {
                if (i > e || j < b)
                    return 0;
                if (b >= i && e <= j)
                    return sTree[node].sum;
                int mid = b + e >> 1;
                propagate(node, b, mid, e);
                long q1 = query(node << 1, b, mid, i, j);
                long q2 = query(node << 1 | 1, mid + 1, e, i, j);
                return q1 + q2;

            }

            public class Node {
                long sum;
                int max;
                int min;

                public Node(long sum, int max, int min) {
                    this.sum = sum;
                    this.max = max;
                    this.min = min;
                }

                public String toString() {
                    return "Node{" +
                            "sum=" + sum +
                            ", max=" + max +
                            ", min=" + min +
                            '}';
                }

            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            try {
                while (st == null || !st.hasMoreTokens())
                    st = new StringTokenizer(br.readLine());
                return st.nextToken();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

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

    }
}