n, m = map(int, input().split()) A = list(map(int, input().split())) q = int(input()) for i in range(q): c, k, d = map(int, input().split()) A[c-1] -= k A[d-1] += k print(sum(a**2 for a in A))