#include <bits/stdc++.h>
#pragma GCC optimize("O3")
namespace io {
class input_reader {
  std::istream &in;
  void throw_error() {
    throw std::runtime_error("No more inputs while reading number");
  }
  template <typename T>
  inline void readIntegerValue(T &f) {
    bool positive = true;
    f = 0;
    char c;
    if (!in.get(c)) throw_error();
    while (c < '0' || c > '9') {
      if (c == '-') positive = false;
      if (!in.get(c)) throw_error();
    }
    while (c >= '0' && c <= '9') {
      f = (f << 3) + (f << 1) + (c & 15);
      if (!in.get(c)) break;
    }
    if (!positive) f *= -1;
  }

 public:
  explicit input_reader(std::istream &in) : in(in) {}
  inline void read(int &f) { readIntegerValue(f); }
  inline void read(short &f) { readIntegerValue(f); }
  inline void read(long int &f) { readIntegerValue(f); }
  inline void read(long long int &f) { readIntegerValue(f); }
  inline void read(unsigned int &f) { readIntegerValue(f); }
  inline void read(unsigned short &f) { readIntegerValue(f); }
  inline void read(unsigned long int &f) { readIntegerValue(f); }
  inline void read(unsigned long long int &f) { readIntegerValue(f); }
  template <typename T>
  inline void read(std::vector<T> &f) {
    for (auto &i : f) read(i);
  }
  template <typename T, int N>
  inline void read(std::array<T, N> &res) {
    for (auto &i : res) read(i);
  }
  template <typename T1, typename T2>
  inline void read(std::pair<T1, T2> &p) {
    in.read(p.first, p.second);
  }
  template <typename T>
  inline void read(T &f) {
    in >> f;
  }
  template <typename T, typename... Args>
  inline void read(T &t, Args &...args) {
    read(t), read(args...);
  }
  template <typename T>
  inline void readArray(int n, T *res) {
    while (n--) read(*(res++));
  }
  template <typename T>
  inline input_reader &operator>>(T &t) {
    return read(t), *this;
  }
};
}  // namespace io
namespace io {
class output_writer {
  std::ostream &out;
  template <typename T>
  inline void printIntegerHelper(T x) {
    if (x >= 10) printIntegerHelper(x / 10);
    out.put(x % 10 + 48);
  }
  template <typename T>
  inline void printInteger(T x) {
    if (x < 0) out.put('-'), x = -x;
    printIntegerHelper(x);
  }
  template <typename T>
  inline void printArray(T &ar) {
    bool first = true;
    for (auto &t : ar) print((first) ? first = false, "" : " ", t);
  }

 public:
  explicit output_writer(std::ostream &out) : out(out) {}
  inline void flush() { out.flush(); }
  inline void print() {}
  inline void print(char x) { out.put(x); }
  inline void print(short x) { printInteger(x); }
  inline void print(int x) { printInteger(x); }
  inline void print(long int x) { printInteger(x); }
  inline void print(long long int x) { printInteger(x); }
  inline void print(unsigned short x) { printInteger(x); }
  inline void print(unsigned int x) { printInteger(x); }
  inline void print(unsigned long int x) { printInteger(x); }
  inline void print(unsigned long long int x) { printInteger(x); }
  template <typename T1>
  inline void print(const T1 &t1) {
    out << t1;
  }
  template <typename T1>
  inline void print(const std::vector<T1> &t1) {
    printArray(t1);
  }
  template <typename T1, int N>
  inline void print(const std::array<T1, N> &t1) {
    printArray(t1);
  }
  template <typename T1, int N, int M>
  inline void print(const std::array<std::array<T1, M>, N> &t1) {
    for (auto &t : t1) println(t);
  }
  template <typename T1>
  inline void print(const std::vector<std::vector<T1>> &t1) {
    for (auto &t : t1) println(t);
  }
  template <typename T, typename... Args>
  inline void print(const T &t, Args... args) {
    print(t), print(args...);
  }
  template <typename... Args>
  inline void println(Args... args) {
    print(args...), print('\n');
  }
  template <typename T>
  output_writer &operator<<(const T &t) {
    return print(t), *this;
  }
};
}  // namespace io
inline long long int pow_mod(const long long int a, const long long int b,
                             const long long int MOD) {
  if (b == 0) return 1;
  if (b == 1) return a % MOD;
  long long int res = pow_mod(a * a % MOD, b >> 1, MOD);
  if (b & 1) res = res * a % MOD;
  return res % MOD;
}
inline long long int mod_inv(const long long int a, const long long int MOD) {
  return pow_mod(a, MOD - 2, MOD);
}
template <typename T>
T gcd(const T &a, const T &b) {
  if (*a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T lcm(const T &a, const T &b) {
  assert(a != 0 && b != 0);
  return a / gcd(a, b) * b;
}
using namespace std;
class DServalAndRootedTree {
  class Solver {
    io::input_reader in;
    io::output_writer out;

   public:
    Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}
    int n;
    vector<int> op, p;
    vector<vector<int>> e;
    struct minimax {
      int count_children, max_child_index_returned;
    };
    vector<minimax> dp;
    minimax dfs(const int i) {
      if (e[i].empty()) return {1, 1};
      vector<minimax> mm;
      for (int j : e[i]) {
        mm.push_back(dp[j]);
      }
      int count = 0;
      for (auto j : mm) count += j.count_children;
      int best;
      if (op[i]) {
        best = 0;
        for (auto j : mm)
          best =
              max(best, count - j.count_children + j.max_child_index_returned);
      } else {
        best = 0;
        int sum = 0;
        for (auto j : mm) {
          sum += j.count_children - j.max_child_index_returned + 1;
        }
        for (auto j : mm) {
          best = max(best, count -
                               (sum - (j.count_children -
                                       j.max_child_index_returned + 1)) -
                               (j.count_children - j.max_child_index_returned));
        }
      }
      return {count, best};
    }
    void solve() {
      in >> n;
      op.resize(n), p.resize(n - 1), dp.resize(n);
      in >> op >> p;
      e.resize(n);
      for (int i = 0; i < n - 1; i++) {
        int pp = p[i];
        e[pp - 1].push_back(i + 1);
      }
      vector<int> bfs;
      {
        int i = 0;
        bfs.push_back(0);
        while (i < n) {
          int cur = bfs[i++];
          for (int j : e[cur]) bfs.push_back(j);
        }
      }
      reverse((bfs).begin(), (bfs).end());
      for (int i : bfs) {
        dp[i] = dfs(i);
      }
      out << dfs(0).max_child_index_returned;
    }
  };

 public:
  void solve(std::istream &in, std::ostream &out) { Solver(in, out).solve(); }
};
int main() {
  std::ios_base::sync_with_stdio(false), cin.tie(0);
  DServalAndRootedTree solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

### Prompt

Generate a CPP solution to the following problem:

Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before. 

As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.

A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a node v is the last different from v vertex on the path from the root to the vertex v. Children of vertex v are all nodes for which v is the parent. A vertex is a leaf if it has no children.

The rooted tree Serval owns has n nodes, node 1 is the root. Serval will write some numbers into all nodes of the tree. However, there are some restrictions. Each of the nodes except leaves has an operation max or min written in it, indicating that the number in this node should be equal to the maximum or minimum of all the numbers in its sons, respectively. 

Assume that there are k leaves in the tree. Serval wants to put integers 1, 2, …, k to the k leaves (each number should be used exactly once). He loves large numbers, so he wants to maximize the number in the root. As his best friend, can you help him?

Input

The first line contains an integer n (2 ≤ n ≤ 3⋅ 10^5), the size of the tree.

The second line contains n integers, the i-th of them represents the operation in the node i. 0 represents min and 1 represents max. If the node is a leaf, there is still a number of 0 or 1, but you can ignore it.

The third line contains n-1 integers f_2, f_3, …, f_n (1 ≤ f_i ≤ i-1), where f_i represents the parent of the node i.

Output

Output one integer — the maximum possible number in the root of the tree.

Examples

Input


6
1 0 1 1 0 1
1 2 2 2 2


Output


1


Input


5
1 0 1 0 1
1 1 1 1


Output


4


Input


8
1 0 0 1 0 1 1 0
1 1 2 2 3 3 3


Output


4


Input


9
1 1 0 0 1 0 1 0 1
1 1 2 2 3 3 4 4


Output


5

Note

Pictures below explain the examples. The numbers written in the middle of the nodes are their indices, and the numbers written on the top are the numbers written in the nodes.

In the first example, no matter how you arrange the numbers, the answer is 1.

<image>

In the second example, no matter how you arrange the numbers, the answer is 4.

<image>

In the third example, one of the best solution to achieve 4 is to arrange 4 and 5 to nodes 4 and 5.

<image>

In the fourth example, the best solution is to arrange 5 to node 5.

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
namespace io {
class input_reader {
  std::istream &in;
  void throw_error() {
    throw std::runtime_error("No more inputs while reading number");
  }
  template <typename T>
  inline void readIntegerValue(T &f) {
    bool positive = true;
    f = 0;
    char c;
    if (!in.get(c)) throw_error();
    while (c < '0' || c > '9') {
      if (c == '-') positive = false;
      if (!in.get(c)) throw_error();
    }
    while (c >= '0' && c <= '9') {
      f = (f << 3) + (f << 1) + (c & 15);
      if (!in.get(c)) break;
    }
    if (!positive) f *= -1;
  }

 public:
  explicit input_reader(std::istream &in) : in(in) {}
  inline void read(int &f) { readIntegerValue(f); }
  inline void read(short &f) { readIntegerValue(f); }
  inline void read(long int &f) { readIntegerValue(f); }
  inline void read(long long int &f) { readIntegerValue(f); }
  inline void read(unsigned int &f) { readIntegerValue(f); }
  inline void read(unsigned short &f) { readIntegerValue(f); }
  inline void read(unsigned long int &f) { readIntegerValue(f); }
  inline void read(unsigned long long int &f) { readIntegerValue(f); }
  template <typename T>
  inline void read(std::vector<T> &f) {
    for (auto &i : f) read(i);
  }
  template <typename T, int N>
  inline void read(std::array<T, N> &res) {
    for (auto &i : res) read(i);
  }
  template <typename T1, typename T2>
  inline void read(std::pair<T1, T2> &p) {
    in.read(p.first, p.second);
  }
  template <typename T>
  inline void read(T &f) {
    in >> f;
  }
  template <typename T, typename... Args>
  inline void read(T &t, Args &...args) {
    read(t), read(args...);
  }
  template <typename T>
  inline void readArray(int n, T *res) {
    while (n--) read(*(res++));
  }
  template <typename T>
  inline input_reader &operator>>(T &t) {
    return read(t), *this;
  }
};
}  // namespace io
namespace io {
class output_writer {
  std::ostream &out;
  template <typename T>
  inline void printIntegerHelper(T x) {
    if (x >= 10) printIntegerHelper(x / 10);
    out.put(x % 10 + 48);
  }
  template <typename T>
  inline void printInteger(T x) {
    if (x < 0) out.put('-'), x = -x;
    printIntegerHelper(x);
  }
  template <typename T>
  inline void printArray(T &ar) {
    bool first = true;
    for (auto &t : ar) print((first) ? first = false, "" : " ", t);
  }

 public:
  explicit output_writer(std::ostream &out) : out(out) {}
  inline void flush() { out.flush(); }
  inline void print() {}
  inline void print(char x) { out.put(x); }
  inline void print(short x) { printInteger(x); }
  inline void print(int x) { printInteger(x); }
  inline void print(long int x) { printInteger(x); }
  inline void print(long long int x) { printInteger(x); }
  inline void print(unsigned short x) { printInteger(x); }
  inline void print(unsigned int x) { printInteger(x); }
  inline void print(unsigned long int x) { printInteger(x); }
  inline void print(unsigned long long int x) { printInteger(x); }
  template <typename T1>
  inline void print(const T1 &t1) {
    out << t1;
  }
  template <typename T1>
  inline void print(const std::vector<T1> &t1) {
    printArray(t1);
  }
  template <typename T1, int N>
  inline void print(const std::array<T1, N> &t1) {
    printArray(t1);
  }
  template <typename T1, int N, int M>
  inline void print(const std::array<std::array<T1, M>, N> &t1) {
    for (auto &t : t1) println(t);
  }
  template <typename T1>
  inline void print(const std::vector<std::vector<T1>> &t1) {
    for (auto &t : t1) println(t);
  }
  template <typename T, typename... Args>
  inline void print(const T &t, Args... args) {
    print(t), print(args...);
  }
  template <typename... Args>
  inline void println(Args... args) {
    print(args...), print('\n');
  }
  template <typename T>
  output_writer &operator<<(const T &t) {
    return print(t), *this;
  }
};
}  // namespace io
inline long long int pow_mod(const long long int a, const long long int b,
                             const long long int MOD) {
  if (b == 0) return 1;
  if (b == 1) return a % MOD;
  long long int res = pow_mod(a * a % MOD, b >> 1, MOD);
  if (b & 1) res = res * a % MOD;
  return res % MOD;
}
inline long long int mod_inv(const long long int a, const long long int MOD) {
  return pow_mod(a, MOD - 2, MOD);
}
template <typename T>
T gcd(const T &a, const T &b) {
  if (*a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T lcm(const T &a, const T &b) {
  assert(a != 0 && b != 0);
  return a / gcd(a, b) * b;
}
using namespace std;
class DServalAndRootedTree {
  class Solver {
    io::input_reader in;
    io::output_writer out;

   public:
    Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}
    int n;
    vector<int> op, p;
    vector<vector<int>> e;
    struct minimax {
      int count_children, max_child_index_returned;
    };
    vector<minimax> dp;
    minimax dfs(const int i) {
      if (e[i].empty()) return {1, 1};
      vector<minimax> mm;
      for (int j : e[i]) {
        mm.push_back(dp[j]);
      }
      int count = 0;
      for (auto j : mm) count += j.count_children;
      int best;
      if (op[i]) {
        best = 0;
        for (auto j : mm)
          best =
              max(best, count - j.count_children + j.max_child_index_returned);
      } else {
        best = 0;
        int sum = 0;
        for (auto j : mm) {
          sum += j.count_children - j.max_child_index_returned + 1;
        }
        for (auto j : mm) {
          best = max(best, count -
                               (sum - (j.count_children -
                                       j.max_child_index_returned + 1)) -
                               (j.count_children - j.max_child_index_returned));
        }
      }
      return {count, best};
    }
    void solve() {
      in >> n;
      op.resize(n), p.resize(n - 1), dp.resize(n);
      in >> op >> p;
      e.resize(n);
      for (int i = 0; i < n - 1; i++) {
        int pp = p[i];
        e[pp - 1].push_back(i + 1);
      }
      vector<int> bfs;
      {
        int i = 0;
        bfs.push_back(0);
        while (i < n) {
          int cur = bfs[i++];
          for (int j : e[cur]) bfs.push_back(j);
        }
      }
      reverse((bfs).begin(), (bfs).end());
      for (int i : bfs) {
        dp[i] = dfs(i);
      }
      out << dfs(0).max_child_index_returned;
    }
  };

 public:
  void solve(std::istream &in, std::ostream &out) { Solver(in, out).solve(); }
};
int main() {
  std::ios_base::sync_with_stdio(false), cin.tie(0);
  DServalAndRootedTree solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

```