#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long binpow(long long base, long long exp, int mod) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % mod;
    exp = exp >> 1;
    base = (base * base) % mod;
  }
  return res;
}
long long mod(long long x) {
  return ((x % 1000000007LL + 1000000007LL) % 1000000007LL);
}
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
vector<long long int> graph[300005];
vector<long long int> visited(300005, false);
long long int dp[300005];
long long int ans = 0;
map<pair<long long int, long long int>, long long int> edgecost;
long long int nodegas[300005];
void dfs(long long int current) {
  visited[current] = 1;
  long long int max1 = 0, max2 = 0;
  for (auto i : graph[current]) {
    if (!visited[i]) {
      dfs(i);
      if (dp[i] - edgecost[{i, current}] >= max1) {
        max2 = max1;
        max1 = dp[i] - edgecost[{i, current}];
      } else {
        if (dp[i] - edgecost[{i, current}] > max2) {
          max2 = dp[i] - edgecost[{i, current}];
        }
      }
    }
  }
  dp[current] = nodegas[current] + max1;
  ans = max(ans, dp[current] + max2);
}
int main() {
  long long int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long int w;
    cin >> w;
    nodegas[i] = w;
  }
  for (int i = 0; i < n - 1; i++) {
    long long int l, r, c;
    cin >> l >> r >> c;
    graph[l].push_back(r);
    graph[r].push_back(l);
    edgecost[{l, r}] = c;
    edgecost[{r, l}] = c;
  }
  dfs(1);
  cout << ans << "\n";
  return 0;
}
