#include <bits/stdc++.h>
using namespace std;
const int N = 200011;
const int mod = 1e9;
int addIt(int x, int val) {
  x += val;
  if (x >= mod) x -= mod;
  return x;
}
int f[N], pref[N];
int tot;
struct Node {
  int S0, S1, add, l, r;
  void init(int l, int r) {
    add = 0;
    this->l = l;
    this->r = r;
  }
  int mid() { return l + r >> 1; }
  Node operator+(const Node &b) const {
    Node ret;
    ret.l = l;
    ret.r = b.r;
    int m = ret.mid();
    int x = m - l + 1;
    if (x == 1) {
      ret.S0 = addIt(S0, b.S1);
    } else {
      ret.S0 = addIt(S0, f[x - 2] * (long long)b.S0 % mod);
      ret.S0 = addIt(ret.S0, (long long)b.S1 * f[x - 1] % mod);
    }
    ret.S1 = addIt(S1, f[x - 1] * (long long)b.S0 % mod);
    ret.S1 = addIt(ret.S1, f[x] * (long long)b.S1 % mod);
    return ret;
  }
} ly[N << 2];
void build(int l, int r, int o) {
  ly[o].init(l, r);
  if (l == r) {
    int x;
    scanf("%d", &x);
    ly[o].S0 = x * f[0];
    ly[o].S1 = x * f[1];
  } else {
    int m = ly[o].mid();
    build(l, m, o << 1);
    build(m + 1, r, o << 1 | 1);
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
  }
}
void Set(int o, int val) {
  ly[o].add = addIt(ly[o].add, val);
  int x = ly[o].r - ly[o].l + 1;
  ly[o].S0 = addIt(ly[o].S0, pref[x - 1] * (long long)val % mod);
  ly[o].S1 =
      addIt(ly[o].S1, (pref[x] - pref[0] + mod) % mod * (long long)val % mod);
}
void down(int o) {
  if (ly[o].add) {
    Set(o << 1, ly[o].add);
    Set(o << 1 | 1, ly[o].add);
    ly[o].add = 0;
  }
}
void update(int o, int L, int R, int val) {
  if (L <= ly[o].l && ly[o].r <= R) {
    Set(o, val);
  } else {
    int m = ly[o].mid();
    down(o);
    if (L <= m) update(o << 1, L, R, val);
    if (R > m) update(o << 1 | 1, L, R, val);
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
  }
}
void update(int o, int L, int val) {
  if (ly[o].l == ly[o].r) {
    ly[o].S0 = val * f[0];
    ly[o].S1 = val * f[1];
  } else {
    int m = ly[o].mid();
    down(o);
    if (L <= m)
      update(o << 1, L, val);
    else
      update(o << 1 | 1, L, val);
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
  }
}
int query(int o, int L, int R) {
  if (L <= ly[o].l && ly[o].r <= R) {
    int x = ly[o].l - L, ret = 0;
    if (x == 0) {
      ret = ly[o].S0;
    } else if (x == 1) {
      ret = ly[o].S1;
    } else {
      ret = addIt(ret, ly[o].S0 * (long long)f[x - 2] % mod);
      ret = addIt(ret, ly[o].S1 * (long long)f[x - 1] % mod);
    }
    return ret;
  } else {
    int m = ly[o].mid();
    int ret = 0;
    down(o);
    if (L <= m) ret = query(o << 1, L, R);
    if (R > m) ret = addIt(ret, query(o << 1 | 1, L, R));
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
    return ret;
  }
}
void prepare(int n) {
  f[0] = f[1] = pref[0] = 1;
  pref[1] = 2;
  for (int i = 2; i <= n; i++) {
    f[i] = addIt(f[i - 1], f[i - 2]);
    pref[i] = addIt(pref[i - 1], f[i]);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  prepare(n);
  build(1, n, 1);
  for (int i = 0; i < m; i++) {
    int op, l, r, val;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      update(1, l, r);
    } else if (op == 2) {
      printf("%d\n", query(1, l, r));
    } else {
      scanf("%d", &val);
      update(1, l, r, val);
    }
  }
  return 0;
}

### Prompt

Your challenge is to write 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 int N = 200011;
const int mod = 1e9;
int addIt(int x, int val) {
  x += val;
  if (x >= mod) x -= mod;
  return x;
}
int f[N], pref[N];
int tot;
struct Node {
  int S0, S1, add, l, r;
  void init(int l, int r) {
    add = 0;
    this->l = l;
    this->r = r;
  }
  int mid() { return l + r >> 1; }
  Node operator+(const Node &b) const {
    Node ret;
    ret.l = l;
    ret.r = b.r;
    int m = ret.mid();
    int x = m - l + 1;
    if (x == 1) {
      ret.S0 = addIt(S0, b.S1);
    } else {
      ret.S0 = addIt(S0, f[x - 2] * (long long)b.S0 % mod);
      ret.S0 = addIt(ret.S0, (long long)b.S1 * f[x - 1] % mod);
    }
    ret.S1 = addIt(S1, f[x - 1] * (long long)b.S0 % mod);
    ret.S1 = addIt(ret.S1, f[x] * (long long)b.S1 % mod);
    return ret;
  }
} ly[N << 2];
void build(int l, int r, int o) {
  ly[o].init(l, r);
  if (l == r) {
    int x;
    scanf("%d", &x);
    ly[o].S0 = x * f[0];
    ly[o].S1 = x * f[1];
  } else {
    int m = ly[o].mid();
    build(l, m, o << 1);
    build(m + 1, r, o << 1 | 1);
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
  }
}
void Set(int o, int val) {
  ly[o].add = addIt(ly[o].add, val);
  int x = ly[o].r - ly[o].l + 1;
  ly[o].S0 = addIt(ly[o].S0, pref[x - 1] * (long long)val % mod);
  ly[o].S1 =
      addIt(ly[o].S1, (pref[x] - pref[0] + mod) % mod * (long long)val % mod);
}
void down(int o) {
  if (ly[o].add) {
    Set(o << 1, ly[o].add);
    Set(o << 1 | 1, ly[o].add);
    ly[o].add = 0;
  }
}
void update(int o, int L, int R, int val) {
  if (L <= ly[o].l && ly[o].r <= R) {
    Set(o, val);
  } else {
    int m = ly[o].mid();
    down(o);
    if (L <= m) update(o << 1, L, R, val);
    if (R > m) update(o << 1 | 1, L, R, val);
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
  }
}
void update(int o, int L, int val) {
  if (ly[o].l == ly[o].r) {
    ly[o].S0 = val * f[0];
    ly[o].S1 = val * f[1];
  } else {
    int m = ly[o].mid();
    down(o);
    if (L <= m)
      update(o << 1, L, val);
    else
      update(o << 1 | 1, L, val);
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
  }
}
int query(int o, int L, int R) {
  if (L <= ly[o].l && ly[o].r <= R) {
    int x = ly[o].l - L, ret = 0;
    if (x == 0) {
      ret = ly[o].S0;
    } else if (x == 1) {
      ret = ly[o].S1;
    } else {
      ret = addIt(ret, ly[o].S0 * (long long)f[x - 2] % mod);
      ret = addIt(ret, ly[o].S1 * (long long)f[x - 1] % mod);
    }
    return ret;
  } else {
    int m = ly[o].mid();
    int ret = 0;
    down(o);
    if (L <= m) ret = query(o << 1, L, R);
    if (R > m) ret = addIt(ret, query(o << 1 | 1, L, R));
    ly[o] = ly[o << 1] + ly[o << 1 | 1];
    return ret;
  }
}
void prepare(int n) {
  f[0] = f[1] = pref[0] = 1;
  pref[1] = 2;
  for (int i = 2; i <= n; i++) {
    f[i] = addIt(f[i - 1], f[i - 2]);
    pref[i] = addIt(pref[i - 1], f[i]);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  prepare(n);
  build(1, n, 1);
  for (int i = 0; i < m; i++) {
    int op, l, r, val;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      update(1, l, r);
    } else if (op == 2) {
      printf("%d\n", query(1, l, r));
    } else {
      scanf("%d", &val);
      update(1, l, r, val);
    }
  }
  return 0;
}

```