#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; #include void solve() { int n; cin >> n; atcoder::mf_graph g(410); int S = 408, T = 409; ll ans = 0; rep(i, 0, n) { int p; cin >> p; if (p < 0) { g.add_edge(S, i, -p); } else { ans += p; g.add_edge(i, T, p); } } int m; cin >> m; rep(i, 0, m) { int u, v; cin >> u >> v; u--, v--; g.add_edge(u, v, 1e18); } int k; cin >> k; rep(i, 0, k) { int a, b, s; cin >> a >> b >> s; a--, b--; ans += s; g.add_edge(a, n + i, 1e18); g.add_edge(b, n + i, 1e18); g.add_edge(n + i, T, s); } ans -= g.flow(S, T); cout << ans << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }