#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) typedef long long ll; typedef long double ld; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; int main() { cin.tie(nullptr); ios::sync_with_stdio(0); int n; cin >> n; vector s(n); rep (i, n) cin >> s[i]; int m; cin >> m; vector > g(n, vector(n, Inf)); rep (i, n) g[i][i] = 0; rep (i, m) { int a, b, c; cin >> a >> b >> c; g[a][b] = g[b][a] = c; } rep (k, n) { rep (i, n) { rep (j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } ll res = Inf; FOR (i, 1, n - 1) { FOR (j, 1, n - 1) { if (i == j) continue; ll tmp = 0; tmp += s[i] + s[j]; tmp += g[0][i] + g[i][j] + g[j][n - 1]; res = min(res, tmp); } } cout << res << endl; return 0; }