N = int(input()) from scipy.sparse.csgraph import shortest_path import numpy as np S = np.array([int(input()) for i in range(N)]) D = np.zeros((N, N), dtype=int) M = int(input()) for i in range(M): a, b, c = map(int, input().split()) D[a, b] = c D[b, a] = c X = shortest_path(D, directed=False) from itertools import permutations ans = 10 ** 9 for i, j in permutations(range(1, N - 1), r=2): ans = min(ans, S[i] + S[j] + X[0, i] + X[i, j] + X[j, N - 1]) print(int(ans))