Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.  [Image] 

The tree is a non-oriented connected graph without cycles. In particular, there always are n - 1 edges in a tree with n vertices.

The puzzle is to position the vertices at the points of the Cartesian plane with integral coordinates, so that the segments between the vertices connected by edges are parallel to the coordinate axes. Also, the intersection of segments is allowed only at their ends. Distinct vertices should be placed at different points. 

Help Dasha to find any suitable way to position the tree vertices on the plane.

It is guaranteed that if it is possible to position the tree vertices on the plane without violating the condition which is given above, then you can do it by using points with integral coordinates which don't exceed 10^18 in absolute value.


-----Input-----

The first line contains single integer n (1 ≤ n ≤ 30) — the number of vertices in the tree. 

Each of next n - 1 lines contains two integers u_{i}, v_{i} (1 ≤ u_{i}, v_{i} ≤ n) that mean that the i-th edge of the tree connects vertices u_{i} and v_{i}.

It is guaranteed that the described graph is a tree.


-----Output-----

If the puzzle doesn't have a solution then in the only line print "NO".

Otherwise, the first line should contain "YES". The next n lines should contain the pair of integers x_{i}, y_{i} (|x_{i}|, |y_{i}| ≤ 10^18) — the coordinates of the point which corresponds to the i-th vertex of the tree.

If there are several solutions, print any of them. 


-----Examples-----
Input
7
1 2
1 3
2 4
2 5
3 6
3 7
Output
YES
0 0
1 0
0 1
2 0
1 -1
-1 1
0 2
Input
6
1 2
2 3
2 4
2 5
2 6

Output
NO

Input
4
1 2
2 3
3 4
Output
YES
3 3
4 3
5 3
6 3


-----Note-----

In the first sample one of the possible positions of tree is: [Image]

Difficulty: interview

Starter code:

Solutions:
def dfs(v, x, y, t, l, pr):
    ans[v] = x, y
    nx = [(l, 0), (0, -l), (-l, 0), (0, l)]
    if t == 0: p = 0, 1, 3
    if t == 1: p = 0, 1, 2
    if t == 2: p = 1, 2, 3
    if t == 3: p = 0, 2, 3
    listv = [u for u in g[v] if u != pr]
    g[v] = listv[:]
    for i in range(min(len(p), len(g[v]))):
        dx = nx[p[i]][0]
        dy = nx[p[i]][1]
        newx = x + dx
        newy = y + dy
        u = g[v][i]
        dfs(u, newx, newy, p[i], l // 4, v)

read = lambda: map(int, input().split())
n = int(input())
g = [list() for i in range(n + 1)]
for i in range(n - 1):
    u, v = read()
    g[u].append(v)
    g[v].append(u)
def fail():
    print('NO')
    return
root = 1
for i in range(n + 1):
    if len(g[i]) > 4:
        fail()
    if len(g[i]) > len(g[root]):
        root = i
ans = [0] * (n + 1)
ans[root] = (0, 0)
inf = 10 ** 18
l = inf // 4
nx = [(l, 0), (0, -l), (-l, 0), (0, l)]
for i in range(len(g[root])):
    dx = nx[i][0]
    dy = nx[i][1]
    newx = 0 + dx
    newy = 0 + dy    
    dfs(g[root][i], newx, newy, i, l // 4, root)
print('YES')
[print(*i) for i in ans[1:]]

def main():
	n = int(input())
	graph = [[] for i in range(n)]
	ans = [(0,0)] * n
	
	for _ in range(n - 1):
		u, v = [int(el) for el in input().split()]
		u -= 1
		v -= 1
		graph[u].append(v)
		graph[v].append(u)
	
	for l in graph:
		if len(l) > 4:
			print('NO')
			return
	
	step = 1 << 28
	
	used = [False] * n
	def dfs(v, direction, step, koord):
		used[v] = True
		if direction == 'u':
			my_koord = (koord[0] + step, koord[1])
			dirs = ['u', 'l', 'r']
		elif direction == 'd':
			my_koord = (koord[0] - step, koord[1])
			dirs = ['d', 'l', 'r']
		elif direction == 'l':
			my_koord = (koord[0], koord[1] - step)
			dirs = ['u', 'd', 'l']
		elif direction == 'r':
			my_koord = (koord[0], koord[1] + step)
			dirs = ['u', 'd', 'r']
		elif direction == '':
			my_koord = (0, 0)
			dirs = ['u', 'd', 'l', 'r']
		
		ans[v] = my_koord
		
		d = 0
		for u in graph[v]:
			if not used[u]:
				dfs(u, dirs[d], step >> 1, my_koord)
				d += 1
	
	dfs(0, '', step, (0, 0))
	
	print('YES')
	for k in ans:
		print(k[0], k[1])
	
main()

def dfs(v, x, y, t, l, pr):
    ans[v] = x, y
    p = [(0, 1, 3), (0, 1, 2), (1, 2, 3), (0, 2, 3)][t]
    g[v] = [u for u in g[v] if u != pr]
    for i in range(min(len(p), len(g[v]))):
        newx = x + nx[p[i]][0] * l
        newy = y + nx[p[i]][1] * l
        dfs(g[v][i], newx, newy, p[i], l // 4, v)

read = lambda: map(int, input().split())
n = int(input())
g = [list() for i in range(n + 1)]
for i in range(n - 1):
    u, v = read()
    g[u].append(v)
    g[v].append(u)
root = 1
for i in range(n + 1):
    if len(g[i]) > 4:
        print('NO')
        return
ans = [0] * (n + 1)
ans[root] = 0, 0
inf = 10 ** 18
l = inf // 4
nx = (1, 0), (0, -1), (-1, 0), (0, 1)
for i in range(len(g[root])):
    dfs(g[root][i], nx[i][0] * l, nx[i][1] * l, i, l // 4, root)
print('YES')
[print(*i) for i in ans[1:]]

def dfs(v, x, y, t, l, pr):
    ans[v] = x, y
    p = [(0, 1, 3), (0, 1, 2), (1, 2, 3), (0, 2, 3)][t]
    g[v] = [u for u in g[v] if u != pr]
    for i in range(min(len(p), len(g[v]))):
        newx = x + nx[p[i]][0] * l
        newy = y + nx[p[i]][1] * l
        dfs(g[v][i], newx, newy, p[i], l // 4, v)

read = lambda: map(int, input().split())
n = int(input())
g = [list() for i in range(n + 1)]
for i in range(n - 1):
    u, v = read()
    g[u].append(v)
    g[v].append(u)
root = 1
for i in range(n + 1):
    if len(g[i]) > 4:
        print('NO')
        return
ans = [0] * (n + 1)
ans[root] = 0, 0
inf = 10 ** 18
l = inf // 4
nx = (1, 0), (0, -1), (-1, 0), (0, 1)
for i in range(len(g[root])):
    dfs(g[root][i], nx[i][0] * l, nx[i][1] * l, i, l // 4, root)
print('YES')
[print(*i) for i in ans[1:]]

#!/usr/bin/env python3
from collections import *
def ri():
    return list(map(int, input().split()))


d = [[1,0], [0, 1], [-1, 0], [0, -1]]

def bfs(s, adj, v, l):
    if v[s] == 1:
        return 0
    q = deque()
    q.append(s)
    v[s] = 1
    while q:
        n = q.popleft()
        for a in adj[n]:
            if v[a] == 0:
                for i in range(4):
                    if dv[n][i] == 0:
                        dv[n][i] = 1
                        break
                pos[a][0] = pos[n][0] + d[i][0]*2**(31-l[n])
                pos[a][1] = pos[n][1] + d[i][1]*2**(31-l[n])
                if i == 0:
                    dv[a][2] = 1
                elif i == 1:
                    dv[a][3] = 1
                elif i == 2:
                    dv[a][0] = 1
                elif i == 3:
                    dv[a][1] = 1
                l[a] = l[n] + 1
                q.append(a)
                v[a] = 1


n = int(input())
adj = [set() for i in range(n)]
v = [0 for i in range(n)]
l = [0 for i in range(n)]
dv = [[0,0,0,0] for i in range(n)]
pos = [[0, 0] for i in range(n)]

for i in range(n-1):
    a, b = ri()
    a -= 1
    b -= 1
    adj[a].add(b)
    adj[b].add(a)

for i in range(n):
    if len(adj[i]) > 4:
        print("NO")
        return

bfs(0, adj, v, l)

print("YES")
for i in range(n):
    print(pos[i][0], pos[i][1])



n = int(input())
p = [set() for i in range(n)]
for k in range(n - 1):
    u, v = map(int, input().split())
    p[u - 1].add(v - 1)
    p[v - 1].add(u - 1)

s = [(0, 0)] * n
t = [(0, 1 << 30, 7)]
l = [1, 0, -1, 0, 1]

while t:
    u, d, j = t.pop()
    x, y = s[u]
    i = 0
    for v in p[u]:
        if i == j: i += 1
        if i > 3: print('NO');return
        p[v].remove(u)
        s[v] = (x + l[i] * d, y + l[i + 1] * d)
        t.append((v, d >> 1, (i + 2) % 4))
        i += 1

print('YES')
for x, y in s: print(x, y)

from collections import deque

n = int(input())
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
gr = [[] for i in range(n)]

for i in range(n - 1):
    a, b = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    gr[a].append(b)
    gr[b].append(a)
for i in range(n):
    if len(gr[i]) > 4:
        print("NO")
        return
print("YES")
d = deque()
d.append((0, 10 ** 18 // 2, 10 ** 18 // 2, -1, -1, 50))
ans = [0] * n
while len(d) > 0:
    v = d[0][0]
    x = d[0][1]
    y = d[0][2]
    ans[v] = (d[0][1], d[0][2])
    p = d[0][4]
    dr = d[0][3]
    pw = d[0][5]
    d.popleft()
    if p != -1:
        gr[v].pop(gr[v].index(p))
    cur = 0
    for i in range(4):
        if i == dr:
            continue
        if cur == len(gr[v]):
            break
        ngh = gr[v][cur]
        d.append((ngh, x + 2 ** pw * dx[i], y + 2 ** pw * dy[i], (i + 2) % 4, v, pw - 1))
        cur += 1
for i in ans:
    print(*i)

n = int(input())
adj = [[] for _ in range(n)]

for _ in range(n - 1):
    u, v = list(map(int, input().split()))
    adj[u - 1].append(v - 1)
    adj[v - 1].append(u - 1)

from collections import deque
def bfs(v):
    vis = [i == v for i in range(n)]
    paths = deque([[v]])

    while paths:
        p = paths.popleft()
        for nv in adj[p[-1]]:
            if not vis[nv]:
                vis[nv] = True
                paths.append(p + [nv]) 

    return p

diameter = bfs(0)
diameter = bfs(diameter[-1])
p = diameter[len(diameter) // 2]

start = (0, 0)
move = [(0, 1), (1, 0), (0, -1), (-1, 0)]
gpt = lambda pt, i, dis : (pt[0] + move[i][0] * dis, pt[1] + move[i][1] * dis)

vis = [False] * n
dis = 2 ** (len(diameter) + 1)

ans = [0] * n
q = deque([(p, start, -1, dis)])

while q:
    p, start, dr, dis = q.popleft()
    vis[p] = True
    ans[p] = start

    if len(adj[p]) > 4:
        print("NO")
        return
    
    if dr == -1:
        drs = [i for i in range(4)]
    else:
        drs = [i for i in range(4) if gpt(move[i], dr, 1) != (0, 0)]

    for nv in adj[p]:       
        if not vis[nv]:
            vis[nv], dr = True, drs.pop()
            npt = gpt(start, dr, dis)
            q.append((nv, npt, dr, dis // 2))
            ans[nv] = npt

print("YES")
for pt in ans:
    print(*pt)





#https://codeforces.com/problemset/problem/761/E
def solve():
    def push(u, v, g):
        if u not in g:
            g[u] = []
        if v not in g:
            g[v] = []    
        g[u].append(v)
        g[v].append(u)
        
    n = int(input())
    g = {}
    
    for _ in range(n-1):
        u, v = map(int, input().split())
        push(u, v, g)
    
    for u in g:
        if len(g[u]) > 4:
            return 'NO', None
    d = {}    
    build(1, 0, 0, 0, 31, -1, d, g)
    s = ''
    for u in range(1, n+1):
        x, y = d[u]
        s += str(x) + ' ' + str(y)
        s += '\n'
    return 'YES', s

def cal_pos(dir_, cur_x, cur_y, cur_base):
    if dir_   == 0:
        return cur_x, cur_y + (1<<cur_base)
    elif dir_ == 1:
        return cur_x + (1<<cur_base), cur_y
    elif dir_ == 2:
        return cur_x, cur_y - (1<<cur_base)
    else:
        return cur_x - (1<<cur_base), cur_y
        
def build(u, p, cur_x, cur_y, cur_base, pre_dir, d, g):
    d[u]  = [cur_x, cur_y]
    type_ = [0,1,2,3]
        
    if pre_dir in type_:
        type_.remove(pre_dir)
    
    if u in g:
        for v in g[u]:
            if v != p:
                dir_ = type_.pop() 
                
                next_x, next_y =  cal_pos(dir_, cur_x, cur_y, cur_base)    
                build(v, u, next_x, next_y, cur_base-1, (dir_ - 2)%4, d, g)
                
ans ,s = solve()
if ans == 'NO':
    print(ans)
else:    
    print(ans)
    print(s)