#include using namespace std; const int INF = 100100100; int main(){ cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N; vector s(N); for(int i = 0; i < N; ++i) cin >> s[i]; vector dist(N, vector(N, INF)); for(int i = 0; i < N; ++i){ dist[i][i] = 0; } cin >> M; for(int i = 0; i < M; ++i){ int a, b, c; cin >> a >> b >> c; dist[a][b] = dist[b][a] = c; } for(int k = 0; k < N; ++k){ for(int i = 0; i < N; ++i){ for(int j = 0; j < N; ++j){ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } int ans = INF; for(int i = 1; i + 1 < N; ++i){ for(int j = 1; j + 1 < N; ++j){ if(i == j) continue; int res = 0; res += dist[0][i] + dist[i][j] + dist[j][N - 1]; res += s[i] + s[j]; ans = min(ans, res); } } cout << ans << endl; return 0; }