#include <bits/stdc++.h>
using namespace std;
const int maxn = 140005;
long long it[maxn * 2 + 10][6][12], bau[100005][6][12];
int to[maxn * 2 + 10], from[maxn * 2 + 10];
long long a[maxn];
int n, m;
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  scanf("%d", &m);
}
void update(int pos, long long k, int zz, int co) {
  int idx = from[pos];
  while (idx) {
    it[idx][zz][co] += k;
    idx = to[idx];
  }
}
long long ask(int l, int r, int l1, int r1, int idx, int zz, int co) {
  int mid = l1 + r1;
  mid /= 2;
  long long ret = 0LL;
  if (idx > maxn * 2) return 0LL;
  if (l1 > r1 || l1 < 0 || r1 > 2 * n + 1) return 0LL;
  if (l1 >= l && r1 <= r) {
    ret = it[idx][zz][co];
  } else if (l1 > r || r1 < l)
    return 0LL;
  else if (mid >= r) {
    ret = ask(l, r, l1, mid, idx * 2, zz, co);
  } else if (l > mid)
    ret = ask(l, r, mid + 1, r1, idx * 2 + 1, zz, co);
  else {
    ret += ask(l, r, l1, mid, idx * 2, zz, co);
    ret += ask(l, r, mid + 1, r1, idx * 2 + 1, zz, co);
  }
  return ret;
}
void make(int l, int r, int idx) {
  if (l == r) {
    from[l] = idx;
    return;
  }
  to[idx * 2] = idx;
  to[idx * 2 + 1] = idx;
  int mid = (l + r) / 2;
  make(l, mid, idx * 2);
  make(mid + 1, r, idx * 2 + 1);
}
void init() {
  long long tmp, add;
  to[1] = 0;
  make(1, n, 1);
  for (int i = 2; i <= 6; ++i)
    for (int k = 1; k <= 2 * i - 2; ++k) {
      tmp = 1;
      add = 1;
      for (int j = k; j <= n; ++j) {
        bau[j][i][k] = tmp;
        if (tmp == i) {
          add = -1;
        } else if (tmp == 1) {
          add = 1;
        }
        tmp += add;
      }
    }
  for (int i = 2; i <= 6; ++i)
    for (int k = 1; k <= i * 2 - 2; ++k) {
      for (int j = 1; j <= n; ++j)
        if (j >= k) {
          tmp = bau[j][i][k];
          update(j, a[j] * tmp, i, k);
        }
    }
}
void update_all(int l, long long x) {
  long long tmp;
  for (int i = 2; i <= 6; ++i)
    for (int k = 1; k <= i * 2 - 2; ++k)
      if (l >= k) {
        tmp = bau[l][i][k];
        update(l, x * tmp - a[l] * tmp, i, k);
      }
  a[l] = x;
}
long long query(int l, int r, int Z) {
  long long ret = 0LL;
  long long tmp = 1, pos = l, add = 1;
  for (long long i = 1; i <= Z * 2 - 2; ++i)
    if (bau[l][Z][i] == 1 && i <= l) {
      ret += ask(l, r, 1, n, 1, Z, i);
      return ret;
    }
  cout << "FUCK" << endl;
  return 0;
}
void solve() {
  int left, right, t, z;
  long long x;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%lld", &left, &x);
      update_all(left, x);
    } else {
      scanf("%d%d%d", &left, &right, &z);
      printf("%lld\n", query(left, right, z));
    }
  }
}
int main() {
  read();
  init();
  solve();
  return 0;
}
