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):
N = int(input())
Pi = []
for i in range(N):
    d = list(map(int, input().split()))
    Pi.append(d)
 

for p in Pi[1:]:
    if (p[0] + p[1]) % 2 != (Pi[0][0] + Pi[0][1]) % 2:
        print(-1)
        exit()
 

Ai = []
if (Pi[0][0] + Pi[0][1]) % 2 == 0:
    Ai.append(1)
for i in range(0, 32):
    Ai.append(2 ** i)
 
def find_arm_pattern(arms, target_x, target_y):
    result = ""
    x = 0
    y = 0
    for a in arms:
        dx = target_x - x
        dy = target_y - y
        if abs(dx) >= abs(dy):
            if dx > 0:
                result += "R"
                x += a
            else:
                result += "L"
                x -= a
        else:
            if dy > 0:
                result += "U"
                y += a
            else:
                result += "D"
                y -= a
    if x == target_x and y == target_y:
        return result
    return None
 
 
arms = list(reversed(Ai))
results = []
for p in Pi:
    r = find_arm_pattern(arms, p[0], p[1])
    results.append(r)
txt = str(arms)
print(len(arms))
print(txt[1:-1].replace(",", ""))
for r in results:
    print(r)

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
U=[0]*N 
V=[0]*N 
parity = 0
for i in range(N):
    x,y = rl()
    U[i],V[i] = format(x+y,'+032b'), format(x-y,'+032b')
    parity += (x+y)%2

if parity == 0 or parity == N:
    parity //= N
    m = 31 if parity else 32
    print(m)
    d = [1 for i in range(m)]
    for i in range(1,31):
        d[i] = d[i-1]*2
    d.sort(reverse=True)
    print(*d, sep=' ')

    for i in range(N):
        res = ''
        u,v = U[i],V[i]

        ub,vb = [1]+list(map(int,u[1:-1])), [1]+list(map(int,v[1:-1]))
        if not parity:
            ub += [0]
            vb += [0]
        if u[0] == '-': ub = list(map(lambda x: x^1, ub))
        if v[0] == '-': vb = list(map(lambda x: x^1, vb))

        for ub_,vb_ in zip(ub,vb):
            if ub_==0 and vb_==0:
                res += 'L'
            elif ub_==1 and vb_==1:
                res += 'R'
            elif ub_==0 and vb_==1:
                res += 'D'
            else:
                res += 'U'
        print(res)
else:
    print(-1)

Solution (Python):
def robot_arms(N: int, XY: list) -> tuple:
    odd, even = 0, 0
    max_dist = 0
    for x, y in XY:
        ax, ay = abs(x), abs(y)
        if (ax + ay) % 2 == 0:
            even += 1
        else:
            odd += 1

        if max_dist < ax + ay:
            max_dist = ax + ay

    if odd == 0:
        
        arms = [1]
    elif even == 0:
        
        arms = []
    else:
        
        return [], []

    
    tmp, sum_tmp = 1, sum(arms)
    while sum_tmp < max_dist:
        arms.append(tmp)
        sum_tmp += tmp
        tmp <<= 1

    
    ops = []
    for x, y in XY:
        op = ''
        
        
        
        
        
        
        
        left_len = sum(arms)
        nx, ny = x, y
        for arm in reversed(arms):
            left_len -= arm
            if abs(nx + arm) + abs(ny) <= left_len:
                op = 'L' + op
                nx, ny = nx + arm, ny
            elif abs(nx - arm) + abs(ny) <= left_len:
                op = 'R' + op
                nx, ny = nx - arm, ny
            elif abs(nx) + abs(ny + arm) <= left_len:
                op = 'D' + op
                nx, ny = nx, ny + arm
            elif abs(nx) + abs(ny - arm) <= left_len:
                op = 'U' + op
                nx, ny = nx, ny - arm
        ops.append(op)

    return arms, ops


if __name__ == "__main__":
    N = int(input())
    XY = [tuple(map(int, input().split())) for _ in range(N)]
    ans = robot_arms(N, XY)

    if len(ans[0]) == 0:
        print(-1)
    else:
        d, w = ans
        print(len(d))
        print(' '.join(map(str, d)))
        for ww in w:
            print(ww)

Solution (Python):
def d_robot_arms(N, Pos):
    

    pos = []
    
    parity = (abs(Pos[0][0]) + abs(Pos[0][1])) % 2
    for x, y in Pos:
        parity_current = (abs(x) + abs(y)) % 2
        if parity != parity_current:
            return -1
        pos.append((x - y, x + y))
        
        
        

    
    
    arms = [1 << k for k in range(30, -1, -1)]
    if parity % 2 == 0:
        arms.append(1)  

    
    ans_tmp = [str(len(arms)), ' '.join(list(map(str, arms)))]

    for u_pos, v_pos in pos:
        
        u_sum, v_sum = 0, 0
        tmp = ''
        for arm_len in arms:
            u_dir = 1 if u_sum <= u_pos else -1
            u_sum += u_dir * arm_len

            v_dir = 1 if v_sum <= v_pos else -1
            v_sum += v_dir * arm_len

            
            
            if u_dir == 1 and v_dir == 1:
                tmp += 'R'
            elif u_dir == 1 and v_dir == -1:
                tmp += 'D'
            elif u_dir == -1 and v_dir == -1:
                tmp += 'L'
            else:
                tmp += 'U'
        ans_tmp.append(''.join(tmp))
    ans = '\n'.join(ans_tmp)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(d_robot_arms(N, Pos))

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
X,Y=[],[]
for _ in range(n):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
mod=(X[0]+Y[0])%2
for i in range(1,n):
    if (X[i]+Y[i])%2!=mod:
        print(-1)
        exit()
if not mod:
    X=[x+1 for x in X]
U=[X[i]+Y[i] for i in range(n)]
V=[X[i]-Y[i] for i in range(n)]
Mode=['L','D','U','R']
m=31
if mod:
    print(m)
    print(' '.join([str(2**i) for i in range(m)]))
else:
    print(m+1)
    print('1 '+' '.join([str(2**i) for i in range(m)]))
for i in range(n):
    w=''
    if not mod:
        w='L'
    ui=(U[i]+2**m-1)//2
    vi=(V[i]+2**m-1)//2
    for _ in range(m):
        u_bit,v_bit=ui&1,vi&1
        ui>>=1
        vi>>=1
        w+=Mode[u_bit*2+v_bit]
    print(w)

Solution (Python):
n = int(input())
place = [tuple(map(int, input().split())) for _ in range(n)]
m = 0
def bitlist(x):
    ret = [0] * 31
    for i in reversed(range(31)):
        if x > 0:
            x -= 1 << i
            ret[i] = 1
        else:
            x += 1 << i
            ret[i] = -1
    return ret
pre = (place[0][0] + place[0][1] + 1) % 2
for x, y in place:
    if (x + y + 1) % 2 != pre:
        print(-1)
        exit()
print(31 + pre)
if pre:
    print(1, end = ' ')
for i in reversed(range(31)):
    print(1 << i, end = ' ')
print()
for x, y in place:
    u = x + y
    v = x - y
    if pre:
        u -= 1
        v -= 1
    ubit = bitlist(u)
    vbit = bitlist(v)
    if pre:
        print('R', end = '')
    for i in reversed(range(31)):
        if ubit[i] == 1 and vbit[i] == 1:
            print('R', end = '')
        elif ubit[i] == 1 and vbit[i] == -1:
            print('U', end = '')
        elif ubit[i] == -1 and vbit[i] == -1:
            print('L', end = '')
        else:
            print('D', end = '')
    print()

Solution (Python):
n = int(input())
x = [0 for i in range(0, n)]
y = [0 for i in range(0, n)]

for i in range(0, n):
    x[i], y[i] = [int(i) for i in input().split(" ")]

mod2 = (x[0] + y[0]) % 2
imp = False

for i in range(1, n):
    if (x[i] + y[i]) % 2 != mod2:
        print(-1)
        imp = True
        break
        
if not imp:
    if mod2 == 0:
        x = [i + 1 for i in x]

    u = [x[i] + y[i] for i in range(0, n)]
    v = [x[i] - y[i] for i in range(0, n)]

    mode = ["L", "D", "U", "R"]
    m = 31

    if mod2 == 0:
        print(m + 1)
        print("1 " + " ".join([str(2**(i - 1)) for i in range(1, m + 1)]))
    else:
        print(m)
        print(" ".join([str(2**(i - 1)) for i in range(1, m + 1)]))

    for i in range(0, n):
        w = ""
        if mod2 == 0:
            w = "L"
        ui = (u[i] + 2**m - 1) // 2
        vi = (v[i] + 2**m - 1) // 2
        for l in range(0, m):
            ul = ui % 2
            ui = ui // 2
            vl = vi % 2
            vi = vi // 2
            w += mode[ul * 2+ vl]
        print(w)

Solution (Python):
def pow2(i):
    ret = 1
    while i!=1:
        i >>= 1
        ret <<= 1
    return ret

m = int(input())

points = []
max2 = -1
flag = True
bias = -1
for i in range(m):
    point = list(map(int,input().split()))
    dis = abs(point[0])+abs(point[1])
    if (dis > max2):
        max2 = dis
    if (bias!=-1 and dis%2 != bias%2):
        flag =False
    if (dis%2 == 0):
        point[0] -= 1 
    points.append(tuple(point))
    bias = dis%2
if flag == False:
    print("-1")
    exit(0)        

bias = max2%2
max2 = pow2(max2)
diss = []
dirctions = [""]*m
while max2>0:
    for i in range(m):
        point = points[i]
        
        if (point[1]>point[0] and point[1]>(-point[0])):
            dirctions[i] = "U"+dirctions[i]
            points[i] = (point[0],point[1]-max2)
        elif(point[1]>point[0] and point[1]<(-point[0])):
            dirctions[i] = "L"+dirctions[i]
            points[i] = (point[0]+max2,point[1])
        elif(point[1]<point[0] and point[1]>(-point[0])):
            dirctions[i] = "R"+dirctions[i]
            points[i] = (point[0]-max2,point[1])
        else:
            dirctions[i] = "D"+dirctions[i] 
            points[i] = (point[0],point[1]+max2)
    diss = [max2] + diss
    max2 >>= 1

if (bias == 0):
    diss = [1] + diss
    for i in range(m):
        dirctions[i] = "R"+dirctions[i]
print(len(diss))
for d in diss:
    print(str(d),end=" ")
print("")
for d in dirctions:
    print(d)

Solution (Python):
from sys import stdin, exit
import numpy as np

N, *XY = map(int, stdin.read().split())
XY = np.array(XY).reshape(N, 2)

XYsum = np.abs(XY).sum(axis=1)
if any(XYsum % 2 != XYsum[0] % 2):
    print(-1)
    exit()

xymax = XYsum.max()
d = [] if xymax % 2 == 1 else [1]
for i in range(41):
    di = 2**i
    if xymax < di:
        break
    d.append(di)
d.reverse()
print(len(d))
print(' '.join(map(str, d)))

for X, Y in XY:
    x, y = 0, 0
    w = ''
    for di in d:
        if abs(X-(x-di)) + abs(Y-y) <= di:
            w += 'L'
            x -= di
        elif abs(X-(x+di)) + abs(Y-y) <= di:
            w += 'R'
            x += di
        elif abs(X-x) + abs(Y-(y-di)) <= di:
            w += 'D'
            y -= di
        else:
            w += 'U'
            y += di
    print(w)

Solution (Python):









n=int(input())
listXY=[list(map(int,input().split())) for _ in range(n)]
listUV=[[listXY[i][0]+listXY[i][1],listXY[i][0]-listXY[i][1]]for i in range(n)]

isOdd=listUV[0][0]%2
canReach=1
for i in range(1,n):
    if isOdd!=listUV[i][0]%2:
        canReach=0
        break

if not canReach:
    print(-1)
else:
    offset=2**31-isOdd
    m=32-isOdd
    d=[2**i for i in range(32)]
    w=[]
    for i in range(n):
        x,y=0,0
        u,v=listUV[i][0]+offset,listUV[i][1]+offset
        s=''
        if not isOdd:
            s='L'
            x=x-1
        for k in range(31):
            u //= 2
            v //= 2
            u1, v1 = u % 2, v % 2
            
            if u1 == 0 and v1 == 1:
                s += 'D'
                y=y-d[k]
            elif u1 == 0 and v1 == 0:
                s += 'L'
                x=x-d[k]
            elif u1 == 1 and v1 == 1:
                s += 'R'
                x=x+d[k]
            elif u1 == 1 and v1 == 0:
                s += 'U'
                y=y+d[k]
        w.append(s)
        
    
    
    print(32-isOdd)
    s=''
    if not isOdd:
        s='1 '
    for i in range(31):
        s+=str(d[i])+' '
    print(s)
    for i in range(n):
        print(w[i])

Solution (Python):



N = int(input())
targets = [ list(map(int, input().split())) for _ in range(N)]

mod_1st = sum(targets[0]) % 2 
if not all( sum(t) %2 == mod_1st for t in targets[1:]):
    print(-1)
    exit(0)

mod = mod_1st
print(33 - mod)  
D = [2**i for i in range(31, -1, -1)] 
if mod == 0:
    D.append(1)
print(' '.join(map(str, D)))

for (x,y) in targets:
    temp = []
    u = x+y
    v = x-y
    for d in D:
        if u >= 0:
            if v >= 0:
                temp.append("R")
                u -= d
                v -= d
            elif v <  0:
                temp.append("U")
                u -= d
                v += d
        elif u < 0:
            if v >= 0:
                temp.append("D")
                u += d
                v -= d
            elif v < 0 :
                temp.append("L")
                u += d
                v += d

    print(''.join(temp))

Solution (Python):



N = int(input())
targets = [ list(map(int, input().split())) for _ in range(N)]

mod_1st = sum(targets[0]) % 2 
if not all( sum(t) %2 == mod_1st for t in targets[1:]):
    print(-1)
    exit(0)






mod = mod_1st
print(33 - mod)  
D = [2**i for i in range(31, -1, -1)] 
if mod == 0:
    D.append(1)
print(' '.join(map(str, D)))

for (x,y) in targets:
    temp = []
    u = x+y
    v = x-y
    for d in D:
        if u >= 0:
            if v >= 0:
                temp.append("R")
                u -= d
                v -= d
            elif v <  0:
                temp.append("U")
                u -= d
                v += d
        elif u < 0:
            if v >= 0:
                temp.append("D")
                u += d
                v -= d
            elif v < 0 :
                temp.append("L")
                u += d
                v += d

    
    
    
    
    
    
    
    
    
    
    
    
    
    print(''.join(temp))

Solution (Python):



N = int(input())
targets = [ list(map(int, input().split())) for _ in range(N)]

mod_1st = sum(targets[0]) % 2 
if not all( sum(t) %2 == mod_1st for t in targets[1:]):
    print(-1)
    exit(0)






mod = mod_1st
print(33 - mod)  
D = [2**i for i in range(31, -1, -1)] 
if mod == 0:
    D.append(1)
print(' '.join(map(str, D)))

for (x,y) in targets:
    temp = []
    for d in D:
        if x >= y and x+y >= 0:
            temp.append("R")
            x -= d
        elif x < y and x + y >= 0:
            temp.append("U")
            y -= d
        elif x >= y and x + y  <0 :
            temp.append("D")
            y += d
        else:
            temp.append("L")
            x += d
    print(''.join(temp))

Solution (Python):


def main():
    N = int(input())
    XY_list = []
    for i in range(N):
        XY_list.append(list(map(int, input().split())))

    rot_list = list(map(lambda xy: [xy[0] + xy[1], -xy[0] + xy[1]], XY_list))

    f = True
    p = rot_list[0][0] % 2
    for i in range(1, N):
        if rot_list[i][0] % 2 != p:
            f = False
            break

    if not f:
        print(-1)
    else:
        offset = 2 ** 31 - p
        m = 32 - p
        d = []
        if p == 0:
            d.append(1)
        for k in range(31):
            d.append(2 ** k)
        w = []
        for i in range(N):
            uv = rot_list[i]
            u, v = uv[0] + offset, uv[1] + offset
            s = ''
            if p == 0:
                s = 'D'
            for k in range(31):
                u //= 2
                v //= 2
                u1, v1 = u % 2, v % 2
                if u1 == 0 and v1 == 0:
                    s += 'D'
                elif u1 == 0 and v1 == 1:
                    s += 'L'
                elif u1 == 1 and v1 == 0:
                    s += 'R'
                elif u1 == 1 and v1 == 1:
                    s += 'U'
            w.append(s)

        print(m)
        s = ''
        for dv in d:
            s += ' ' + str(dv)
        print(s[1:])
        for i in range(N):
            print(w[i])


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))
    mod = sum(xy[0]) % 2
    for x, y in xy:
        if (x + y) % 2 != mod:
            print(-1)
            exit()
    print(33 - mod)
    D = [2 ** i for i in range(31, -1, -1)]
    if mod == 0:
        D.append(1)
    print(' '.join(map(str, D)))

    for x, y in xy:
        temp = []
        for d in D:
            if x >= y and x + y >= 0:
                temp.append("R")
                x -= d
            elif x < y and x + y >= 0:
                temp.append("U")
                y -= d
            elif x >= y and x + y < 0:
                temp.append("D")
                y += d
            else:
                temp.append("L")
                x += d
        print(''.join(temp))


main()

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

odds_even = set([(x + y) % 2 for x, y in Points])
if len(odds_even) != 1:
    print(-1)
    exit()

D = [2 ** i for i in range(39)]  
D = D[::-1]  
if odds_even == {0}:  
    D.append(1)

print(len(D))
print(' '.join(map(str, D)))

for tX, tY in Points:
    nX, nY = 0, 0
    ans = ''
    for d in D:
        uX, uY = nX, nY + d  
        rX, rY = nX + d, nY  
        dX, dY = nX, nY - d  
        lX, lY = nX - d, nY  

        diff_U = abs(tX - uX) + abs(tY - uY)
        diff_R = abs(tX - rX) + abs(tY - rY)
        diff_D = abs(tX - dX) + abs(tY - dY)
        diff_L = abs(tX - lX) + abs(tY - lY)

        Diff = [diff_U, diff_R, diff_D, diff_L]
        Command = ['U', 'R', 'D', 'L']
        Next = [[uX, uY], [rX, rY], [dX, dY], [lX, lY]]

        min_diff_index = Diff.index(min(Diff))

        ans += Command[min_diff_index]
        nX, nY = Next[min_diff_index]

    print(ans)

Solution (Python):
def solve(x, y, d, m):
    ret = ""
    dx = [-1, 0, 0, 1]
    dy = [0, -1, 1, 0]
    mode = ['R', 'U', 'D', 'L']
    for i in range(m):
        dir = 0
        t = abs(x + d[i] * dx[0]) + abs(y + d[i] * dy[0])
        for j in range(4):
            nx = x + d[i] * dx[j]
            ny = y + d[i] * dy[j]
            if abs(nx) + abs(ny) < t:
                t = abs(nx) + abs(ny)
                dir = j
        x = x + d[i] * dx[dir]
        y = y + d[i] * dy[dir]
        ret += mode[dir]

    print (ret)


def main():
    m = 34
    X, Y, d = [], [], []

    for i in range(32, 0, -1):
        d += [2**i]
    d += [1]

    N = int(input())
    even, odd = 0, 0

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

        if (abs(x) + abs(y)) % 2 == 0:
            even += 1
        else:
            odd += 1

    if even and odd:
        print(-1)
        return 0

    if odd:
        m -= 1
    else:
        d += [1]

    print(m)
    print(" ".join(map(str, d)))

    for i in range(N):
        solve(X[i], Y[i], d, m)

main()

Solution (Python):
def solve(x, y, d, m):
    ret = ""
    for i in range(m):
        if x + y >= 0 and x - y >= 0:
            ret += "R"
            x -= d[i]
        elif x + y >= 0 and x - y < 0:
            ret += "U"
            y -= d[i];
        elif x + y < 0 and x - y >= 0:
            ret += "D"
            y += d[i];
        else:
            ret += "L"
            x += d[i]
    print (ret)


def main():
    m = 34
    X, Y, d = [], [], []

    for i in range(32, 0, -1):
        d += [2**i]
    d += [1]

    N = int(input())
    even, odd = 0, 0

    for i in range(N):
        x, y = map(int, input().split())
        X += [x]; Y += [y]
    
        if (abs(x) + abs(y)) % 2 == 0:
            even += 1
        else:
            odd += 1

    if even and odd:
        print(-1)
        return 0

    if odd:
        m -= 1
    else:
        d += [1]

    print(m)
    print(" ".join(map(str, d)))

    for i in range(N):
        solve(X[i], Y[i], d, m)

main()

Solution (Python):
from functools import reduce
import math

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


x, y = coord[0]
p = (x + y) & 1
limit = 0
for x, y in coord:
    if p != (x + y) & 1:
        print(-1)
        exit()
    lim = abs(x) + abs(y)
    if lim > limit:
        limit = lim

limit = round(math.log2(limit))
if p == 1:
    d = [2 ** i for i in reversed(range(limit + 1))]
else:
    d = [1] + [2 ** i for i in reversed(range(limit + 1))]

print(len(d))
print(reduce((lambda acc, dist: str(acc) + " " + str(dist)), d))

for x, y in coord:
    u = x + y
    v = x - y

    command = ""
    for i in range(len(d)):
        if u >= 0 and v >= 0:
            command += "R"
            u -= d[i]
            v -= d[i]
        elif u >= 0 > v:
            command += "U"
            u -= d[i]
            v += d[i]
        elif u < 0 <= v:
            command += "D"
            u += d[i]
            v -= d[i]
        elif u < 0 and v < 0:
            command += "L"
            u += d[i]
            v += d[i]

    print(command)

Solution (Python):
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
MOD = sum(XY[0]) % 2

for x, y in XY:
    if MOD != (x + y) % 2:
        print(-1)
        exit()

m = 33 - MOD
print(m)
D = [2 ** i for i in range(31, -1, -1)]
if MOD == 0:
    D.append(1)

print(" ".join(map(str, D)))
for x, y in XY:
    w = ""
    for d in D:
        if x + y >= 0 and x - y >= 0:
            w += "R"
            x -= d
        elif x + y < 0 and x - y >= 0:
            w += "D"
            y += d
        elif x + y >= 0 and x - y < 0:
            w += "U"
            y -= d
        else:
            w += "L"
            x += d

    print(w)

Solution (Python):
import copy
N = int(input())
X = []
X.append(list(map(int, input().split())))

T = (X[0][0] + X[0][1]) % 2
max = abs(X[0][0]) + abs(X[0][1])
for i in range(1,N):
  X.append(list(map(int, input().split())))
  t = abs(X[i][0]) + abs(X[i][1])
  if t % 2 != T:
    print(-1)
    exit()
  if max < t:
    max = t
    



D = []
sum = 0
if T == 0:
  max -= 1
t = 1
while 1:
  D.append(t)
  sum += t
  if sum >= max:
    break
  t *= 2
if T == 0:
  D.append(1)
D.reverse()


print(len(D))

s = ""
for i in range(len(D)):
  s += str(D[i]) + " "
print (s)


for i in range(N):
  U = X[i][0] + X[i][1]
  V = X[i][0] - X[i][1]
  s = ""
  for j in range(len(D)):
    if U >= 0:
      if V >= 0:
        s += "R"
        U -= D[j]
        V -= D[j]
      else:
        s += "U"
        U -= D[j]
        V += D[j]
    else:
      if V >= 0:
        s += "D"
        U += D[j]
        V -= D[j]
      else:
        s += "L"
        U += D[j]
        V += D[j]
  print(s)

Solution (Python):
def d_robot_arms(N, Pos):
    

    pos = []
    
    parity = (abs(Pos[0][0]) + abs(Pos[0][1])) % 2
    for x, y in Pos:
        parity_current = (abs(x) + abs(y)) % 2
        if parity != parity_current:
            return -1
        pos.append([x - y, x + y])
        
        

    
    
    arms = [1 << k for k in range(30, -1, -1)]
    if parity % 2 == 0:
        arms.append(1)  

    
    ans_tmp = [str(len(arms)), ' '.join(list(map(str, arms)))]

    for pos_u, pos_v in pos:
        
        usum, vsum = 0, 0
        tmp = ''
        for arm_len in arms:
            if usum <= pos_u:
                udir = 'positive'
                usum += arm_len
            else:
                udir = 'negative'
                usum -= arm_len

            if vsum <= pos_v:
                vdir = 'positive'
                vsum += arm_len
            else:
                vdir = 'negative'
                vsum -= arm_len

            
            
            if udir == 'positive' and vdir == 'positive':
                tmp += 'R'
            elif udir == 'positive' and vdir == 'negative':
                tmp += 'D'
            elif udir == 'negative' and vdir == 'negative':
                tmp += 'L'
            else:
                tmp += 'U'
        ans_tmp.append(''.join(tmp))
    ans = '\n'.join(ans_tmp)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(d_robot_arms(N, Pos))

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

arms = []
n = 1
for i in range(39):
    arms.append(n)
    n *= 2
if guuki==0:
    arms.append(1)
arms.reverse()

dirs = {'R':(1,0),'U':(0,1),'L':(-1,0),'D':(0,-1)}

print(len(arms))
print(*arms)
for x,y in XY:
    nx = ny = 0
    s = ''
    if guuki==0:
        nx += 1
        s += 'R'
    for a in arms[-39:]:
        dist = float('inf')
        dr = ''
        for d,(dx,dy) in dirs.items():
            tmp = abs(x - (nx+dx*a)) + abs(y - (ny+dy*a))
            if tmp < dist:
                dist = tmp
                dr = d
        dx,dy = dirs[dr]
        nx += dx*a
        ny += dy*a
        s += dr
    print(s)

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

sys.setrecursionlimit(10**5)

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):
    x,y = li()
    xy.append((x,y))
    
exist = True
    
eo = (xy[0][0]+xy[0][1]) % 2
for x,y in xy[1:]:
    if (x+y)%2 != eo:
        exist = False
    
if not exist:
    print(-1)
    
else:
    if eo == 1:
        arms = [2**i for i in range(40)]
        print(40)
        print(*arms[::-1])
        
    else:
        arms = [1] + [2**i for i in range(39)]
        print(40)
        print(*arms[::-1])
        
    for x,y in xy:
        u,v = x-y, x+y
        ucur, vcur = 0,0
        ans = ""
        for am in arms[::-1]:
            if ucur >= u and vcur >= v:
                ucur -= am
                vcur -= am
                ans += "L"
                
            elif ucur <= u and vcur <= v:
                ucur += am
                vcur += am
                ans += "R"
                
            elif ucur >= u and vcur <= v:
                ucur -= am
                vcur += am
                ans += "U"
                
            elif ucur <= u and vcur >= v:
                ucur += am
                vcur -= am
                ans += "D"
                
        print(ans)

Solution (Python):









from math import *

def L(xi, di):
    return xi - di

def R(xi, di):
    return xi + di

def D(yi, di):
    return yi - di

def U(yi, di):
    return yi + di

def main():
    N = int(input())
    x_list = [list(map(int, input().split())) for i in range(N)]
    sum_list = [abs(x[0]) + abs(x[1]) for x in x_list]
    checker = sum_list[0] % 2

    for wa in sum_list:
        if wa % 2 != checker:
            print("-1")
            return

    arm_list = []
    if checker == 0:
        arm_list.append(1)

    pow_i = 0
    max_sum = max(sum_list)
    while max_sum > sum(arm_list):
        arm_list.append(2 ** pow_i)
        pow_i += 1
    arm_list = sorted(arm_list, key=lambda x: -x)
    print(len(arm_list))
    print(" ".join(map(str, arm_list)))

    for c in x_list:
        now_c = [0,0]
        order = ""

        for arm in arm_list:
            dx = c[0] - now_c[0]
            dy = c[1] - now_c[1]

            if abs(dx) > abs(dy):
                if dx > 0:
                    order += "R"
                    now_c[0] = R(now_c[0], arm)
                else:
                    order += "L"
                    now_c[0] = L(now_c[0], arm)
            else:
                if dy > 0:
                    order += "U"
                    now_c[1] = U(now_c[1], arm)
                else:
                    order += "D"
                    now_c[1] = D(now_c[1], arm)
        print(order)

if __name__ == "__main__":
    main()