N = int(input()) S = [int(input()) for _ in range(N)] G = [list() for _ in range(N)] from itertools import permutations M = int(input()) cost = [[float('inf')]*N for _ in range(N)] for i in range(N): cost[i][i] = 0 for i in range(M): A, B, C = map(int, input().split()) cost[A][B] = C cost[B][A] = C for k in range(N): for i in range(N): for j in range(N): cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]) res = float('inf') for v in permutations(range(1, N-1), 2): a, b = v[0], v[1] res = min(res, cost[0][a]+cost[a][b]+cost[b][-1]+S[a]+S[b]) print(res)