#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int MOD = 1e9;
int n, m;
class Seg {
 public:
  long long a, b, c, o;
  Seg(long long _a = 0, long long _b = 0, long long _c = 0, long long _o = 0) {}
} seg[N];
long long fib[N], a[N], fibsum[N];
void modify(int x, int l, int r, long long v) {
  seg[x].o = (seg[x].o + v) % MOD;
  seg[x].a = (seg[x].a + v * (r - l + 1)) % MOD;
  seg[x].b = (seg[x].b + v * (MOD + fibsum[r] - fibsum[l - 1])) % MOD;
  seg[x].c =
      (seg[x].c + v * (MOD + fibsum[r - 1] - (l >= 2 ? fibsum[l - 2] : 0))) %
      MOD;
}
void push(int x, int l, int r) {
  if (l == r) return;
  if (seg[x].o) {
    modify(x * 2, l, (l + r) / 2, seg[x].o);
    modify(x * 2 + 1, (l + r) / 2 + 1, r, seg[x].o);
    seg[x].o = 0;
  }
}
void pull(int x, int l, int r) {
  if (l == r) {
    seg[x].a = seg[x].o % MOD;
    seg[x].b = seg[x].o * fib[l] % MOD;
    seg[x].c = seg[x].o * fib[l - 1] % MOD;
    return;
  }
  int ll = x * 2, rr = x * 2 + 1;
  seg[x].a = (seg[ll].a + seg[rr].a) % MOD;
  seg[x].b = (seg[ll].b + seg[rr].b) % MOD;
  seg[x].c = (seg[ll].c + seg[rr].c) % MOD;
}
void add(int x, int l, int r, int ql, int qr, long long v) {
  if (l >= ql && r <= qr) {
    modify(x, l, r, v);
    return;
  }
  push(x, l, r);
  int M = (l + r) / 2;
  if (ql <= M) add(x * 2, l, M, ql, qr, v);
  if (qr > M) add(x * 2 + 1, M + 1, r, ql, qr, v);
  pull(x, l, r);
}
long long ra, rb, rc;
void ask(int x, int l, int r, int ql, int qr) {
  if (l >= ql && r <= qr) {
    ra += seg[x].a;
    rb += seg[x].b;
    rc += seg[x].c;
    return;
  }
  push(x, l, r);
  int M = (l + r) / 2;
  if (ql <= M) ask(x * 2, l, M, ql, qr);
  if (qr > M) ask(x * 2 + 1, M + 1, r, ql, qr);
  pull(x, l, r);
}
void get(int ql, int qr) {
  ra = rb = rc = 0;
  ask(1, 1, n, ql, qr);
  ra %= MOD;
  rb %= MOD;
  rc %= MOD;
}
int main(void) {
  scanf("%d%d", &n, &m);
  fib[0] = fib[1] = 1;
  for (int i = 2; i <= n; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
  fibsum[0] = 1;
  for (int i = 1; i <= n; i++) fibsum[i] = (fib[i] + fibsum[i - 1]) % MOD;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    add(1, 1, n, i, i, (a[i] + MOD) % MOD);
  }
  while (m--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int i, v;
      scanf("%d%d", &i, &v);
      get(i, i);
      add(1, 1, n, i, i, (v - ra + MOD) % MOD);
    } else if (t == 3) {
      int l, r, d;
      scanf("%d%d%d", &l, &r, &d);
      add(1, 1, n, l, r, d);
    } else {
      int ql, qr;
      scanf("%d%d", &ql, &qr);
      get(ql, qr);
      long long A = 0, B = 1, C = 1, D = MOD - 1, X = rb, Y = rc, P, Q, R, S;
      while (ql > 0) {
        if (ql % 2) {
          P = A * X + B * Y;
          Q = C * X + D * Y;
          X = P % MOD;
          Y = Q % MOD;
        }
        P = A * A + B * C;
        Q = A * B + B * D;
        R = C * A + D * C;
        S = C * B + D * D;
        A = P % MOD;
        B = Q % MOD;
        C = R % MOD;
        D = S % MOD;
        ql /= 2;
      }
      printf("%d\n", (int)X);
    }
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve 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 = 1000005;
const int MOD = 1e9;
int n, m;
class Seg {
 public:
  long long a, b, c, o;
  Seg(long long _a = 0, long long _b = 0, long long _c = 0, long long _o = 0) {}
} seg[N];
long long fib[N], a[N], fibsum[N];
void modify(int x, int l, int r, long long v) {
  seg[x].o = (seg[x].o + v) % MOD;
  seg[x].a = (seg[x].a + v * (r - l + 1)) % MOD;
  seg[x].b = (seg[x].b + v * (MOD + fibsum[r] - fibsum[l - 1])) % MOD;
  seg[x].c =
      (seg[x].c + v * (MOD + fibsum[r - 1] - (l >= 2 ? fibsum[l - 2] : 0))) %
      MOD;
}
void push(int x, int l, int r) {
  if (l == r) return;
  if (seg[x].o) {
    modify(x * 2, l, (l + r) / 2, seg[x].o);
    modify(x * 2 + 1, (l + r) / 2 + 1, r, seg[x].o);
    seg[x].o = 0;
  }
}
void pull(int x, int l, int r) {
  if (l == r) {
    seg[x].a = seg[x].o % MOD;
    seg[x].b = seg[x].o * fib[l] % MOD;
    seg[x].c = seg[x].o * fib[l - 1] % MOD;
    return;
  }
  int ll = x * 2, rr = x * 2 + 1;
  seg[x].a = (seg[ll].a + seg[rr].a) % MOD;
  seg[x].b = (seg[ll].b + seg[rr].b) % MOD;
  seg[x].c = (seg[ll].c + seg[rr].c) % MOD;
}
void add(int x, int l, int r, int ql, int qr, long long v) {
  if (l >= ql && r <= qr) {
    modify(x, l, r, v);
    return;
  }
  push(x, l, r);
  int M = (l + r) / 2;
  if (ql <= M) add(x * 2, l, M, ql, qr, v);
  if (qr > M) add(x * 2 + 1, M + 1, r, ql, qr, v);
  pull(x, l, r);
}
long long ra, rb, rc;
void ask(int x, int l, int r, int ql, int qr) {
  if (l >= ql && r <= qr) {
    ra += seg[x].a;
    rb += seg[x].b;
    rc += seg[x].c;
    return;
  }
  push(x, l, r);
  int M = (l + r) / 2;
  if (ql <= M) ask(x * 2, l, M, ql, qr);
  if (qr > M) ask(x * 2 + 1, M + 1, r, ql, qr);
  pull(x, l, r);
}
void get(int ql, int qr) {
  ra = rb = rc = 0;
  ask(1, 1, n, ql, qr);
  ra %= MOD;
  rb %= MOD;
  rc %= MOD;
}
int main(void) {
  scanf("%d%d", &n, &m);
  fib[0] = fib[1] = 1;
  for (int i = 2; i <= n; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
  fibsum[0] = 1;
  for (int i = 1; i <= n; i++) fibsum[i] = (fib[i] + fibsum[i - 1]) % MOD;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    add(1, 1, n, i, i, (a[i] + MOD) % MOD);
  }
  while (m--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int i, v;
      scanf("%d%d", &i, &v);
      get(i, i);
      add(1, 1, n, i, i, (v - ra + MOD) % MOD);
    } else if (t == 3) {
      int l, r, d;
      scanf("%d%d%d", &l, &r, &d);
      add(1, 1, n, l, r, d);
    } else {
      int ql, qr;
      scanf("%d%d", &ql, &qr);
      get(ql, qr);
      long long A = 0, B = 1, C = 1, D = MOD - 1, X = rb, Y = rc, P, Q, R, S;
      while (ql > 0) {
        if (ql % 2) {
          P = A * X + B * Y;
          Q = C * X + D * Y;
          X = P % MOD;
          Y = Q % MOD;
        }
        P = A * A + B * C;
        Q = A * B + B * D;
        R = C * A + D * C;
        S = C * B + D * D;
        A = P % MOD;
        B = Q % MOD;
        C = R % MOD;
        D = S % MOD;
        ql /= 2;
      }
      printf("%d\n", (int)X);
    }
  }
  return 0;
}

```