Salaries

No attempts yetTime limit1sMemory limit128 MB

Problem

A company has nn 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 11 to nn. 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.

Input

The first line contains an integer nn (1n1061 \le n \le 10^6), the number of employees, numbered from 11 to nn.

Each of the next nn lines describes one employee. Line i+1i+1 contains two integers pip_i and ziz_i (1pin1 \le p_i \le n, 0zin0 \le z_i \le n). Here pip_i is the id of employee ii's direct supervisor; if pi=ip_i = i then employee ii is the CEO. If zi>0z_i > 0 it is the disclosed salary of employee ii; if zi=0z_i = 0 the salary of employee ii is not disclosed. All positive values ziz_i are pairwise distinct.

The input is always consistent: at least one salary assignment agrees with both the hierarchy and the disclosed values.

Output

Print nn lines. On line ii print employee ii's salary if it is disclosed or can be uniquely inferred from the disclosed salaries; otherwise print 00.