#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n, v[N];
vector<vector<int> > g;
vector<int> dp[5001][N];
vector<int> vals[N];
int calc(int u, int i, int rem) {
  if (i == -1) {
    if (rem) return 1e9;
    return 0;
  }
  int &ret = dp[rem][u][i];
  if (ret != -1) return ret;
  ret = 1e9;
  if (i == g[u].size()) {
    ret = max(v[u], calc(u, i - 1, rem));
    if (ret > v[u]) ret = 1e9;
    if (rem <= v[u]) ret = min(ret, calc(u, i - 1, v[u] - rem));
    return ret;
  }
  vector<int> &q = vals[g[u][i]];
  for (int take = 0; take < q.size() && q[take] <= rem; ++take)
    ret = min(ret, calc(g[u][i], g[g[u][i]].size(), q[take]) +
                       calc(u, i - 1, rem - q[take]));
  return ret;
}
void DFS(int u) {
  set<int> v;
  v.insert(::v[u]);
  for (int i = 0; i < g[u].size(); ++i) {
    DFS(g[u][i]);
    for (auto x : vals[g[u][i]]) v.insert(x);
  }
  v.insert(0);
  for (auto x : v) vals[u].push_back(x);
  sort(vals[u].begin(), vals[u].end());
}
int main() {
  scanf("%d", &n);
  cout << sizeof(dp) << endl;
  return 0;
  g.resize(n);
  for (int x, i = 1; i < n; ++i) {
    scanf("%d", &x);
    g[x - 1].push_back(i);
  }
  for (int j = 0; j <= 5000; ++j)
    for (int i = 0; i < n; ++i) dp[j][i].resize(g[i].size() + 1, -1);
  for (int i = 0; i < n; ++i) scanf("%d", v + i);
  for (int i = 0; i < n; ++i) DFS(i);
  for (int i = 0; i <= 5000; ++i)
    if (calc(0, g[0].size(), i) < 1e8) {
      puts("POSSIBLE");
      return 0;
    }
  puts("IMPOSSIBLE");
  return 0;
}
