#include <bits/stdc++.h>
using namespace std;
class BinaryIndexedTree {
  int N;
  vector<long long> tree;

 public:
  BinaryIndexedTree(int _N = 0) : N(_N), tree(vector<long long>(_N + 1)) {}
  long long get_cumfreq(int idx) {
    long long sum = 0;
    for (; idx > 0; idx -= (idx & -idx)) sum += tree[idx];
    return sum;
  }
  void update(int idx, long long val = 1) {
    for (; idx <= N; idx += (idx & -idx)) tree[idx] += val;
  }
  long long get_freq(int idx) {
    if (idx <= 0) return 0;
    long long sum = tree[idx];
    int z = idx - (idx & -idx);
    for (--idx; idx != z; idx -= (idx & -idx)) sum -= tree[idx];
    return sum;
  }
};
int N;
long long A[100004];
int S[7][11];
BinaryIndexedTree bit[7][11];
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  for (int z = 2; z <= 6; ++z) {
    int M = 2 * (z - 1);
    for (int i = 1; i <= M; ++i) {
      int iModM = i % M;
      S[z][i] = iModM == 0 ? 2 : (iModM <= z ? iModM : (2 * z - iModM));
    }
    S[z][0] = S[z][M];
    for (int ini = 1; ini <= M; ++ini) {
      bit[z][ini] = BinaryIndexedTree(N);
      for (int i = ini; i <= N; ++i) {
        int iModM = (i - ini + 1) % M;
        bit[z][ini].update(i, A[i] * S[z][iModM]);
      }
    }
  }
  int Q;
  cin >> Q;
  while (Q-- > 0) {
    int t;
    cin >> t;
    if (t == 1) {
      int p, v;
      cin >> p >> v;
      for (int z = 2; z <= 6; ++z) {
        int M = 2 * (z - 1);
        for (int ini = 1; ini <= M; ++ini) {
          if (p < ini) continue;
          int iModM = (p - ini + 1) % M;
          bit[z][ini].update(p, (v - A[p]) * S[z][iModM]);
        }
      }
      A[p] = v;
    } else {
      int L, R, z;
      cin >> L >> R >> z;
      int M = 2 * (z - 1);
      int LModM = L % M;
      if (LModM == 0) LModM = M;
      long long res =
          bit[z][LModM].get_cumfreq(R) - bit[z][LModM].get_cumfreq(L - 1);
      cout << res << endl;
    }
  }
  return 0;
}
