#include using namespace std; int main() { int N, M, Q; cin >> N >> M; vector a( M ); long long s = 0; for( int i = 0; i < M; i++ ) { cin >> a[i]; s += a[i] * a[i]; } cin >> Q; for( int i = 0; i < Q; i++ ) { int c, k, d; cin >> c >> k >> d; c--; d--; long long pre = a[c] * a[c] + a[d] * a[d]; a[c] -= k; a[d] += k; long long post = a[c] * a[c] + a[d] * a[d]; s += post - pre; cout << s << endl; } }