Software Package Manager

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You'd like to design a package manager on your own, and thus you'd like to resolve the dependency problem among packages. If package AA depends on package BB, then we must install package BB before package AA. Likewise, if we'd like to remove package BB, we also need to remove package AA. You know the dependency relations among the packages, and you may assume all packages other than package 00 will rely on exactly one package (package 00 does not rely on any other packages). There are no cycles in the dependency relation (like A_1A\_1 depends on A_2A\_2A_2A\_2 depends on A_3A\_3, …, A_m_1A\_{m\_1} depends on A_mA\_m but A_mA\_m depends on A_1A\_1), and of course no package depends on itself.

Now you'd like to know how many packages have their status changed upon installing or uninstalling a given package. Notice installing an installed package or uninstalling an uninstalled package will not change the status of any package.

입력

The first line of the input is an integer nn representing the number of packages. The packages are numbered beginning with 00.

The next line has n1n-1 integers separated by a single space, representing the package that package 1,2,,n2,n11, 2, \dots, n-2, n-1 depends on.

The next line contains an integer qq representing the number of queries. In the following qq lines, each line contains a query of form install x or uninstall x representing installing or uninstalling package xx. You need to maintain the status of each package. Initially, all packages are uninstalled. You need to output how many packages will change the status after the step, and then apply the (un)installation.

출력

The output consists of qq lines. The ii-th line is an integer representing the number of packages whose status change at step ii.

제한

  • 7 n100,0007 ≤ n ≤ 100\\,000
  • 5 q100,0005 ≤ q ≤ 100\\,000