#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > gr[300002];
int n;
long long w[300002];
bool v[300002];
long long mx = -1;
long long dfs(int u) {
  long long mx1 = 0, mx2 = 0;
  v[u] = 1;
  for (auto e : gr[u])
    if (!v[e.first]) {
      long long val = dfs(e.first) - e.second;
      if (val >= mx1) {
        mx2 = mx1;
        mx1 = val;
      } else if (val > mx2)
        mx2 = val;
    }
  mx = max(mx, mx1 + mx2 + w[u]);
  return mx1 + w[u];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 1; i < n; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    gr[u].push_back(make_pair(v, c));
    gr[v].push_back(make_pair(u, c));
  }
  dfs(1);
  cout << mx << "\n";
  return 0;
}
