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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1;
int n, m;
int a[maxn];
int p, v;
int s, f;
long long koyta[20];
int run[20][maxn];
map<int, int> start[20];
map<int, int> finish[20];
long long cal() {
  long long ans = 0LL;
  long long p2 = 1;
  for (int i = 0; i < 20; i++) {
    ans += p2 * koyta[i];
    p2 <<= 1;
  }
  return ans;
}
long long F(long long x) { return x * (x + 1) / 2; }
int lsize, rsize, totsize;
int ls, lf;
int rs, rf;
int ts, tf;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    for (int j = 0; j < 20; j++)
      if ((a[i] >> j) & 1) run[j][i] = 1;
  }
  for (int j = 0; j < 20; j++) {
    for (int i = 0; i < n; i++) {
      if (run[j][i] == 1) {
        s = i;
        f = i;
        while (i + 1 < n && run[j][i + 1] == 1) i++, f = i;
        start[j][s] = f;
        finish[j][f] = s;
        koyta[j] += F(f - s + 1);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &p, &v);
    p--;
    for (int j = 0; j < 20; j++) {
      if ((v >> j) & 1) {
        if (run[j][p] == 1) continue;
        run[j][p] = 1;
        if (p - 1 >= 0 && p + 1 < n && run[j][p - 1] == 1 &&
            run[j][p + 1] == 1) {
          lsize = 0;
          rsize = 0;
          ls;
          lf = p - 1;
          ls = finish[j][lf];
          lsize = lf - ls + 1;
          start[j].erase(ls);
          finish[j].erase(lf);
          rs = p + 1;
          rf;
          rf = start[j][rs];
          rsize = rf - rs + 1;
          start[j].erase(rs);
          finish[j].erase(rf);
          start[j][ls] = rf;
          finish[j][rf] = ls;
          koyta[j] -= F(lsize);
          koyta[j] -= F(rsize);
          koyta[j] += F(lsize + rsize + 1);
        } else if (p - 1 >= 0 && run[j][p - 1] == 1 &&
                   (p + 1 >= n or (p + 1 < n && run[j][p + 1] == 0))) {
          lsize = 0;
          ls;
          lf = p - 1;
          ls = finish[j][lf];
          lsize = lf - ls + 1;
          start[j].erase(ls);
          finish[j].erase(lf);
          start[j][ls] = p;
          finish[j][p] = ls;
          koyta[j] -= F(lsize);
          koyta[j] += F(lsize + 1);
        } else if (p + 1 < n && run[j][p + 1] == 1 &&
                   (p - 1 < 0 or (p - 1 >= 0 && run[j][p - 1] == 0))) {
          rsize = 0;
          rs = p + 1;
          rf;
          rf = start[j][rs];
          rsize = rf - rs + 1;
          start[j].erase(rs);
          finish[j].erase(rf);
          start[j][p] = rf;
          finish[j][rf] = p;
          koyta[j] -= F(rsize);
          koyta[j] += F(rsize + 1);
        } else {
          start[j][p] = p;
          finish[j][p] = p;
          koyta[j] += F(1);
        }
      } else {
        if (run[j][p] == 0) continue;
        run[j][p] = 0;
        if (p - 1 >= 0 && p + 1 < n && run[j][p - 1] == 1 &&
            run[j][p + 1] == 1) {
          totsize = 0;
          lsize = 0;
          rsize = 0;
          auto itr = finish[j].lower_bound(p);
          rf = itr->first;
          ls = itr->second;
          totsize = rf - ls + 1;
          start[j].erase(ls);
          finish[j].erase(rf);
          lf = p - 1;
          lsize = lf - ls + 1;
          start[j][ls] = lf;
          finish[j][lf] = ls;
          rs = p + 1;
          rsize = rf - rs + 1;
          start[j][rs] = rf;
          finish[j][rf] = rs;
          koyta[j] -= F(totsize);
          koyta[j] += F(lsize);
          koyta[j] += F(rsize);
        } else if (p - 1 >= 0 && run[j][p - 1] == 1 &&
                   (p + 1 >= n or (p + 1 < n && run[j][p + 1] == 0))) {
          lsize = 0;
          ls;
          lf = p;
          ls = finish[j][lf];
          lsize = lf - ls + 1;
          start[j].erase(ls);
          finish[j].erase(lf);
          start[j][ls] = p - 1;
          finish[j][p - 1] = ls;
          koyta[j] -= F(lsize);
          koyta[j] += F(lsize - 1);
        } else if (p + 1 < n && run[j][p + 1] == 1 &&
                   (p - 1 < 0 or (p - 1 >= 0 && run[j][p - 1] == 0))) {
          rsize = 0;
          rs = p;
          rf;
          rf = start[j][rs];
          rsize = rf - rs + 1;
          start[j].erase(rs);
          finish[j].erase(rf);
          start[j][p + 1] = rf;
          finish[j][rf] = p + 1;
          koyta[j] -= F(rsize);
          koyta[j] += F(rsize - 1);
        } else {
          start[j].erase(p);
          finish[j].erase(p);
          koyta[j] -= F(1);
        }
      }
    }
    printf("%I64d\n", cal());
  }
  return 0;
}