/**
 *    author:  tourist
 *    created: 26.10.2022 07:36:10       
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  for (int it = 0; it <= q; it++) {
    long long ans = 0;
    int mn = a[0];
    for (int i = 0; i < n; i++) {
      mn = min(mn, a[i]);
      ans += mn;
    }
    cout << ans << '\n';
    if (it == q) {
      break;
    }
    int op, x;
    cin >> op >> x;
    if (op == 1) {
      a[x] += 1;
    } else {
      assert(a[x] > 0);
      a[x] -= 1;
    }
  }
  return 0;
}
