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.*;
import java.math.BigInteger;
import java.util.*;

public class Main {


    long MODULO = 998244353;
    void solve() throws IOException {
        int n = readInt();
        int m = readInt();
        long[] arr = new long[n];
        for (int i=0; i<n; ++i) arr[i] = readInt();
        SegmentTree sgt = new SegmentTree(arr);

        while(m-- > 0){
            int type = readInt();
            if (type == 1){
                int l = readInt();
                int r = readInt();
                out.println(sgt.getSum(1, 1, n, l, r));
            }
            if (type == 2){
                int l = readInt();
                int r = readInt();
                int x = readInt();
                sgt.updateModulo(1, 1, n, l, r, x);
            }
            if (type == 3) {
                int pos = readInt();
                int k = readInt();
                sgt.updateValue(1, 1, n, pos, k);
            }
        }

        for (int i=01; i<=n; ++i){
            //out.println(sgt.getSum(1, 1, n, i, i));
        }
    }

    long gcd(long a, long b){
        return a % b == 0 ? b : gcd(b, a % b);
    }

    class SegmentTree {
        long[] sumT;
        long[] maxT;
        int n;
        SegmentTree(long[] arr){
            this.n = arr.length;
            this.sumT = new long[n * 4];
            this.maxT = new long[n * 4];
            build(1, 1, n, arr);
        }
        int getLeft(int v){
            return 2 * v;
        }
        int getRight(int v){
            return 2 * v + 1;
        }
        void build(int v, int l, int r, long[] arr){
            if (l == r){
                sumT[v] = arr[l - 1];
                maxT[v] = arr[l - 1];
                return;
            }
            int left = getLeft(v);
            int right = getRight(v);
            int mid = (l + r) / 2;
            build(left, l, mid, arr);
            build(right, mid + 1, r, arr);
            maxT[v] = Math.max(maxT[left], maxT[right]);
            sumT[v] = sumT[left] + sumT[right];
        }

        long getSum(int v, int tl, int tr, int l, int r){
            if (l > r) return 0;
            if (tl == l && tr == r) {
                return sumT[v];
            }
            int mid = (tr + tl) / 2;
            int left = getLeft(v);
            int right = getRight(v);
            return getSum(left, tl, mid, l, Math.min(r ,mid)) + getSum(right, mid + 1, tr, Math.max(l, mid + 1), r);
        }

        void updateModulo(int v, int tl, int tr, int l, int r, long m){
            if (tl >  r || tr < l || maxT[v] < m ) return;
            if (tl == tr){
                maxT[v] %= m;
                sumT[v] %= m;
                return;
            }
            int mid = (tr + tl) / 2;
            int left = getLeft(v);
            int right = getRight(v);
            updateModulo(left, tl, mid, l, Math.min(mid, r), m);
            updateModulo(right, mid + 1, tr, Math.max(l, mid + 1), r, m);
            maxT[v] = Math.max(maxT[left], maxT[right]);
            sumT[v] = sumT[left] + sumT[right];
        }

        void updateValue(int v, int tl, int tr, int pos, int value){
            if (tl == tr){
                maxT[v] = value;
                sumT[v] = value;
                return;
            }
            int mid = (tr + tl) / 2;
            int left = getLeft(v);
            int right = getRight(v);

            if (pos <= mid) updateValue(left, tl, mid, pos, value);
            else updateValue(right, mid + 1, tr, pos, value);
            maxT[v] = Math.max(maxT[left], maxT[right]);
            sumT[v] = sumT[left] + sumT[right];
        }
    }
    int[][] steps = {{1, 0}, {0, 1}};
    String fileName = "";
    private final static Random rnd = new Random();

    long binPow(long a, long b, long m) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return ((a % m) * (binPow(a, b - 1, m) % m)) % m;
        } else {
            long c = binPow(a, b / 2, m);
            return (c * c) % m;
        }

    }
    boolean checkBit(long mask, int bit) {
        return (mask & (1l << bit)) > 0;
    }

    ////////////////////////////////////////////////////////////
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        new Main().run();
    }

    void run() throws NumberFormatException, IOException {
        solve();
        out.close();
    }

    ;

    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok;
    String delim = " ";

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }

        }
        tok = new StringTokenizer("");
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) {
                return null;
            }

            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken(delim);
    }

    int readInt() throws NumberFormatException, IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws NumberFormatException, IOException {
        return Long.parseLong(readString());
    }

    int[] readIntArray(int n) throws NumberFormatException, IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = readInt();
        }
        return a;
    }

    double readDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(readString());
    }
}