Corporate life after a hostile takeover

Given two rooted trees on the same n employees, count for each employee how many others are descendants in both trees.

Hard8TreeDFSPrefix sumSortingNo attempts yetTime limit0.5sMemory limit1024 MB

Problem

JanuszPol is a Polish company with a long tradition. Its finances recently turned bad, and a foreign competitor took it over. The new board decided to rebuild the company organization from scratch. Until now the structure was a plain tree.

  • Exactly one executive director has no superior.
  • Every other employee has exactly one direct superior, and there are no cyclic relations.

Employee yy is a subordinate of employee xx if yy sits below xx in the tree, that is, if following direct superiors upward from yy reaches xx.

After the takeover the company employs the same people and stays organized as a tree, but every employee receives a different position, so the shape of the tree may change completely. The executive director keeps the position. Right now nobody dares to give orders to anyone else, because a subordinate may become a superior at any moment.

You are given the tree before the takeover and the tree after it. For every employee xx, determine how many people were subordinates of xx before and remain subordinates of xx after.

Input

The first line contains an integer nn (2n2000002 \leq n \leq 200\,000), the number of employees. Employees are numbered from 11 to nn, and employee 11 is the executive director. The second line describes the structure before the takeover with n1n-1 numbers a2,a3,,ana_2, a_3, \ldots, a_n, where aia_i is the number of the superior of employee ii. The third line contains n1n-1 numbers b2,b3,,bnb_2, b_3, \ldots, b_n, where bib_i is the superior of employee ii after the takeover. Both descriptions define a proper tree rooted at 11.

Output

Print one line with nn numbers separated by spaces. The ii-th of them is the number of people who are subordinates of employee ii in both trees at once.