#include <bits/stdc++.h>
using namespace std;
long long f[200010], sf[200010], a[200010];
void init() {
  f[0] = sf[0] = 0;
  f[1] = sf[1] = 1;
  for (int i = 2; i < 200010; i++) {
    f[i] = (f[i - 1] + f[i - 2]) % 1000000000;
    sf[i] = (sf[i - 1] + f[i]) % 1000000000;
  }
}
struct tree {
  int l;
  int r;
  long long s1, s2;
  long long lazy;
  int size() { return r - l + 1; }
} nde[4 * 200010 + 1];
void pushup(int n) {
  int len = nde[n << 1].size();
  long long a = f[len], b = f[len + 1], c = f[len + 2];
  nde[n].s1 = (nde[n << 1].s1 + a * nde[n << 1 | 1].s2 % 1000000000 +
               (b - a) * nde[n << 1 | 1].s1 % 1000000000) %
              1000000000;
  nde[n].s2 = (nde[n << 1].s2 + b * nde[n << 1 | 1].s2 % 1000000000 +
               (c - b) * nde[n << 1 | 1].s1 % 1000000000) %
              1000000000;
}
void pushdown(int n) {
  long long lazy = nde[n].lazy;
  if (lazy) {
    int len = nde[n << 1].size();
    nde[n << 1].s1 =
        (nde[n << 1].s1 + sf[len - 1] * lazy % 1000000000) % 1000000000;
    nde[n << 1].s2 =
        (nde[n << 1].s2 + sf[len] * lazy % 1000000000) % 1000000000;
    nde[n << 1].lazy = (nde[n << 1].lazy + lazy) % 1000000000;
    len = nde[n << 1 | 1].size();
    nde[n << 1 | 1].s1 =
        (nde[n << 1 | 1].s1 + sf[len - 1] * lazy % 1000000000) % 1000000000;
    nde[n << 1 | 1].s2 =
        (nde[n << 1 | 1].s2 + sf[len] * lazy % 1000000000) % 1000000000;
    nde[n << 1 | 1].lazy = (nde[n << 1 | 1].lazy + lazy) % 1000000000;
    nde[n].lazy = 0;
  }
}
void update(int pos, long long val, int n) {
  if (nde[n].l >= nde[n].r) {
    nde[n].s1 = 0;
    nde[n].s2 = val;
    nde[n].lazy = 0;
    return;
  }
  pushdown(n);
  if (pos <= nde[n << 1].r)
    update(pos, val, n << 1);
  else
    update(pos, val, n << 1 | 1);
  pushup(n);
}
void add(int l, int r, long long val, int n) {
  if (l <= nde[n].l && r >= nde[n].r) {
    int len = nde[n].size();
    nde[n].s1 = (nde[n].s1 + val * sf[len - 1] % 1000000000) % 1000000000;
    nde[n].s2 = (nde[n].s2 + val * sf[len] % 1000000000) % 1000000000;
    nde[n].lazy = (nde[n].lazy + val % 1000000000) % 1000000000;
    return;
  }
  pushdown(n);
  if (r <= nde[n << 1].r)
    add(l, r, val, n << 1);
  else if (l > nde[n << 1].r)
    add(l, r, val, n << 1 | 1);
  else {
    add(l, nde[n << 1].r, val, n << 1);
    add(nde[n << 1 | 1].l, r, val, n << 1 | 1);
  }
  pushup(n);
}
tree query(int l, int r, int n) {
  if (l <= nde[n].l && r >= nde[n].r) {
    return nde[n];
  }
  pushdown(n);
  if (r <= nde[n << 1].r) {
    return query(l, r, n << 1);
  } else if (l > nde[n << 1].r) {
    return query(l, r, n << 1 | 1);
  } else {
    tree la, ra, tmp;
    la = query(l, nde[n << 1].r, n << 1);
    ra = query(nde[n << 1 | 1].l, r, n << 1 | 1);
    int len = la.size();
    long long a = f[len], b = f[len + 1], c = f[len + 2];
    tmp.l = la.l;
    tmp.r = ra.r;
    tmp.s1 = (la.s1 + a * ra.s2 % 1000000000 + (b - a) * ra.s1 % 1000000000) %
             1000000000;
    tmp.s2 = (la.s2 + b * ra.s2 % 1000000000 + (c - b) * ra.s1 % 1000000000) %
             1000000000;
    return tmp;
  }
}
void build(int l, int r, int n) {
  nde[n].l = l;
  nde[n].r = r;
  if (l >= r) {
    nde[n].lazy = 0;
    nde[n].s1 = 0;
    nde[n].s2 = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, n << 1);
  build(mid + 1, r, n << 1 | 1);
  pushup(n);
}
int main() {
  init();
  int n, m, t, x, l, r;
  long long y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  build(1, n, 1);
  while (m--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%I64d", &x, &y);
      update(x, y, 1);
    } else if (t == 2) {
      scanf("%d%d", &l, &r);
      tree ans = query(l, r, 1);
      printf("%I64d\n", (ans.s2 % 1000000000 + 1000000000) % 1000000000);
    } else {
      scanf("%d%d%I64d", &l, &r, &y);
      add(l, r, y, 1);
    }
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:

You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:

  1. For given numbers xi and vi assign value vi to element axi. 
  2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 
  3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). 



Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: 

  * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); 
  * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); 
  * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). 



The input limits for scoring 30 points are (subproblem E1): 

  * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. 



The input limits for scoring 70 points are (subproblems E1+E2): 

  * It is guaranteed that there will be queries of the 1-st and 2-nd type only. 



The input limits for scoring 100 points are (subproblems E1+E2+E3): 

  * No extra limitations. 

Output

For each query print the calculated sum modulo 1000000000 (109).

Examples

Input

5 5
1 3 1 2 4
2 1 4
2 1 5
2 2 4
1 3 10
2 1 5


Output

12
32
8
50


Input

5 4
1 3 1 2 4
3 1 4 1
2 2 4
1 2 10
2 1 5


Output

12
45

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long f[200010], sf[200010], a[200010];
void init() {
  f[0] = sf[0] = 0;
  f[1] = sf[1] = 1;
  for (int i = 2; i < 200010; i++) {
    f[i] = (f[i - 1] + f[i - 2]) % 1000000000;
    sf[i] = (sf[i - 1] + f[i]) % 1000000000;
  }
}
struct tree {
  int l;
  int r;
  long long s1, s2;
  long long lazy;
  int size() { return r - l + 1; }
} nde[4 * 200010 + 1];
void pushup(int n) {
  int len = nde[n << 1].size();
  long long a = f[len], b = f[len + 1], c = f[len + 2];
  nde[n].s1 = (nde[n << 1].s1 + a * nde[n << 1 | 1].s2 % 1000000000 +
               (b - a) * nde[n << 1 | 1].s1 % 1000000000) %
              1000000000;
  nde[n].s2 = (nde[n << 1].s2 + b * nde[n << 1 | 1].s2 % 1000000000 +
               (c - b) * nde[n << 1 | 1].s1 % 1000000000) %
              1000000000;
}
void pushdown(int n) {
  long long lazy = nde[n].lazy;
  if (lazy) {
    int len = nde[n << 1].size();
    nde[n << 1].s1 =
        (nde[n << 1].s1 + sf[len - 1] * lazy % 1000000000) % 1000000000;
    nde[n << 1].s2 =
        (nde[n << 1].s2 + sf[len] * lazy % 1000000000) % 1000000000;
    nde[n << 1].lazy = (nde[n << 1].lazy + lazy) % 1000000000;
    len = nde[n << 1 | 1].size();
    nde[n << 1 | 1].s1 =
        (nde[n << 1 | 1].s1 + sf[len - 1] * lazy % 1000000000) % 1000000000;
    nde[n << 1 | 1].s2 =
        (nde[n << 1 | 1].s2 + sf[len] * lazy % 1000000000) % 1000000000;
    nde[n << 1 | 1].lazy = (nde[n << 1 | 1].lazy + lazy) % 1000000000;
    nde[n].lazy = 0;
  }
}
void update(int pos, long long val, int n) {
  if (nde[n].l >= nde[n].r) {
    nde[n].s1 = 0;
    nde[n].s2 = val;
    nde[n].lazy = 0;
    return;
  }
  pushdown(n);
  if (pos <= nde[n << 1].r)
    update(pos, val, n << 1);
  else
    update(pos, val, n << 1 | 1);
  pushup(n);
}
void add(int l, int r, long long val, int n) {
  if (l <= nde[n].l && r >= nde[n].r) {
    int len = nde[n].size();
    nde[n].s1 = (nde[n].s1 + val * sf[len - 1] % 1000000000) % 1000000000;
    nde[n].s2 = (nde[n].s2 + val * sf[len] % 1000000000) % 1000000000;
    nde[n].lazy = (nde[n].lazy + val % 1000000000) % 1000000000;
    return;
  }
  pushdown(n);
  if (r <= nde[n << 1].r)
    add(l, r, val, n << 1);
  else if (l > nde[n << 1].r)
    add(l, r, val, n << 1 | 1);
  else {
    add(l, nde[n << 1].r, val, n << 1);
    add(nde[n << 1 | 1].l, r, val, n << 1 | 1);
  }
  pushup(n);
}
tree query(int l, int r, int n) {
  if (l <= nde[n].l && r >= nde[n].r) {
    return nde[n];
  }
  pushdown(n);
  if (r <= nde[n << 1].r) {
    return query(l, r, n << 1);
  } else if (l > nde[n << 1].r) {
    return query(l, r, n << 1 | 1);
  } else {
    tree la, ra, tmp;
    la = query(l, nde[n << 1].r, n << 1);
    ra = query(nde[n << 1 | 1].l, r, n << 1 | 1);
    int len = la.size();
    long long a = f[len], b = f[len + 1], c = f[len + 2];
    tmp.l = la.l;
    tmp.r = ra.r;
    tmp.s1 = (la.s1 + a * ra.s2 % 1000000000 + (b - a) * ra.s1 % 1000000000) %
             1000000000;
    tmp.s2 = (la.s2 + b * ra.s2 % 1000000000 + (c - b) * ra.s1 % 1000000000) %
             1000000000;
    return tmp;
  }
}
void build(int l, int r, int n) {
  nde[n].l = l;
  nde[n].r = r;
  if (l >= r) {
    nde[n].lazy = 0;
    nde[n].s1 = 0;
    nde[n].s2 = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, n << 1);
  build(mid + 1, r, n << 1 | 1);
  pushup(n);
}
int main() {
  init();
  int n, m, t, x, l, r;
  long long y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  build(1, n, 1);
  while (m--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%I64d", &x, &y);
      update(x, y, 1);
    } else if (t == 2) {
      scanf("%d%d", &l, &r);
      tree ans = query(l, r, 1);
      printf("%I64d\n", (ans.s2 % 1000000000 + 1000000000) % 1000000000);
    } else {
      scanf("%d%d%I64d", &l, &r, &y);
      add(l, r, y, 1);
    }
  }
  return 0;
}

```