#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9;
int n, m;
long long a[200001], fibo[200001], fibosum0[200001], fibosum1[200001];
struct Segment_Tree {
  int left, right, len;
  long long s0, s1, lazy;
} tree[200001 << 2];
struct Data {
  long long a[2][2];
} bb[200001], one, b;
inline Data operator*(const Data x, const Data y) {
  Data res;
  res.a[0][0] = (x.a[0][0] * y.a[0][0] + x.a[0][1] * y.a[1][0]) % mod;
  res.a[0][1] = (x.a[0][0] * y.a[0][1] + x.a[0][1] * y.a[1][1]) % mod;
  res.a[1][0] = (x.a[1][0] * y.a[0][0] + x.a[1][1] * y.a[1][0]) % mod;
  res.a[1][1] = (x.a[1][0] * y.a[0][1] + x.a[1][1] * y.a[1][1]) % mod;
  return res;
}
inline long long cal_fx(long long s0, long long s1, int l) {
  return (bb[l - 1].a[0][0] * s1 + bb[l - 1].a[0][1] * s0) % mod;
}
inline void plant_tree(int id, int l, int r) {
  tree[id].left = l, tree[id].right = r;
  tree[id].len = r - l + 1, tree[id].lazy = 0;
  if (l == r) {
    tree[id].s0 = fibo[0] * a[l] % mod;
    tree[id].s1 = fibo[1] * a[l] % mod;
    return;
  }
  int mid = (l + r) >> 1;
  plant_tree(id << 1, l, mid);
  plant_tree(id << 1 | 1, mid + 1, r);
  tree[id].s0 =
      (tree[id << 1].s0 +
       cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %
      mod;
  tree[id].s1 =
      (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,
                                 tree[id << 1].len + 1)) %
      mod;
}
inline void push_down(int id) {
  if (!tree[id].lazy) return;
  if (tree[id].left != tree[id].right) {
    tree[id << 1].s0 =
        (tree[id << 1].s0 + tree[id].lazy * fibosum0[tree[id << 1].len - 1]) %
        mod;
    tree[id << 1].s1 =
        (tree[id << 1].s1 + tree[id].lazy * fibosum0[tree[id << 1].len]) % mod;
  }
  tree[id].lazy = 0;
}
inline void update_pos(int id, int pos, long long val) {
  if (tree[id].left == tree[id].right) {
    tree[id].s0 = fibo[0] * val % mod;
    tree[id].s1 = fibo[1] * val % mod;
    return;
  }
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (pos <= mid)
    update_pos(id << 1, pos, val);
  else
    update_pos(id << 1 | 1, pos, val);
  tree[id].s0 =
      (tree[id << 1].s0 +
       cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %
      mod;
  tree[id].s1 =
      (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,
                                 tree[id << 1].len + 1)) %
      mod;
}
inline void update_leaf(int id, int l, int r, long long val) {
  if (tree[id].left == l && tree[id].right == r) {
    tree[id].s0 = (tree[id].s0 + val * fibosum0[tree[id].len - 1]) % mod;
    tree[id].s1 = (tree[id].s1 + val * fibosum1[tree[id].len]) % mod;
    tree[id].lazy = (tree[id].lazy + val) % mod;
    return;
  }
  push_down(id);
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (r <= mid)
    update_leaf(id << 1, l, r, val);
  else if (mid < l)
    update_leaf(id << 1 | 1, l, r, val);
  else {
    update_leaf(id << 1, l, mid, val);
    update_leaf(id << 1 | 1, mid + 1, r, val);
  }
  tree[id].s0 =
      (tree[id << 1].s0 +
       cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %
      mod;
  tree[id].s1 =
      (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,
                                 tree[id << 1].len + 1)) %
      mod;
}
inline Segment_Tree query(int id, int l, int r) {
  if (tree[id].left == l && tree[id].right == r) {
    return tree[id];
  }
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (r <= mid)
    return query(id << 1, l, r);
  else if (mid < l)
    return query(id << 1 | 1, l, r);
  else {
    Segment_Tree leftson, rightson, now;
    leftson = query(id << 1, l, mid);
    rightson = query(id << 1 | 1, mid + 1, r);
    now.s0 = (leftson.s0 + cal_fx(rightson.s0, rightson.s1, leftson.len)) % mod;
    now.s1 =
        (leftson.s1 + cal_fx(rightson.s0, rightson.s1, leftson.len + 1)) % mod;
    now.len = leftson.len + rightson.len;
    return now;
  }
}
inline void init() {
  fibo[0] = fibo[1] = 1;
  for (int i = 2; i < 200001; i++) {
    fibo[i] = (fibo[i - 2] + fibo[i - 1]) % mod;
  }
  fibosum0[0] = fibo[0];
  for (int i = 1; i < 200001; i++) {
    fibosum0[i] = (fibosum0[i - 1] + fibo[i]) % mod;
    fibosum1[i] = (fibosum1[i - 1] + fibo[i]) % mod;
  }
  one.a[0][0] = one.a[1][1] = 1;
  one.a[1][0] = one.a[0][1] = 0;
  b.a[0][0] = b.a[0][1] = b.a[1][0] = 1;
  b.a[1][1] = 0;
  bb[0] = one;
  for (int i = 1; i < 200001; i++) {
    bb[i] = bb[i - 1] * b;
  }
}
int main() {
  init();
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
  }
  plant_tree(1, 1, n);
  while (m--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int x, v;
      scanf("%d %d", &x, &v);
      update_pos(1, x, v);
    } else if (type == 2) {
      int l, r;
      scanf("%d %d", &l, &r);
      Segment_Tree res = query(1, l, r);
      printf("%lld\n", res.s0);
    } else if (type == 3) {
      int l, r, d;
      scanf("%d %d %d", &l, &r, &d);
      update_leaf(1, l, r, d);
    }
  }
}

### Prompt

Please formulate a cpp solution to the following problem:

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;
const long long mod = 1e9;
int n, m;
long long a[200001], fibo[200001], fibosum0[200001], fibosum1[200001];
struct Segment_Tree {
  int left, right, len;
  long long s0, s1, lazy;
} tree[200001 << 2];
struct Data {
  long long a[2][2];
} bb[200001], one, b;
inline Data operator*(const Data x, const Data y) {
  Data res;
  res.a[0][0] = (x.a[0][0] * y.a[0][0] + x.a[0][1] * y.a[1][0]) % mod;
  res.a[0][1] = (x.a[0][0] * y.a[0][1] + x.a[0][1] * y.a[1][1]) % mod;
  res.a[1][0] = (x.a[1][0] * y.a[0][0] + x.a[1][1] * y.a[1][0]) % mod;
  res.a[1][1] = (x.a[1][0] * y.a[0][1] + x.a[1][1] * y.a[1][1]) % mod;
  return res;
}
inline long long cal_fx(long long s0, long long s1, int l) {
  return (bb[l - 1].a[0][0] * s1 + bb[l - 1].a[0][1] * s0) % mod;
}
inline void plant_tree(int id, int l, int r) {
  tree[id].left = l, tree[id].right = r;
  tree[id].len = r - l + 1, tree[id].lazy = 0;
  if (l == r) {
    tree[id].s0 = fibo[0] * a[l] % mod;
    tree[id].s1 = fibo[1] * a[l] % mod;
    return;
  }
  int mid = (l + r) >> 1;
  plant_tree(id << 1, l, mid);
  plant_tree(id << 1 | 1, mid + 1, r);
  tree[id].s0 =
      (tree[id << 1].s0 +
       cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %
      mod;
  tree[id].s1 =
      (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,
                                 tree[id << 1].len + 1)) %
      mod;
}
inline void push_down(int id) {
  if (!tree[id].lazy) return;
  if (tree[id].left != tree[id].right) {
    tree[id << 1].s0 =
        (tree[id << 1].s0 + tree[id].lazy * fibosum0[tree[id << 1].len - 1]) %
        mod;
    tree[id << 1].s1 =
        (tree[id << 1].s1 + tree[id].lazy * fibosum0[tree[id << 1].len]) % mod;
  }
  tree[id].lazy = 0;
}
inline void update_pos(int id, int pos, long long val) {
  if (tree[id].left == tree[id].right) {
    tree[id].s0 = fibo[0] * val % mod;
    tree[id].s1 = fibo[1] * val % mod;
    return;
  }
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (pos <= mid)
    update_pos(id << 1, pos, val);
  else
    update_pos(id << 1 | 1, pos, val);
  tree[id].s0 =
      (tree[id << 1].s0 +
       cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %
      mod;
  tree[id].s1 =
      (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,
                                 tree[id << 1].len + 1)) %
      mod;
}
inline void update_leaf(int id, int l, int r, long long val) {
  if (tree[id].left == l && tree[id].right == r) {
    tree[id].s0 = (tree[id].s0 + val * fibosum0[tree[id].len - 1]) % mod;
    tree[id].s1 = (tree[id].s1 + val * fibosum1[tree[id].len]) % mod;
    tree[id].lazy = (tree[id].lazy + val) % mod;
    return;
  }
  push_down(id);
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (r <= mid)
    update_leaf(id << 1, l, r, val);
  else if (mid < l)
    update_leaf(id << 1 | 1, l, r, val);
  else {
    update_leaf(id << 1, l, mid, val);
    update_leaf(id << 1 | 1, mid + 1, r, val);
  }
  tree[id].s0 =
      (tree[id << 1].s0 +
       cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %
      mod;
  tree[id].s1 =
      (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,
                                 tree[id << 1].len + 1)) %
      mod;
}
inline Segment_Tree query(int id, int l, int r) {
  if (tree[id].left == l && tree[id].right == r) {
    return tree[id];
  }
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (r <= mid)
    return query(id << 1, l, r);
  else if (mid < l)
    return query(id << 1 | 1, l, r);
  else {
    Segment_Tree leftson, rightson, now;
    leftson = query(id << 1, l, mid);
    rightson = query(id << 1 | 1, mid + 1, r);
    now.s0 = (leftson.s0 + cal_fx(rightson.s0, rightson.s1, leftson.len)) % mod;
    now.s1 =
        (leftson.s1 + cal_fx(rightson.s0, rightson.s1, leftson.len + 1)) % mod;
    now.len = leftson.len + rightson.len;
    return now;
  }
}
inline void init() {
  fibo[0] = fibo[1] = 1;
  for (int i = 2; i < 200001; i++) {
    fibo[i] = (fibo[i - 2] + fibo[i - 1]) % mod;
  }
  fibosum0[0] = fibo[0];
  for (int i = 1; i < 200001; i++) {
    fibosum0[i] = (fibosum0[i - 1] + fibo[i]) % mod;
    fibosum1[i] = (fibosum1[i - 1] + fibo[i]) % mod;
  }
  one.a[0][0] = one.a[1][1] = 1;
  one.a[1][0] = one.a[0][1] = 0;
  b.a[0][0] = b.a[0][1] = b.a[1][0] = 1;
  b.a[1][1] = 0;
  bb[0] = one;
  for (int i = 1; i < 200001; i++) {
    bb[i] = bb[i - 1] * b;
  }
}
int main() {
  init();
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
  }
  plant_tree(1, 1, n);
  while (m--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int x, v;
      scanf("%d %d", &x, &v);
      update_pos(1, x, v);
    } else if (type == 2) {
      int l, r;
      scanf("%d %d", &l, &r);
      Segment_Tree res = query(1, l, r);
      printf("%lld\n", res.s0);
    } else if (type == 3) {
      int l, r, d;
      scanf("%d %d %d", &l, &r, &d);
      update_leaf(1, l, r, d);
    }
  }
}

```