A company has n employees arranged in a strict hierarchy. Every employee except the CEO has exactly one direct supervisor, and the CEO is the (direct or indirect) supervisor of everyone else. Each employee earns a distinct monthly salary, and these salaries are exactly the integers from 1 to n. Every supervisor earns strictly more than each of their subordinates.
Some salaries are publicly disclosed. By law, whenever an employee's salary is disclosed, the salary of their direct supervisor is disclosed as well.
Determine every salary that is not disclosed but is nonetheless uniquely determined by the disclosed salaries together with the hierarchy.
The first line contains an integer n (1≤n≤106), the number of employees, numbered from 1 to n.
Each of the next n lines describes one employee. Line i+1 contains two integers pi and zi (1≤pi≤n, 0≤zi≤n). Here pi is the id of employee i's direct supervisor; if pi=i then employee i is the CEO. If zi>0 it is the disclosed salary of employee i; if zi=0 the salary of employee i is not disclosed. All positive values zi are pairwise distinct.
The input is always consistent: at least one salary assignment agrees with both the hierarchy and the disclosed values.
Print n lines. On line i print employee i's salary if it is disclosed or can be uniquely inferred from the disclosed salaries; otherwise print 0.