#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main(){ ll N, M, S=0, Q, C, K, D; cin >> N >> M; vector A(M+1); for (int i=0; i> A[i+1]; S += A[i+1] * A[i+1]; } cin >> Q; while(Q){ Q--; cin >> C >> K >> D; S -= A[C] * A[C]; S -= A[D] * A[D]; A[C] -= K; A[D] += K; S += A[C] * A[C]; S += A[D] * A[D]; cout << S << endl; } return 0; }