#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<pair<int, int> > adj[N];
int w[N];
long long dp[N][2], res;
void dfs1(int u, int par) {
  dp[u][0] = w[u];
  for (pair<int, int> v : adj[u]) {
    if (v.first == par) continue;
    dfs1(v.first, u);
    dp[u][0] = max(dp[u][0], dp[v.first][0] + w[u] - v.second);
  }
}
void dfs2(int u, int par) {
  long long best = 0, se_best = 0;
  for (pair<int, int> v : adj[u]) {
    if (v.first == par) continue;
    if (dp[v.first][0] + w[u] - v.second >= best) {
      swap(best, se_best);
      best = dp[v.first][0] + w[u] - v.second;
    } else {
      if (dp[v.first][0] + w[u] - v.second > se_best)
        se_best = dp[v.first][0] + w[u] - v.second;
    }
  }
  for (pair<int, int> v : adj[u]) {
    if (v.first == par) continue;
    dp[v.first][1] = max(0LL, dp[u][1] - 1LL * v.second);
    if (best == w[u] + dp[v.first][0] - v.second && best != se_best) {
      dp[v.first][1] = max(dp[v.first][1], se_best - v.second);
    } else {
      dp[v.first][1] = max(dp[v.first][1], best - v.second);
    }
    dfs2(v.first, u);
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  for (int i = 1; i <= n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(pair<int, int>(v, c));
    adj[v].push_back(pair<int, int>(u, c));
  }
  dfs1(1, -1);
  dfs2(1, -1);
  for (int i = 1; i <= n; ++i) res = max(res, dp[i][1] + dp[i][0]);
  cout << res;
  return 0;
}
