#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   long long init[N], tab[N * 2], ope[N][3], ch[N], h[N], num[N * 8], sum[N * 8],       ans[N * 8], nn, ss, aa;   bool ini[N * 2];   int sz = 0;   inline void Update(int x, int l, int r) {     if (l == r) return;     int lc = (x << 1), rc = lc + 1;     sum[x] = sum[lc] + sum[rc];     num[x] = num[lc] + num[rc];     ans[x] = ans[lc] + ans[rc] + num[lc] * sum[rc] - num[rc] * sum[lc];   }   inline void Build(int x, int l, int r) {     if (l == r) {       if (ini[l]) {         num[x] = 1;         sum[x] = tab[l];         ans[x] = 0;       }       return;     }     int mid = (l + r) >> 1, lc = (x << 1), rc = lc + 1;     Build(lc, l, mid);     Build(rc, mid + 1, r);     Update(x, l, r);   }   inline void Insert(int x, int l, int r, int pos, int tp) {     if (l == r) {       if (tp == 1) {         num[x] = 1;         sum[x] = tab[l];         ans[x] = 0;       } else         num[x] = sum[x] = ans[x] = 0;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       Insert(x << 1, l, mid, pos, tp);     else       Insert(x << 1 | 1, mid + 1, r, pos, tp);     Update(x, l, r);   }   inline void Query(int x, int l, int r, int a, int b) {     if (l > r) return;     if (l == a && r == b) {       aa = aa + ans[x] + nn * sum[x] - num[x] * ss;       nn += num[x];       ss += sum[x];       return;     }     if (l == r) return;     int mid = (l + r) >> 1;     if (b <= mid)       Query(x << 1, l, mid, a, b);     else if (a > mid)       Query(x << 1 | 1, mid + 1, r, a, b);     else       Query(x << 1, l, mid, a, mid), Query(x << 1 | 1, mid + 1, r, mid + 1, b);   }   int main() {     int n, q;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &init[i]);       tab[i] = ch[i] = h[i] = init[i];     }     sz = n;     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %I64d%I64d%I64d , &ope[i][0], &ope[i][1], &ope[i][2]);       if (ope[i][0] == 1) {         ch[ope[i][1]] += ope[i][2];         tab[++sz] = ch[ope[i][1]];       }     }     sort(init + 1, init + n + 1);     sort(tab + 1, tab + sz + 1);     unique(tab + 1, tab + sz + 1);     for (int i = 1; i <= sz; i++)       if (tab[i] > tab[i + 1]) sz = i;     int p = 1;     for (int i = 1; i <= n; i++) {       while (tab[p] != init[i] && p <= sz) p++;       ini[p] = 1;     }     Build(1, 1, sz);     int l, r;     for (int i = 1; i <= q; i++) {       if (ope[i][0] == 2) {         l = std::lower_bound(tab + 1, tab + sz + 1, ope[i][1]) - tab;         while (tab[l] < ope[i][1] && l <= sz) l++;         if (l == 0) l = 1;         if (l > sz) {           printf( 0 n );           continue;         }         r = std::lower_bound(tab + 1, tab + sz + 1, ope[i][2]) - tab;         if (r > sz) r = sz;         while (tab[r] > ope[i][2] && r >= 1) r--;         if (r <= 0) {           printf( 0 n );           continue;         }         nn = ss = aa = 0;         Query(1, 1, sz, l, r);         printf( %I64d n , aa);       } else {         l = std::lower_bound(tab + 1, tab + sz + 1, h[ope[i][1]]) - tab;         h[ope[i][1]] += ope[i][2];         r = std::lower_bound(tab + 1, tab + sz + 1, h[ope[i][1]]) - tab;         Insert(1, 1, sz, l, -1);         Insert(1, 1, sz, r, 1);       }     }     return 0;   }