#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
vector<pair<long long int, long long int> > adj[500005];
long long int fuel[500005];
long long int dp[500005];
long long int viz[500005];
long long int ans = 0;
void dfs(long long int x) {
  viz[x] = true;
  vector<long long int> vec;
  long long int cnt = 0;
  for (auto u : adj[x]) {
    if (!viz[u.first]) {
      dfs(u.first);
      cnt = max(0ll, dp[u.first] + fuel[u.first] - u.second);
      vec.push_back(cnt);
    }
  }
  sort(vec.rbegin(), vec.rend());
  if (!vec.empty())
    dp[x] = vec[0];
  else
    dp[x] = 0;
  if (vec.size() == 0)
    cnt = 0;
  else if (vec.size() == 1) {
    if (vec[0] != 0) {
      if (vec[0] + fuel[x] > 0)
        cnt = vec[0] + fuel[x];
      else
        cnt = 0;
    }
  } else {
    if (vec[0] != 0 || vec[1] != 0) cnt = fuel[x] + vec[0] + vec[1];
    if (vec[0] != 0) cnt = max(cnt, fuel[x] + vec[0]);
    cnt = max(0ll, cnt);
  }
  ans = max(ans, cnt);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    long long int n = 0, m = 0, k = 0, i = 0, j = 0, p = 0, q = 0, x = 0, y = 0,
                  z = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0, hi = 0;
    string s;
    bool flag = false;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> fuel[i];
    for (i = 0; i < n - 1; i++) {
      cin >> x >> y >> z;
      adj[x].push_back(make_pair(y, z));
      adj[y].push_back(make_pair(x, z));
    }
    dfs(1);
    for (i = 1; i <= n; i++) ans = max(ans, fuel[i]);
    cout << ans << endl;
    ;
  }
  return 0;
}
