#include <bits/stdc++.h>
using namespace std;
int n, tot, s[300005], dn[300005], up[300005], w[300005], C, sum;
pair<long long, int> d[300005][2];
long long dis[300005], ans;
bool vis[300005];
vector<pair<int, int> > e[300005];
inline void push(const int &u, const int &v, const int &c) {
  e[u].emplace_back(v, c);
}
inline void read(int &x) {
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
}
void dfs(const int &u, const int &f = 0) {
  dn[u] = 1;
  for (auto _V : e[u])
    if (_V.first != f && !vis[_V.first])
      dfs(_V.first, u), dn[u] += dn[_V.first];
}
void upd(const int &u, const int &f = 0) {
  d[u][0] = d[u][1] = {0, 0};
  for (auto _V : e[u])
    if (_V.first != f && !vis[_V.first])
      dis[_V.first] = -_V.second, upd(_V.first, u);
  dis[u] += d[u][0].first;
  d[f][1] = max(d[f][1], {dis[u] + w[u], u});
  if (d[f][1] > d[f][0]) swap(d[f][1], d[f][0]);
}
void dnd(const int &u, const int &f = 0) {
  ans = max(ans, dis[u] += w[u]);
  for (auto _V : e[u])
    if (_V.first != f && !vis[_V.first])
      if (dis[u] - _V.second >= 0)
        dis[_V.first] = dis[u] - _V.second, dnd(_V.first, u);
}
void find(const int &u, const int &f = 0) {
  up[u] = sum - dn[u];
  for (auto _V : e[u])
    if (_V.first != f && !vis[_V.first]) find(_V.first, u);
  up[u] = max(up[u], dn[u]);
  if (up[u] < up[C]) C = u;
}
void solve(const int &u, const int &f = 0) {
  vis[u] = 1;
  dis[u] = w[u];
  upd(u);
  ans = max(ans, w[u] + d[u][0].first);
  for (auto _V : e[u])
    if (_V.first != f && !vis[_V.first]) {
      if (_V.first != d[u][0].second) {
        if (w[u] + d[u][0].first - _V.second >= 0)
          dis[_V.first] = w[u] + d[u][0].first - _V.second, dnd(_V.first, u);
      } else if (w[u] + d[u][1].first - _V.second >= 0)
        dis[_V.first] = w[u] + d[u][1].first - _V.second, dnd(_V.first, u);
    }
  for (auto _V : e[u])
    if (_V.first != f && !vis[_V.first])
      dfs(_V.first), sum = dn[_V.first], C = 0, find(_V.first), solve(C);
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(w[i]);
  up[0] = n + 1;
  for (int i = 1, u, v, c; i < n; i++)
    read(u), read(v), read(c), push(u, v, c), push(v, u, c);
  ;
  upd(1);
  for (int i = 1; i <= n; i++)
    ans = max(ans, d[i][0].first + d[i][1].first + w[i]);
  printf("%lld\n", ans);
}
