#include <bits/stdc++.h>
using namespace std;
int n, cnt, last[1000010], in[1000010], ot[1000010], now;
struct edge {
  int to, next;
  long long w;
} e[1000010 << 1];
long long ans, w[1000010], mx[1000010 << 2], ad[1000010 << 2];
inline void add(int u, int v, int w) {
  e[++cnt] = {v, last[u], w}, last[u] = cnt;
  e[++cnt] = {u, last[v], w}, last[v] = cnt;
}
void dfs1(int x, int fa) {
  in[x] = ++now;
  for (int i = last[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs1(v, x);
  }
  ot[x] = now;
}
inline void down(int k) {
  mx[k << 1] += ad[k], mx[k << 1 | 1] += ad[k];
  ad[k << 1] += ad[k], ad[k << 1 | 1] += ad[k];
  ad[k] = 0;
}
inline void up(int k) { mx[k] = max(mx[k << 1], mx[k << 1 | 1]); }
void change(int k, int l, int r, int L, int R, long long v) {
  if (L > R) return;
  if (l >= L && r <= R) {
    mx[k] += v, ad[k] += v;
    return;
  }
  if (ad[k]) down(k);
  int m = l + r >> 1;
  if (L <= m) change(k << 1, l, m, L, R, v);
  if (R > m) change(k << 1 | 1, m + 1, r, L, R, v);
  up(k);
}
void dfs2(int x, int fa, long long o) {
  change(1, 1, n, in[x], in[x], o);
  for (int i = last[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs2(v, x, o - e[i].w + w[v]);
  }
}
void work(int x, int fa, long long v) {
  change(1, 1, n, in[x], ot[x], v - w[fa]);
  change(1, 1, n, 1, in[x] - 1, w[x] - v);
  change(1, 1, n, ot[x] + 1, n, w[x] - v);
  ans = max(ans, mx[1]);
  for (int i = last[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    work(v, x, e[i].w);
  }
  change(1, 1, n, in[x], ot[x], -v + w[fa]);
  change(1, 1, n, 1, in[x] - 1, v - w[x]);
  change(1, 1, n, ot[x] + 1, n, v - w[x]);
}
inline void solve() {
  scanf("%d", &n);
  for (auto i = (1); i <= (n); ++i) scanf("%lld", &w[i]);
  for (auto i = (1); i <= (n - 1); ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w);
  }
  dfs1(1, 0), dfs2(1, 0, w[1]);
  ans = mx[1];
  for (int i = last[1]; i; i = e[i].next) work(e[i].to, 1, e[i].w);
  printf("%lld\n", ans);
}
int main() { solve(); }
