Bureaucracy

Simulate repeatedly sending a task down the smallest-numbered child on each root-to-leaf path, paying 1,2,3,... coins up the chain, and deleting the leaf.

Hard8TreeDFSSimulationBrute forceNo attempts yetTime limit1sMemory limit64 MB

Problem

Mirko is now the CEO of a huge corporation. The corporation has NN people, numbered 11 to NN, and Mirko is number 11. Everyone except Mirko has exactly one boss, and we call that person an assistant of the boss. A boss can have several assistants and still reports to their own boss. Mirko is the exception. He sits at the top of the pyramid, so he has no boss, only assistants.

When the investors give Mirko a task, he passes it to his assistant with the smallest number. That assistant passes it to their own assistant with the smallest number, and this repeats until the task reaches somebody with no assistants. That person does the work.

This is where the real problem starts. The person who did the task gets 11 coin, that person's boss gets 22 coins, the boss of that boss gets 33 coins, and so on up to Mirko, who gets as many coins as there are people in the chain. After the payout, the employee who actually did the work decides the system is unfair and quits.

The next task is handled with one person fewer in the corporation, so the payouts can be smaller, but the work must go on. Tasks keep piling up, so the whole procedure (assigning a task, doing it, splitting the coins, and losing the worker) repeats until Mirko is alone and does his first and last task himself.

Mirko will have collected a fortune by then, and he also wants to know how much every employee earned.

Input

The first line contains the integer NN (2N2000002 \le N \le 200000), the number of employees including Mirko.

The second line contains N1N - 1 integers a2,a3,,aNa_2, a_3, \dots, a_N (1ai<i1 \le a_i < i), where aia_i is the number of the boss of employee ii.

Output

Print one line with NN numbers separated by single spaces. The iith number is the total number of coins employee ii earns.

Hint

Follow the sample with N=5N = 5. Mirko gives the first task to employee 22, who gives it to employee 33, who does the work. Employee 33 gets 11 coin, employee 22 gets 22 coins, and employee 11 (Mirko) gets 33 coins. Employee 33 then quits.

Mirko gives the second task to employee 22 again. Employee 33 is gone, so employee 22 passes it to employee 44, who passes it to employee 55, who does the work. Employee 55 gets 11 coin, employee 44 gets 22 coins, employee 22 gets 33 coins, and employee 11 gets 44 coins. Employee 55 then quits.

The procedure runs for 55 tasks in total. Mirko ends up with 1313 coins, employee 22 with 88, employee 44 with 33, and employees 33 and 55 with 11 coin each.