N = int(input()) S = [int(input()) for _ in range(N)] M = int(input()) INF = 10 ** 5 cost = [[INF] * N for _ in range(N)] for i in range(N): cost[i][i] = 0 for _ in range(M): a, b, c = map(int, input().split()) cost[a][b] = min(cost[a][b], c) cost[b][a] = cost[a][b] 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]) ans = INF for i in range(1, N - 1): for j in range(1, N - 1): if i == j: continue tmp = S[0] + S[N - 1] tmp += cost[0][i] tmp += cost[i][j] tmp += cost[j][N - 1] tmp += S[i] tmp += S[j] ans = min(ans, tmp) print(ans)