N,M = map(int,input().split()) A = list(map(int,input().split())) now = 0 for a in A: now += a * a for _ in range(int(input())): c,k,d = map(int,input().split()) c -= 1 d -= 1 now -= A[c] * A[c] + A[d] * A[d] A[c] -= k A[d] += k now += A[c] * A[c] + A[d] * A[d] print(now)