Problem:
 Score : 600 points    Problem Statement Snuke is introducing a robot arm with the following properties to his factory:   The robot arm consists of m  sections and m+1  joints . The sections are numbered 1 , 2 , ..., m , and the joints are numbered 0 , 1 , ..., m . Section i connects Joint i-1 and Joint i . The length of Section i is d_i .  For each section, its mode can be specified individually. There are four modes: L , R , D and U . The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint i will be determined as follows (we denote its coordinates as (x_i, y_i) ):  (x_0, y_0) = (0, 0) .  If the mode of Section i is L , (x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1}) .  If the mode of Section i is R , (x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1}) .  If the mode of Section i is D , (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i}) .  If the mode of Section i is U , (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i}) .     Snuke would like to introduce a robot arm so that the position of Joint m can be matched with all of the N points (X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N) by properly specifying the modes of the sections.
Is this possible?
If so, find such a robot arm and how to bring Joint m to each point (X_j, Y_j) .      Constraints  All values in input are integers.  1 \leq N \leq 1000  -10^9 \leq X_i \leq 10^9  -10^9 \leq Y_i \leq 10^9       Partial Score  In the test cases worth 300 points, -10 \leq X_i \leq 10 and -10 \leq Y_i \leq 10 hold.         Input Input is given from Standard Input in the following format:  N  X_1  Y_1  X_2  Y_2  :  X_N  Y_N       Output If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print -1 .  m  d_1  d_2  ...  d_m  w_1  w_2  :  w_N   m and d_i are the configurations of the robot arm. Refer to the problem statement for what each of them means.
Here, 1 \leq m \leq 40 and 1 \leq d_i \leq 10^{12} must hold. Also, m and d_i must all be integers.  w_j is a string of length m that represents the way to bring Joint m of the robot arm to point (X_j, Y_j) .
The i -th character of w_j should be one of the letters L , R , D and U , representing the mode of Section i .        Sample Input 1 3
-1 0
0 3
2 -1      Sample Output 1 2
1 2
RL
UU
DR  In the given way to bring Joint m of the robot arm to each (X_j, Y_j) , the positions of the joints will be as follows:   To (X_1, Y_1) = (-1, 0) : First, the position of Joint 0 is (x_0, y_0) = (0, 0) . As the mode of Section 1 is R , the position of Joint 1 is (x_1, y_1) = (1, 0) . Then, as the mode of Section 2 is L , the position of Joint 2 is (x_2, y_2) = (-1, 0) .  To (X_2, Y_2) = (0, 3) : (x_0, y_0) = (0, 0), (x_1, y_1) = (0, 1), (x_2, y_2) = (0, 3) .  To (X_3, Y_3) = (2, -1) : (x_0, y_0) = (0, 0), (x_1, y_1) = (0, -1), (x_2, y_2) = (2, -1) .        Sample Input 2 5
0 0
1 0
2 0
3 0
4 0      Sample Output 2 -1       Sample Input 3 2
1 1
1 1      Sample Output 3 2
1 1
RU
UR  There may be duplicated points among (X_j, Y_j) .       Sample Input 4 3
-7 -3
7 3
-3 -7      Sample Output 4 5
3 1 4 1 5
LRDUL
RDULR
DULRD

Solution (Python):
def solve(xy):
    p = False
    if all([(x+y)%2==0 for x,y in xy]):
        p = True
    elif all([(x+y)%2==1 for x,y in xy]):
        pass
    else:
        print(-1)
        return
    m = [2**i for i  in range(30,-1,-1)]
    if p:
        m.append(1)
    anses = []
    for x,y in xy:
        usum, vsum = (0, 0)
        ans = []
        u = x+y
        v = x-y
        anses.append(ans)
        for d in m:
            if usum <= u:
                usum += d
                if vsum <= v:
                    vsum += d
                    ans.append('R')
                else:
                    vsum -= d
                    ans.append('U')
            else:
                usum -= d
                if vsum <= v:
                    vsum += d
                    ans.append('D')
                else:
                    vsum -= d
                    ans.append('L')
    print(len(m))
    print(" ".join([str(i) for i in m]))
    for a in anses:
        print("".join(a))


def main():
    n = int(input())
    xy = []
    for i in range(n):
        xy.append([int(i) for i in input().split()])
    solve(xy)

if __name__ == '__main__':
    main()

Solution (Python):
n = input()
x = []
y = []
for i in range(n):
	a, b = map(int, raw_input().split())
	x.append(a)
	y.append(b)
for i in range(n):
	if (x[0] + y[0]) % 2 != (x[i] + y[i]) % 2:
		print -1
		exit()
d = [1 << i for i in range(32)][::-1]
if (x[0] + y[0]) % 2 == 0:
	d.append(1)

print len(d)
for i in d:
	print i,
print
for i in range(n):
	s = ''
	for j in d:
		if abs(x[i]) > abs(y[i]):
			if x[i] > 0:
				x[i] -= j
				s += 'R'
			else:
				x[i] += j
				s += 'L'
		else:
			if y[i] > 0:
				y[i] -= j
				s += 'U'
			else:
				y[i] += j
				s += 'D'
	print s

Solution (Python):
import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(a,b):
    pas=''
    s=a[::-1]
    t=b[::-1]
    A=[0]*31
    B=[0]*31
    for i in range(len(s)):
        if s[i]=='1':
            A[i]=1
    for i in range(len(t)):
        if t[i]=='1':
            B[i]=1
    n=31
    for i in range(n):
        if A[i]==0 and B[i]==0:
            pas+='L'
        if A[i]==0 and B[i]==1:
            pas+='D'
        if A[i]==1 and B[i]==0:
            pas+='U'
        if A[i]==1 and B[i]==1:
            pas+='R'
        
    return pas
if L[0]==1:
    m=32
    d=[1]+[pow(2,i) for i in range(31)]
    ans=[]
    S=[]
    for x,y in table:
        S.append((x-1,y))
    for x,y in S:
        a='R'
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)       
else:
    m=31
    d=[pow(2,i) for i in range(31)]
    ans=[]
    S=table
    for x,y in S:
        a=''
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)      

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)

Solution (Python):
import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(a,b):
    pas=''
    s=a[::-1]
    t=b[::-1]
    A=[0]*31
    B=[0]*31
    for i in range(len(s)):
        if s[i]=='1':
            A[i]=1
    for i in range(len(t)):
        if t[i]=='1':
            B[i]=1
    n=31
    for i in range(n):
        if A[i]==0 and B[i]==0:
            pas+='L'
        if A[i]==0 and B[i]==1:
            pas+='D'
        if A[i]==1 and B[i]==0:
            pas+='U'
        if A[i]==1 and B[i]==1:
            pas+='R'
        
    return pas
if L[0]==1:
    m=32
    d=[1]+[pow(2,i) for i in range(31)]
    ans=[]
    S=[]
    for x,y in table:
        S.append((x-1,y))
    for x,y in S:
        a='R'
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)       
else:
    m=31
    d=[pow(2,i) for i in range(31)]
    ans=[]
    S=table
    for x,y in S:
        a=''
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)      

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)

Solution (Python):
def solve(queries):
    converted = [(x + y, x - y) for x, y in queries]
    oddeven = converted[0][0] % 2
    if any(q[0] % 2 != oddeven for q in converted):
        print(-1)
        return
    arms = [1 << i for i in range(35)]
    arms.reverse()
    if oddeven == 0:
        arms.append(1)

    buf = []
    for u, v in converted:
        tmp = []
        for d in arms:
            dx, dy = u >= 0, v >= 0
            if dx:
                u -= d
                if dy:
                    tmp.append('R')
                    v -= d
                else:
                    tmp.append('U')
                    v += d
            else:
                u += d
                if dy:
                    tmp.append('D')
                    v -= d
                else:
                    tmp.append('L')
                    v += d
        buf.append(''.join(tmp))
        
    print(len(arms))
    print(*arms)
    print('\n'.join(buf))


def check(s, arms):
    x, y = 0, 0
    for c, d in zip(s, arms):
        dx, dy = [(d, 0), (-d, 0), (0, d), (0, -d)]['RLUD'.index(c)]
        x += dx
        y += dy
    print(x, y)


n = int(input())
queries = [tuple(map(int, input().split())) for i in range(n)]
solve(queries)

Solution (Python):

from sys import stdin

s_in = lambda: stdin.readline()[:-1] 
d_in = lambda: int(stdin.readline()) 
ds_in = lambda: list(map(int, stdin.readline().split())) 

N = d_in()
rotated = []
for _ in range(N):
    x, y = ds_in()
    u = x + y
    v = x - y
    rotated.append([u, v])

Mod = rotated[0][0] % 2
for r in rotated:
    if r[0] % 2 != Mod:
        print(-1)
        exit()
    


if Mod == 1:
    m = 31
else:
    m = 32
print(m)
d_list = [str(2 ** i) for i in range(0, m-1+Mod)]
if Mod == 0:
    d_list.insert(0, str(1))
print(' '.join(d_list))

for r in rotated:
    ans_u = bin((r[0] + 2**31 - Mod) // 2)[2:]
    ans_v = bin((r[1] + 2**31 - Mod) // 2)[2:]

    if len(ans_u) < m - 1 + Mod:
        ans_u = '0' * (m-1+Mod - len(ans_u)) + ans_u
    if len(ans_v) < m - 1 + Mod:
        ans_v = '0' * (m-1+Mod - len(ans_v)) + ans_v

    if Mod == 1:
        w = ''
    else:
        w = 'L'
    for i, j in zip(ans_u[::-1], ans_v[::-1]):
        if i == '0' and j == '0':
            w += 'L'
        elif i == '0' and j == '1':
            w += 'D'
        elif i == '1' and j == '0':
            w += 'U'
        else:
            w += 'R'
    print(w)

Solution (Python):
N = int(input())
xyList = [[int(i) for i in input().split()] for _ in range(N)]

def culcNumList(num):
    numList = [1]
    lastNum = 2
    while(True):
        if lastNum >= num:
            return numList
        numList.append(lastNum)
        lastNum *= 2

max_sum = 0
oddFlag = False
evenFlag = False
for xy in xyList:
    sum_xy = sum(xy)
    max_sum = max(sum_xy, max_sum)
    if sum_xy % 2 == 0: evenFlag = True
    else: oddFlag = True

if oddFlag and evenFlag:
    print(-1)
else:
    d = culcNumList(max_sum)[::-1]
    if evenFlag: d.append(1)
    print(len(d))
    print(" ".join([str(s) for s in d]))

    for xy in xyList:
        nowX, nowY = 0, 0
        ans = ""
        for arm in d:
            if abs(nowX - xy[0]) >= abs(nowY - xy[1]):
                if nowX > xy[0]:
                    ans += "L"
                    nowX -= arm
                else:
                    ans += "R"
                    nowX += arm
            else:
                if nowY > xy[1]:
                    ans += "D"
                    nowY -= arm
                else:
                    ans += "U"
                    nowY += arm
        print(ans)

Solution (Python):
N = int(input())
qs = [tuple(map(int,input().split())) for i in range(N)]
parity = sum(qs[0])%2
for x,y in qs[1:]:
    if (x+y)%2 != parity:
        print(-1)
        exit()

arms = [1]
if not parity:
    arms.append(1)
while arms[-1] < 2*10**9:
    arms.append(arms[-1] * 2)
arms.reverse()

dirs = {'L':(1,0), 'R':(-1,0), 'D':(0,1), 'U':(0,-1)}
ans = []
for x,y in qs:
    command = ''
    for a in arms:
        dist = abs(x) + abs(y)
        best_c = None
        best_gain = -10**10
        for c,(dx,dy) in dirs.items():
            newdist = abs(x+ dx*a) + abs(y+ dy*a)
            gain = dist - newdist
            if gain > best_gain:
                best_gain = gain
                best_c = c
        command += best_c
        dx,dy = dirs[best_c]
        x += dx*a
        y += dy*a
    ans.append(command)

print(len(arms))
print(*arms)
print(*ans, sep='\n')

Solution (Python):


import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A):
    par = abs(A[0][0] + A[0][1]) % 2
    for (x, y) in A:
        if abs(x + y) % 2 != par:
            return None

    M = [2 ** i for i in range(31, -1, -1)]
    if par == 0:
        M.append(1)
    S = []

    for x, y in A:
        u = x + y
        v = x - y
        if par == 0:
            u += 1
            v += 1

        s = []
        for i in range(32):
            if u > 0:
                uv = 1
                u -= M[i]
            else:
                uv = -1
                u += M[i]

            if v > 0:
                vv = 1
                v -= M[i]
            else:
                vv = -1
                v += M[i]

            if (uv, vv) == (-1, -1):
                s.append('L')
            elif (uv, vv) == (1, 1):
                s.append('R')
            elif (uv, vv) == (-1, 1):
                s.append('D')
            else:
                s.append('U')

        assert u == 0
        assert v == 0

        if par == 0:
            s.append('L')

        S.append(''.join(s))

    return (M, S)



def main():
    N = int(inp())
    A = []
    for _ in range(N):
        x, y = [int(e) for e in inp().split()]
        A.append((x, y))

    ans = solve(N, A)
    if ans is None:
        print('-1')
        return

    m, s = ans
    print(len(m))
    print(*m)
    for t in s:
        print(t)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X,Y = [],[]
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)


p = set()
for i in range(N):
    p.add((X[i]+Y[i])%2)


if len(p)>1:
    print(-1)
    exit()


if 0 in p:
    for i in range(N):
        X[i] -= 1


D = []
for i in range(35):
    D.append(2**i)
D.sort(reverse=True)

Ans = []

for i in range(N):
    x,y = X[i],Y[i]
    x0,y0 = 0,0
    ans = ""
    for d in D:
        tx,ty = x-x0,y-y0
        if ty<tx and ty>-tx:
            ans += "R"
            x0 += d
        elif ty<tx and ty<-tx:
            ans += "D"
            y0 -= d
        elif ty>tx and ty<-tx:
            ans += "L"
            x0 -= d
        else:
            ans += "U"
            y0 += d
    Ans.append(ans)


if 0 in p:
    D.append(1)
    print(len(D))
    print(" ".join(map(str,D)))
    for ans in Ans:
        print(ans + "R")
else:
    print(len(D))
    print(" ".join(map(str,D)))
    for ans in Ans:
        print(ans)

Solution (Python):
N = int(input())
z = []
for i in range(N):
    xi, yi = map(int, input().split())
    z.append([xi + yi, xi - yi])

parity = z[0][1] % 2
for i in range(1, N):
    if z[i][0] % 2 != parity:
        print(-1)
        exit()
m = 32
def sign(n):
    pm = []
    diff = (((1 << m) - 1) - n) // 2
    for i in range(m):
        if (diff >> i) & 1 == 1:
            pm.append(-1)
        else:
            pm.append(1)
    return pm

ans = [''] * N
if parity == 0:
    arm = [1] + [1 << k for k in range(m)]
    for i in range(N):
        z[i][0] -= 1
        z[i][1] -= 1
        ans[i] += 'R'
if parity == 1:
    arm = [1 << k for k in range(m)]

for i in range(N):
    ui = sign(z[i][0])
    vi = sign(z[i][1])
    for k in range(m):
        if ui[k] == 1:
            if vi[k] == 1:
                ans[i] += 'R'
            else:
                ans[i] += 'U'
        else:
            if vi[k] == 1:
                ans[i] += 'D'
            else:
                ans[i] += 'L'
print(len(arm))
print(' '.join(map(str, arm)))
for i in range(N):
    print(ans[i])

Solution (Python):
r=range(int(input()))
u=[]
v=[]

for i in r:
  a,b=map(int,input().split())
  u+=[a+b]
  v+=[a-b]
  if u[0] % 2 != u[i] % 2:
    print(-1)
    exit()
    
d =[2**i for i in range(31)][::-1]
d+=[] if u[0] % 2 else [1]
print(len(d))
print(*d)

for i in r:
  x=""
  for j in d:
    fu = abs(u[i] + j) < abs(u[i] - j)
    fv = abs(v[i] + j) < abs(v[i] - j)
    u[i]+=[-j,j][fu]
    v[i]+=[-j,j][fv]
    x+='RUDL'[fu * 2 + fv]
  print(x)

Solution (Python):
from collections import Counter as C
N = int(input())
P = []
M = []
d = 32
for i in range(N):
    x, y = map(int, input().split(" "))
    x += 3<<d 
    P.append(x+y)
    M.append(x-y)
  
k = 1 - P[0]%2
if len(C([p%2 for p in P])) > 1:
    print(-1) 
else: 
    print(d+k)
    print(" ".join(["1"][:k]+[str(1<<i) for i in range(d)]))
    for i in range(N):
        a = bin(P[i])[-d-1:]
        b = bin(M[i])[-d-1:]
        print(''.join(['LDUR'[(int(a[i])*2+int(b[i]))] for i in range(d+k)])[::-1])

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
xy = []
for _ in range(n):
    xy.append(tuple(list(li())))


consis = True    
odev = (xy[0][0] + xy[0][1]) % 2
for x,y in xy[1:]:
    if (x+y)%2 != odev:
        consis = False
        
if consis:
    
    m = 0
    if odev == 1:
        m = 32
        ds = [2**i for i in range(31,-1,-1)]
    else:
        m = 33
        ds = [2**i for i in range(31,-1,-1)] + [1]
        
    print(m)
    print(" ".join([str(d) for d in ds]))
    
    
    for x,y in xy:
        u = x+y
        v = x-y
        
        
        us = []
        res = 0
        target = u
        for d in ds:
            if target > res:
                us.append(1)
                res += d
            else:
                us.append(-1)
                res -= d
           
        
        vs = []
        res = 0
        target = v
        for d in ds:
            if target > res:
                vs.append(1)
                res += d
            else:
                vs.append(-1)
                res -= d
                
        
        
        
        
        
        ans = []
        for u,v in zip(us, vs):
            if u==-1 and v==-1:
                ans.append("L")
            elif u==1 and v==1:
                ans.append("R")
            elif u==-1 and v==1:
                ans.append("D")
            elif u==1 and v==-1:
                ans.append("U")
            
        print("".join(ans))

else:
    print(-1)

Solution (Python):





"""
ARC103 D
"""

from collections import deque
n = int(input())
xyli = deque([tuple(map(int,input().split())) for i in range(n)])
zli = list(map(lambda t:(t[0]+t[1])%2,xyli))

if len(set(zli))>1:
    print(-1)
    exit()
oe = zli[0]
flag =False
if oe == 0:
    xyli = list(map(lambda t:(t[0]+1,t[1]),xyli))
    flag = True

uvli = list(map(lambda t:(t[0]+t[1],t[0]-t[1]),xyli))

def mode(ubin,vbin):
    if ubin and vbin:
        return('R')
    elif (not ubin) and vbin:
        return('D')
    elif ubin and (not vbin):
        return('U')
    else:
        return('L')

if flag:
    print(32)
    print(" ".join(map(str,[1]+[2**(30-i) for i in range(31)])))
else:
    print(31)
    print(" ".join(map(str,[2**(30-i) for i in range(31)])))

for u,v in uvli:
    ubin = format(((2**31-1)+u)//2,'031b')
    vbin = format(((2**31-1)+v)//2,'031b')
    if flag:
        print('L',end='')
    for i in range(31):
        print(mode(int(ubin[i]),int(vbin[i])),end='')
    print()

Solution (Python):





"""
ARC103 D
"""

from collections import deque
n = int(input())
xyli = deque([tuple(map(int,input().split())) for i in range(n)])

m = 20
dli = [1 for i in range(20)]

zli = list(map(lambda t:(t[0]+t[1])%2,xyli))

flag=True
if len(set(zli))>1:
    print(-1)
    exit()


oe = zli[0]

ans = []
dli = []
flag =False
if oe == 0:
    xyli = list(map(lambda t:(t[0]+1,t[1]),xyli))
    flag = True

uvli = list(map(lambda t:(t[0]+t[1],t[0]-t[1]),xyli))

def mode(ubin,vbin):
    if ubin and vbin:
        return('R')
    elif (not ubin) and vbin:
        return('D')
    elif ubin and (not vbin):
        return('U')
    else:
        return('L')

if flag:
    print(32)
    print(" ".join(map(str,[1]+[2**(30-i) for i in range(31)])))
else:
    print(31)
    print(" ".join(map(str,[2**(30-i) for i in range(31)])))

for u,v in uvli:
    ubin = format(((2**31-1)+u)//2,'031b')
    vbin = format(((2**31-1)+v)//2,'031b')
    if flag:
        print('L',end='')
    for i in range(31):
        print(mode(int(ubin[i]),int(vbin[i])),end='')
    print()

Solution (Python):
n = int(input())
ps = [list(map(int, input().split())) for i in range(n)]

prev = None
for x, y in ps:
    mandist = abs(x) + abs(y)
    if prev is not None and mandist % 2 != prev:
        print(-1)
        exit()
    prev = mandist % 2

isodd = mandist % 2
ds = [2 ** i for i in range(31)]
ds = ds[::-1]
if isodd:
    m = 31
else:
    m = 32
    ds += [1]

print(m)
print(*ds)
for x, y in ps:
    px = py = 0
    ans = ""
    for d in ds:
        dx = x - px
        dy = y - py
        if abs(dx) >= abs(dy):
            if dx >= 0:
                ans += "R"
                px += d
            else:
                ans += "L"
                px -= d
        else:
            if dy >= 0:
                ans += "U"
                py += d
            else:
                ans += "D"
                py -= d
    print(ans)

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
pos = []
flag1 = flag2 = False

for i in range(N):
    X, Y = map(int, raw_input().split())
    if (X + Y) % 2:
        flag1 = True
    else:
        flag2 = True
    pos += [(X, Y)]

if flag1 and flag2:
    print -1
    exit()

arms = [2 ** i for i in range(37)][::-1]
if flag2:
    arms += [1]

print len(arms)
print " ".join(map(str, arms))

dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
S = "LRDU"

for gx, gy in pos:
    x, y = 0, 0
    ans = ""
    for d in arms:
        x2, y2 = INF, INF
        for i in range(4):
            dx, dy = dir[i]
            x1, y1 = x + dx * d, y + dy * d
            if abs(x2 - gx) + abs(y2 - gy) > abs(x1 - gx) + abs(y1 - gy):
                x2, y2 = x1, y1
                c = S[i]
        ans += c
        x, y = x2, y2
    print ans

Solution (Python):
from collections import Counter as C
N = int(input())
P=[]
M=[]
for i in range(N):
    a, b = map(int, input().split(" "))
    a += 2**35*3
    P.append (a+b)
    M.append (a-b)

k=P[0] % 2
if len(C([p%2 for p in P])) > 1:
    print (-1) 
else: 
    print (33-k)
    print (["1 ",""][k] + " ".join([str(2**i) for i in range(32)]))
    for i in range(N):
        a=bin(P[i])[6:]
        b=bin(M[i])[6:]
        print(''.join(['LDUR'[::[1,-1][i==0]][(int(a[i])*2+int(b[i]))] for i in range(33-k)])[::-1])

Solution (Python):
from collections import Counter as C
N = int(input())
X=[]
Y=[]
for i in range(N):
    a, b = map(int, input().split(" "))
    X.append (a)
    Y.append (b)

if len(C([(X[i]+Y[i])%2 for i in range(N)]).most_common()) > 1:
    print (-1) 
else: 
    if (X[0]+Y[0]) % 2 == 0: 
        print (33)
        print ("1 " + " ".join([str(2**i) for i in range(32)]))
        x_init = 1
        ret_init = "L"
    else: 
        print (32) 
        print (" ".join([str(2**i) for i in range(32)]))
        x_init = 0
        ret_init = ""
        
    for i in range(N):
        x=X[i]+x_init
        y=Y[i]
        ret = ret_init

        for j in range(32):
            if ((x+y) % 4 == 1) == (j < 31):
                if x % 2 !=0:
                    ret += "L"
                    x += 1
                else:
                    ret += "D"
                    y += 1
            else:
                if x % 2 !=0:
                    ret += "R"
                    x -= 1
                else:
                    ret += "U"
                    y -= 1
            x//=2
            y//=2
        print (ret)

Solution (Python):
from functools import reduce
from itertools import product


def helper(dx,dy):
  if (dx,dy) == (0,0):
    return 'LR',0,0
  elif (dx,dy) == (0,1):
    return 'DD',0,1
  elif (dx,dy) == (0,2):
    return 'UU',0,0
  elif (dx,dy) == (1,0):
    return 'LL',1,0
  elif (dx,dy) == (1,1):
    return 'RU',0,0
  elif (dx,dy) == (1,2):
    return 'DR',0,1
  elif (dx,dy) == (2,0):
    return 'RR',0,0
  elif (dx,dy) == (2,1):
    return 'LU',1,0
  elif (dx,dy) == (2,2):
    return 'LD',1,1

def validate(D,solution):
  x,y = 0,0
  for d,m in zip(D,solution):
    if m == 'L':
      x -= d
    elif m == 'R':
      x += d
    elif m == 'D':
      y -= d
    else:
      y += d
  return x,y

def solve(x,y,n):

  result = []
  for i in range(n):
    xx = x%3
    yy = y%3

    s,a,b = helper(xx,yy)
    result.append(s)
    x = (x-xx)//3 + a
    y = (y-yy)//3 + b

  result = ''.join(result)
  return result,x,y


N = int(input())
points = list(tuple(map(int,input().split())) for _ in range(N))


even = all(sum(p) % 2 == 0 for p in points)
odd = all(sum(p) % 2 == 1 for p in points)
if not even and not odd:
  print(-1)
  exit()



if even:
  D = sum(([3**i,3**i] for i in range(20)), list())
  print(len(D))
  print(' '.join(map(str, D)))
  for x,y in points:
    solution,_,_ = solve(x, y, 20)
    
    print(solution)
else:
  D = sum(([3**i,3**i] for i in range(20)), list())[:-1]
  print(len(D))
  print(' '.join(map(str, D)))

  for x,y in points:
    solution,x,y = solve(x, y, 19)
    if (x,y) == (1,0):
      solution += 'R'
    elif (x,y) == (-1,0):
      solution += 'L'
    elif (x,y) == (0,1):
      solution += 'U'
    else:
      solution += 'D'
    
    print(solution)

Solution (Python):
import sys
import socket
import random

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
letter = ['L', 'R', 'D', 'U']


def check():
    M = 10 ** 2
    n = 1
    x = [random.randint(-M, M) for i in range(n)]
    y = [random.randint(-M, M) for i in range(n)]
    m, d, w = solve(n, x, y)

    return True


def solve(n, x, y):

    if len(set([(x[i] + y[i]) % 2 for i in range(n)])) == 2:
        return -1
    d = [2 ** k for k in range(35, -1, -1)]
    parity = (x[0] + y[0]) % 2
    if parity == 0:
        d.append(1)
    m = len(d)
    w = []
    for i in range(n):
        u, v = 0, 0
        s = []
        for j in range(m):
            choices = []
            for k in range(4):
                distance = abs(u + d[j] * dx[k] - x[i]) + abs(v + d[j] * dy[k] - y[i])
                choice = (distance, k)
                choices.append(choice)
            choices.sort()
            smallest_distance, best_k = choices[0]
            u += d[j] * dx[best_k]
            v += d[j] * dy[best_k]
            s.append(letter[best_k])
        w.append(''.join(s))
    return m, d, w


def main():

    random.seed = 1
    n = read_int()
    x = [0] * n
    y = [0] * n
    for i in range(n):
        x[i], y[i] = read_int_list()
    res = solve(n, x, y)
    if res == -1:
        print(res)
        return
    m, d, w = res
    print(m)
    print(*d)
    print('\n'.join(w))


if __name__ == '__main__':
    
    main()

Solution (Python):

N = int(input())
X_list = [0]*N
Y_list = [0]*N

res_flag = 1

r = -1
for i in range(N):
    X, Y = map(int, input().split())
    if r >= 0:
        if r != (X+Y)%2:
            res_flag = -1
    else:
        r = (X+Y)%2
    X_list[i] = X
    Y_list[i] = Y
    
if res_flag == -1:
    print(-1)
else:
    if r == 0:
        print(32)
        print(" ".join([str(2**i) for i in range(30, -1, -1)]+["1"]))
        X_add = 1
        m_list_add = ["L"]
    else:
        print(31)
        print(" ".join([str(2**i) for i in range(30, -1, -1)]))
        X_add = 0
        m_list_add = []
    for n in range(N):
        X = X_list[n] + X_add
        Y = Y_list[n]
        
        S = X + Y
        T = X - Y
        m_list = []
        for i in range(30, -1, -1):
            if S < 0 and T < 0:
                m_list.append("L")
                S += 2**i
                T += 2**i
            elif S < 0 and T > 0:
                m_list.append("D")
                S += 2**i
                T -= 2**i
            elif S > 0 and T > 0:
                m_list.append("R")
                S -= 2**i
                T -= 2**i
            elif S > 0 and T < 0:
                m_list.append("U")
                S -= 2**i
                T += 2**i
            else:
                print("?")
        if S != 0 or T != 0:
            print("?")
        
        print("".join(m_list + m_list_add))

Solution (Python):
N = input()
X = [0]*N
Y = [0]*N
for i in range(N):
  X[i],Y[i] = map(int, raw_input().split())

p = (X[0]+Y[0])%2
for i in range(1,N):
  if p!=(X[i]+Y[i])%2:
    print -1
    exit(0)

if p==0:
  print 33
  print 1,
else:
  print 32
for i in range(32)[::-1]:
  print 1<<i,
print


for i in range(N):
  if p==0:
    w = "L"
    X[i] += 1
  else:
    w = ""
  for j in range(32)[::-1]:
    if abs(X[i])>abs(Y[i]):
      if X[i]>0:
        w += "R"
        X[i] -= 1<<j
      else:
        w += "L"
        X[i] += 1<<j
    else:
      if Y[i]>0:
        w += "U"
        Y[i] -= 1<<j
      else:
        w += "D"
        Y[i] += 1<<j
  print w

Solution (Python):
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]

z = sum(XY[0])%2
for xy in XY:
    x, y = xy
    if not (x+y)%2==z:
        print(-1)
        exit()

D = [1<<i for i in range(34)]
if z==0:
    D.append(1)
print(len(D))
print(" ".join(map(str, D)))
for x, y in XY:
    if z==0:
        x-=1
    s=""
    yy = x+y
    xx = x-y
    for i, d in enumerate(D[:34]):
        if i==33:
            if xx>0:
                if yy>0:
                    s+="R"
                else:
                    s+="D"
            else:
                if yy>0:
                    s+="U"
                else:
                    s+="L"
            break
        
        xq, xm = divmod(xx, 4)
        yq, ym = divmod(yy, 4)
        if xm==1:
            if ym==1:
                s+="L"
            elif ym==3:
                s+="U"
            else:
                while True:
                    print(1)
        elif xm==3:
            if ym==1:
                s+="D"
            elif ym==3:
                s+="R"
            else:
                while True:
                    print(1)
        else:
            while True: print(1)
        
        
        xx>>=1
        yy>>=1
        if xx%2==0:
            xx+=1
        if yy%2==0:
            yy+=1
    if z == 0:
        s += "R"
    print(s)

Solution (Python):
N = int(input())
ps = [list(map(int, input().split())) for _ in range(N)]

prev = None
for x, y in ps:
  mandist = abs(x) + abs(y)
  if prev is not None and mandist % 2 != prev:
    print('-1')
    exit()
  prev = mandist % 2

isodd = mandist % 2
ds = [2 ** i for i in range(32)] 
ds = ds[::-1]
if isodd:
  m = 32
else:
  m = 33
  ds += [1]

print(m)
print(' '.join(list(map(str, ds))))
for x, y in ps:
  px = py = 0
  ans = ''
  for d in ds:
    dx = x - px
    dy = y - py
    if abs(dx) >= abs(dy):
      if dx >= 0:
        ans += 'R'
        px += d
      else:
        ans += 'L'
        px -= d
    else:
      if dy >= 0:
        ans += 'U'
        py += d
      else:
        ans += 'D'
        py -= d
  print(ans)