Problem: Inna is fed up with jokes about female logic. So she started using binary logic instead.

Inna has an array of n elements a1[1], a1[2], ..., a1[n]. Girl likes to train in her binary logic, so she does an exercise consisting of n stages: on the first stage Inna writes out all numbers from array a1, on the i-th (i ≥ 2) stage girl writes all elements of array ai, which consists of n - i + 1 integers; the k-th integer of array ai is defined as follows: ai[k] = ai - 1[k] AND ai - 1[k + 1]. Here AND is bit-wise binary logical operation.

Dima decided to check Inna's skill. He asks Inna to change array, perform the exercise and say the sum of all <image> elements she wrote out during the current exercise.

Help Inna to answer the questions!

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — size of array a1 and number of Dima's questions. Next line contains n integers a1[1], a1[2], ..., a1[n] (0 ≤ ai ≤ 105) — initial array elements.

Each of next m lines contains two integers — Dima's question description. Each question consists of two integers pi, vi (1 ≤ pi ≤ n; 0 ≤ vi ≤ 105). For this question Inna should make a1[pi] equals vi, and then perform the exercise. Please, note that changes are saved from question to question.

Output

For each question print Inna's answer on a single line.

Examples

Input

3 4
1 1 1
1 1
2 2
3 2
1 2


Output

6
4
7
12

Solution (in JAVA):

Solution:

import java.io.*;
import java.util.*;

public class E {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	int MAX = 17;
	
	TreeSet<Integer>[] sets = new TreeSet[MAX];
	long res = 0;

	long calc(long length, long rate) {
		return ((length * (length + 1)) * rate) / 2;
	}
	
	void remove(int idx, int bit) {
		int upper = sets[bit].ceiling(idx);
		int lower = sets[bit].floor(idx);
		
//		out.println("remove : " + lower + " " + upper);
		
		res -= calc(upper - lower - 1, 1 << bit);
		res += calc(upper - idx - 1, 1 << bit);
		res += calc(idx - lower - 1, 1 << bit);
		
		sets[bit].add(idx);
	}
	
	void add(int idx, int bit) {
		int upper = sets[bit].ceiling(idx + 1);
		int lower = sets[bit].floor(idx - 1);
		
//		out.println("add : " + lower + " " + upper);
		
		res += calc(upper - lower - 1, 1 << bit);
		res -= calc(upper - idx - 1, 1 << bit);
		res -= calc(idx - lower - 1, 1 << bit);
		
		sets[bit].remove(idx);
	}
	
	public void run() {
		int n = in.nextInt(), m = in.nextInt();
		int[] a = in.nextIntArray(n);
		
		for (int i = 0; i < MAX; i++) {
			sets[i] = new TreeSet<Integer>();
			sets[i].add(0);
			sets[i].add(n + 1);
		}
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < MAX; j++) {
				if ((a[i] & (1 << j)) == 0) {
					sets[j].add(i+1);
				}
			}
		}
		
		for (int j = 0; j < MAX; j++) {
			int prev = 0;
			while (prev <= n) {
				int next = sets[j].ceiling(prev + 1);
				res += calc(next - prev - 1, (1 << j));
				prev = next;
			}
		}

		for (int i = 0; i < m; i++) {
			int p = in.nextInt(), v = in.nextInt();
			
//			out.println("<< " + p + ", " + v + " >>");
			for (int j = 0; j < MAX; j++) {
				if ((a[p-1] & (1 << j)) != 0) 
					remove(p, j);
			}
			
			a[p-1] = v;
			for (int j = 0; j < MAX; j++) {
				if ((a[p-1] & (1 << j)) != 0) 
					add(p, j);
			}
			
			out.println(res);
		}
		
		
		out.close();
	}

	public static void main(String[] args) {
		new E().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

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

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

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

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

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

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		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();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}