404692: GYM101611 C Carpet

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Carpettime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

All cinema stars of Treeland are gathering in its capital to take part in the cinema academy award ceremony. This time organizers decided to prepare something very new for the welcoming part. Their idea is to replace old-fashioned red carpet with a one having a map of Treeland depicted on it.

Treeland consists of n cities connected with n - 1 bidirectional roads in such a way that it is possible to get from any city to any other city. Let us represent the carpet as a rectangular grid of 1 000 000 × 20 unit square cells. Cities should be painted in centers of some cells in such a way that no two cities occupy the same cell. After that roads are painted as segments connecting corresponding cell centers.

To make the carpet beautiful, it was decided to place cities in such a way that no two segments corresponding to roads intersect. This means that no two segments have common points different from their common endpoints.

Some clever mathematician already proved that a solution exists, but unfortunately his proof doesn't provide a way to construct the answer, so this task was assigned to you.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cities in Treeland.

Each of the next n - 1 lines contains a pair of integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — indices of a road that connects cities ui and vi. It is guaranteed that it is possible to get from any city to any other city.

Output

Print n lines. The i-th of these lines should contain two integers xi and yi (1 ≤ xi ≤ 1 000 000, 1 ≤ yi ≤ 20) — the coordinates of the cell to place the i-th city.

ExamplesInput
6
1 2
1 3
1 4
4 5
4 6
Output
2 2
1 1
1 3
3 2
4 3
4 1
Input
7
1 2
1 3
2 4
2 5
3 6
3 7
Output
1 1
1 2
2 2
1 3
2 3
3 3
4 3
Note

The picture below illustrates a possible solution for the first sample.

加入题单

上一题 下一题 算法标签: