#include <bits/stdc++.h>
using namespace std;
const int N = 100044;
long long a[N], s[34][N];
int f[N][8], n, q;
void add(int idx, int p, long long w) {
  for (int i = p; i <= n; i += (i & -i)) s[idx][i] += w;
}
long long que(int idx, int p) {
  long long ans = 0;
  for (int i = p; i; i -= (i & -i)) ans += s[idx][i];
  return ans;
}
int g[] = {0, 0, 2, 4, 6, 8, 10}, sg[] = {0, 0, 2, 6, 12, 20, 30};
int main() {
  int x, y, z, op;
  long long v;
  scanf("%d", &n);
  for (int z = 2; z <= 6; z++) {
    for (int i = 1; i <= n + 40; i++) {
      int t = i % g[z];
      if (t == 0)
        f[i][z] = 2;
      else if (t <= z)
        f[i][z] = t;
      else
        f[i][z] = 2 * z - t;
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    for (int j = 2, s = 0; j <= 6; j++) {
      for (int k = 0; k < g[j]; k++) {
        add(s + k, i, a[i] * f[i - k + g[j]][j]);
      }
      s = sg[j];
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d %lld", &x, &v);
      long long d = v - a[x];
      for (int j = 2, s = 0; j <= 6; j++) {
        for (int k = 0; k < g[j]; k++) {
          add(s + k, x, d * f[x - k + g[j]][j]);
        }
        s = sg[j];
      }
      a[x] = v;
    } else {
      scanf("%d %d %d", &x, &y, &z);
      int ofs = (x - 1) % g[z];
      printf("%lld\n", que(sg[z - 1] + ofs, y) - que(sg[z - 1] + ofs, x - 1));
    }
  }
}
