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):


inf = float('inf')

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

parity = None
can_make = True
for coordinate in coordinates:
    if parity is None:
        parity = sum(coordinate) % 2
    else:
        if parity != sum(coordinate) % 2:
            can_make = False
            break

if not can_make:
    print(-1)
    exit()
    

if parity == 0:
    d = [pow(2, i) for i in range(31 + 1)] + [1]
    
else:
    d = [pow(2, i) for i in range(31 + 1)]
    
d.sort(reverse=True)

ans = []
for x, y in coordinates:
    u = x + y
    v = x - y
    
    
    
    
    
    
    curu, curv = 0, 0
    ops = ''
    for dd in d:
        dist = inf
        op = ''
        det_du, det_dv = 0, 0
        for c, (du, dv) in zip('LRDU', [(-1, -1), (1, 1), (-1, 1), (1, -1)]):
            t = abs(curu + du * dd - u) + abs(curv + dv * dd - v)
            if dist > t:
                op = c
                dist = t
                det_du = du
                det_dv = dv
        ops += op
        curu += det_du * dd
        curv += det_dv * dd
    if (curu, curv) == (u, v):
        ans.append(ops)
    else:
        print(-1)
        

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

Solution (Python):
inf = float('inf')

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

parity = None
can_make = True
for coordinate in coordinates:
    if parity is None:
        parity = sum(coordinate) % 2
    else:
        if parity != sum(coordinate) % 2:
            can_make = False
            break

if not can_make:
    print(-1)
    exit()
    

m = 40
if parity == 0:
    d = [pow(2, i) for i in range(39)] + [1]
    
else:
    d = [pow(2, i) for i in range(40)]
    
d.sort(reverse=True)

ans = []
for x, y in coordinates:
    curx, cury = 0, 0
    ops = ''
    for dd in d:
        dist = inf
        op = ''
        det_dx, det_dy = 0, 0
        for c, (dx, dy) in zip('LRDU', [(-1, 0), (1, 0), (0, -1), (0, 1)]):
            t = abs(curx + dx * dd - x) + abs(cury + dy * dd - y)
            if dist > t:
                op = c
                dist = t
                det_dx = dx
                det_dy = dy
        ops += op
        curx += det_dx * dd
        cury += det_dy * dd
    if (curx, cury) == (x, y):
        ans.append(ops)
    else:
        print(-1)
        

print(m)
print(*d)
print(*ans, sep='\n')

Solution (Python):
N = int(input())
S = [0] * N
X = [0] * N
Y = [0] * N
for i in range(N):
    X[i], Y[i] = map(int, input().split())
    S[i] = X[i] + Y[i]
    
    if (S[i] - S[0]) % 2 != 0:
        print(-1)
        exit()

nums = []
for i in range(30, -1, -1):
    
    nums.append(1 << i)


if S[0] % 2 == 0:
    nums.append(1)

m = len(nums)

print(m)
print(*nums)

for i in range(N):
    u = X[i] + Y[i]
    v = X[i] - Y[i]
    
    for num in nums:
        if u >= 0:
            if v >= 0:
                print('R',end='')
                u -= num
                v -= num
            else:
                print('U',end='')
                u -= num
                v += num
        else:
            if v >= 0:
                print('D',end='')
                u += num
                v -= num
            else:
                print('L',end='')
                u += num
                v += num
    print()

print()

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



if N != 1:
    a = abs(XY[0][0]) + abs(XY[0][1])
    flag = (XY[0][0] + XY[0][1])%2
for i in range(N-1):
    b = abs(XY[i+1][0]) + abs(XY[i+1][1])
    a = max(a, b)
    if flag != (XY[i+1][0] + XY[i+1][1])%2:
        print (-1)
        exit()


m = 0
while a > 1:
    m += 1
    a = a//2


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

if flag == 0: 
    print (len(d) + 1)
    print (' '.join(map(str, [1] + d)))
else: 
    print (len(d))
    print (' '.join(map(str, d)))



def string(X, Y): 
    if (abs(X) + abs(Y))%2 == 0: 
        ans = 'R'
        x = X - 1
        y = Y
    else:
        x, y = X, Y
        ans = str()
    for i in d:
        if abs(x - i) + abs(y) < i:
            ans += 'R'
            x = x - i
        elif abs(x + i) + abs(y) < i:
            ans += 'L'
            x = x + i
        elif abs(x) + abs(y - i) < i:
            ans += 'U'
            y = y - i
        elif abs(x) + abs(y + i) < i:
            ans += 'D'
            y = y + i
    return ans

for i in XY:
    print (string(i[0], i[1]))

Solution (Python):
import numpy as np
N = int(input())
XY = np.array([[int(x) for x in input().split()] for _ in range(N)],dtype=np.int64)
X = XY[:,0]
Y = XY[:,1]
command  = np.array([""]*N,dtype=object)

def solve(k,X,Y,arms,command):
    if k==-1:
        return final_solve(X,Y,arms,command)
    else:
        
        
        bl_X = (np.abs(X)>np.abs(Y))
        bl_Y = ~bl_X
        neg_X = (X<0)
        neg_Y = (Y<0)
        L = bl_X & neg_X
        R = bl_X & (~neg_X)
        U = bl_Y & (~neg_Y)
        D = bl_Y & neg_Y
        p = 1<<k
        command[L] += "L"
        command[R] += "R"
        command[U] += "U"
        command[D] += "D"
        X[L] +=p

        X[R] -=p

        Y[U] -=p

        Y[D] +=p

        arms.append(p)
        return solve(k-1,X,Y,arms,command)
def final_solve(X,Y,arms,command):
    s = np.abs(X)+np.abs(Y)
    b0 = (s==0).all()
    b1 = (s==1).all()
    if b0:
        return arms,command
    elif not b1:
        return None,None

    arms.append(1)
    L = (X==-1)
    R = (X==1)
    D = (Y==-1)
    U = (Y==1)
    command[L] += "L"
    command[R] += "R"
    command[U] += "U"
    command[D] += "D"
    return arms,command


arms,command = solve(35,X,Y,[],command)

if arms is None:
    print(-1)
else:
    print(len(arms))
    print(" ".join([str(i) for i in arms]))
    print("\n".join(command))

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

for i in range(n - 1):
    if (grid[i][0] + grid[i][1]) % 2 != (grid[i + 1][0] + grid[i + 1][1]) % 2:
        print(-1)
        exit()
m = 31
D = [2 ** i for i in range(m)]
if (grid[0][0] + grid[0][1]) % 2 == 0:
    D.insert(0, 1)
    m += 1
w = [[] for i in range(n)]
for i, g in enumerate(grid):
    x, y = g
    for d in D[::-1]:
        if abs(x) >= abs(y):
            if x > 0:
                x -= d
                w[i].append('R')
            else:
                x += d
                w[i].append('L')
        else:
            if y > 0:
                y -= d
                w[i].append('U')
            else:
                y += d
                w[i].append('D')

print(m)
print(*D)
for ans in w:
    print(*ans[::-1], sep='')

Solution (Python):
N = int(input())
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x + y, x - y))
if any(XY[0][0] % 2 != xy[0] % 2 for xy in XY):
    print(-1)
    exit()
odd = XY[0][0] % 2 == 1
if odd:
    d = [2 ** i for i in range(30, -1, -1)]
else:
    d = [2 ** i for i in range(30, -1, -1)] + [1]
print(len(d))
print(*d)
for xpy, xmy in XY:
    s = ""
    p = 0
    m = 0
    for di in d:
        ps = 1 if p <= xpy else -1
        ms = 1 if m <= xmy else -1
        p += ps * di
        m += ms * di
        if ps == 1:
            s += "R" if ms == 1 else "U"
        else:
            s += "D" if ms == 1 else "L"
    print(s)

Solution (Python):
N=int(input())
XY=[]
for i in range(N):
    x,y=map(int,input().split())
    XY.append([x,y])
    if (XY[0][0]+XY[0][1])%2!=(XY[-1][0]+XY[-1][1])%2:
        print(-1)
        quit()
D=[2**i for i in range(31)]
if (XY[0][0]+XY[0][1])%2==0:
    D=[1]+D
print(len(D))
S=sum(D)
for d in D[::-1]:
    print(d,end=" ")
print()
def check(x,y,s):
    if abs(x)+abs(y)<=s:
        return True
    else:
        return False
for x,y in XY:
    s=S
    for d in D[::-1]:
        s-=d
        if check(x-d,y,s):
            print("R",end="")
            x-=d
        elif check(x+d,y,s):
            print("L",end="")
            x+=d
        elif check(x,y+d,s):
            print("D",end="")
            y+=d
        elif check(x,y-d,s):
            print("U",end="")
            y-=d
        else:
            print("WWWWWWWWWWWWWWWWWW")
            quit()
    print()

Solution (Python):
import sys



def f(x, y, i):
    d = 1 << i
    if y > x and y > -x:
        return x, y - d, "U"
    elif y < x and y > -x:
        return x - d, y, "R"
    elif y < x and y < -x:
        return x, y + d, "D"
    else:
        return x + d, y, "L"


N = int(input())
X = []
Y = []
mx = 0
for i in range(N):
    x, y = [int(x) for x in input().split()]
    mx = max(abs(x) + abs(y), mx)
    X.append(x)
    Y.append(y)

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




if s == 0:
    X = [x - 1 for x in X]

D = []
d = 1
while d < mx:
    D.append(d)
    d = d * 2

m = len(D)
print(m if s != 0 else m + 1)
if s == 0:
    D = [1] + D
print(" ".join([str(d) for d in D]))

for i in range(N):
    x, y = X[i], Y[i]
    dirs = []
    for j in range(m - 1, -1, -1):
        x, y, dir = f(x, y, j)
        dirs.append(dir)
    if s == 0:
        dirs.append("R")
    print("".join(dirs[::-1]))

Solution (Python):
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline 
    N = int(file())
    point = [[int(i) for i in file().split()] for j in range(N)]
    length = (point[0][0] + point[0][1]) % 2
    for i in range(1, N):
        if sum(point[i]) % 2 != length:
            print(-1)
            break
    else:
        d = [pow(2, i) for i in range(31)]
        direction = {("0", "0"): "L", ("1","1"): "R", ("0", "1"): "D", ("1", "0"): "U"}
        ans = ""
        add = (0 if length == 1 else 1)
        if add == 1: d.append(1)
        for i in range(N):
            U, V = point[i][0] + point[i][1] + add, point[i][0] - point[i][1] + add
            ubit = format((U + pow(2, 31) - 1)//2, "b").zfill(31)
            vbit = format((V + pow(2, 31) - 1)//2, "b").zfill(31)
            arm = ""
            for j in reversed(range(31)):
                arm += direction[(ubit[j], vbit[j])]
            if add == 1: arm += "L"
            ans += arm + "\n"
        print(len(d))
        print(" ".join(map(str, d)))
        print(ans)

    INF = 10 ** 25
    mod = 7 + 10 ** 9
    return 0
  
if __name__ == "__main__":
    solve()

Solution (Python):
import numpy as np

N = int(input())
XY = np.array([[int(x) for x in input().split()] for _ in range(N)],dtype=np.int64)
X = XY[:,0]
Y = XY[:,1]

command = np.array([''] * N,dtype=object)

def solve(k,X,Y,arms,command):  
  
  
  if k == -1:
    return solve_final(X,Y,arms,command)
  
  bl_X = (np.abs(X) > np.abs(Y))
  bl_Y = ~bl_X
  negative_X = (X < 0)
  negative_Y = (Y < 0)
  L = bl_X & negative_X
  R = bl_X & (~negative_X)
  D = bl_Y & negative_Y
  U = bl_Y & (~negative_Y)
  command[L] += 'L'
  command[R] += 'R'
  command[D] += 'D'
  command[U] += 'U'
  p = (1<<k)
  arms.append(p)
  X[L] += p
  X[R] -= p
  Y[D] += p
  Y[U] -= p
  return solve(k-1,X,Y,arms,command)

def solve_final(X,Y,arms,command):
  s = np.abs(X) + np.abs(Y)
  bl0 = (s == 0).all()
  bl1 = (s == 1).all()
  if bl0:
    return arms,command
  elif not bl1:
    return None,None
  
  arms.append(1)
  L = (X == -1)
  R = (X == 1)
  D = (Y == -1)
  U = (Y == 1)
  command[L] += 'L'
  command[R] += 'R'
  command[D] += 'D'
  command[U] += 'U'
  return arms,command

arms,command = solve(35,X,Y,[],command)

if arms is None:
  print(-1)
else:
  print(len(arms))
  print(' '.join([str(x) for x in arms]))
  print('\n'.join(command))

Solution (Python):
from sys import exit
N = int(input())

Od = True
Ev = True
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    if (x+y) % 2:
        Ev = False
    else:
        Od = False
    XY.append((x, y))

if not Od and not Ev:
    print(-1)
    exit()

ans = [2**i for i in range(31)]
Sig = sum(ans)

if Ev:
    ans = [1] + ans
print(len(ans))
print(*ans)
for x, y in XY:
    if Ev:
        x -= 1
    pl = abs((Sig - (x + y))//2)
    mi = abs((Sig - (x - y))//2)
    RU = [1 if pl & 2**i else 0 for i in range(31)]
    RD = [1 if mi & 2**i else 0 for i in range(31)]
    ans = [None]*31
    for j in range(31):
        if RU[j] and RD[j]:
            ans[j] = 'R'
        elif RD[j] and not RU[j]:
            ans[j] = 'D'
        elif not RD[j] and RU[j]:
            ans[j] = 'U'
        else:
            ans[j] = 'L'
    ans = ''.join(ans)
    xi, yi = 0, 0
    for i, s in enumerate(ans):
        if s == 'U':
            yi += 2**i
        if s == 'D':
            yi -= 2**i
        if s == 'R':
            xi += 2**i
        if s == 'L':
            xi -= 2**i
    if y != yi:
        ans = ans.translate(str.maketrans('UD', 'DU'))
    if x != xi:
        ans = ans.translate(str.maketrans('LR', 'RL'))
    if Ev:
        ans = 'R' + ans
    print(ans)

Solution (Python):
N = int(input())
point = [tuple(map(int, input().split())) for i in range(N)]
point_farthest = max(point, key=lambda p: abs(p[0]) + abs(p[1]))
mod = sum(point_farthest) % 2
D = [1, 1] if mod == 0 else [1]
while sum(D) < abs(point_farthest[0]) + abs(point_farthest[1]):
    D.append(D[-1] * 2)
D.reverse()
W = []
for x, y in point:
    if (x + y) % 2 != mod:
        print(-1)
        exit()
    w = ''
    for d in D:
        if abs(x) >= abs(y):
            if x > 0:
                w += 'R'
                x -= d
            else:
                w += 'L'
                x += d
        else:
            if y > 0:
                w += 'U'
                y -= d
            else:
                w += 'D'
                y += d
    W.append(w)
print(len(D))
print(*D)
print(*W, sep='\n')

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

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


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

print(len(D))
print(' '.join(map(str, D)))
operation = {'R': (-1, 0), 'L': (1, 0), 'U': (0, -1), 'D': (0, 1)}  
for x, y in Points:
    nx, ny = x, y
    ans = ''
    for d in D:
        best_score = float('inf')
        best_command = None
        next_x, next_y = None, None

        for command, move in operation.items():
            mx, my = move
            tx, ty = nx + d * mx, ny + d * my
            score = abs(tx) + abs(ty)
            if score < best_score:
                best_score = score
                best_command = command
                next_x, next_y = tx, ty

        ans += best_command
        nx, ny = next_x, next_y

    print(ans)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





def main():
    n = intin()
    xylist = intinl(n)

    even_odd = None
    uvlist = []

    for x, y in xylist:
        tmp_even_odd = (x + y) % 2

        if even_odd is None:
            even_odd = tmp_even_odd

        if even_odd != tmp_even_odd:
            print(-1)
            return

        uvlist.append((x + y, x - y))

    m = 33 if even_odd else 34

    print(m)
    dlist = [str(2**i) for i in reversed(list(range(0, 33)))]
    if not even_odd:
        dlist.append('1')
    print(' '.join(dlist))

    for u, v in uvlist:

        if not even_odd:
            u += 1
            v += 1
        line = ''

        if u >= 0 and v >= 0:
            line += 'R'
        if u >= 0 and v < 0:
            line += 'U'
        if u < 0 and v >= 0:
            line += 'D'
        if u < 0 and v < 0:
            line += 'L'

        for i in reversed(list(range(1, 33))):
            u_bit = (u >> i) & 1
            v_bit = (v >> i) & 1
            if u_bit and v_bit:
                line += 'R'
            if u_bit and not v_bit:
                line += 'U'
            if not u_bit and v_bit:
                line += 'D'
            if not u_bit and not v_bit:
                line += 'L'

        if not even_odd:
            line += 'L'

        print(line)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

N = int(input())
coord = [tuple(map(int, input().split())) for _ in range(N)]
parity = (coord[0][0] + coord[0][1]) % 2
flag = False
for c in coord[1:]:
    if (c[0] + c[1]) % 2 != parity:
        flag = True
        break
if flag:
    print(-1)
    sys.exit()
D = [2**(31-i) for i in range(32)]
if parity == 0:
    D.append(1)
print(len(D))
print(*D, sep=' ')
for c in coord:
    w = ''
    pos = [0, 0]
    for d in D:
        dif = [c[0] - pos[0], c[1] - pos[1]]
        cands = [(abs(dif[0] - d) + abs(dif[1]), 'R'), (abs(dif[0] + d) + abs(dif[1]), 'L'), (abs(dif[0]) + abs(dif[1] - d), 'U'), (abs(dif[0]) + abs(dif[1] + d), 'D')]
        select = min(cands)
        w += select[1]
        if select[1] == 'R':
            pos[0] += d
        elif select[1] == 'L':
            pos[0] -= d
        elif select[1] == 'U':
            pos[1] += d
        else:
            pos[1] -= d
    print(w)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
XY=[[None] for i in range(N)]
x,y=MAP()
XY[0]=(x, y)
od_ev=(abs(x)+abs(y))%2
for i in range(1, N):
    x,y=MAP()
    
    if od_ev!=(abs(y)+abs(x))%2:
        print(-1)
        exit()
    XY[i]=(x, y)


arms=[]
for i in range(31, -1, -1):
    arms.append(2**i)
if od_ev==0: arms.append(1)
print(len(arms))
print(*arms)

for i in range(N):
    ans=['']*len(arms)
    x,y=XY[i]
    
    u=x+y
    v=x-y
    for j, arm in enumerate(arms):
        
        if u>=0 and v>=0:
            ans[j]='R'
            u-=arm
            v-=arm
        elif u>=0 and v<0:
            ans[j]='U'
            u-=arm
            v+=arm
        elif u<0 and v>=0:
            ans[j]='D'
            u+=arm
            v-=arm
        elif u<0 and v<0:
            ans[j]='L'
            u+=arm
            v+=arm
    print(''.join(ans))

Solution (Python):

def get_check(num, place):
    dist = abs(place[0][0]) + abs(place[0][1])
    check_flg = dist

    for i in range(num - 1):
        dist_now = abs(place[i + 1][0]) + abs(place[i + 1][1])
        if dist % 2 != dist_now % 2:
            check_flg = 0
            break
        if check_flg < dist_now:
            check_flg = dist_now
    return check_flg

def start_process(num, place):

    check_flg = get_check(num, place)
    if check_flg:

        seeds = [2 ** (31 - i) for i in range(32)]
        if check_flg % 2 == 0:
            seeds.append(1)
        print(len(seeds))
        print(' '.join(map(str, seeds)))

        for x, y in place:
            for k in seeds:
                if abs(x) > abs(y):
                    if x > 0:
                        res = 'R'
                        x -= k
                    else:
                        res = 'L'
                        x += k
                else:
                    if y > 0:
                        res = 'U'
                        y -= k
                    else:
                        res = 'D'
                        y += k
                print(res, end='')
            print('')


    else:
        print(-1)


def main():
    num = int(input())
    place = [list(map(int, input().split())) for i in range(num)]
    start_process(num, place)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
xy = [[int(item) for item in input().split()] for _ in range(n)]


mod2 = (xy[0][0] + xy[0][1]) % 2
for x, y in xy:
    if (x + y) % 2 != mod2:
        print(-1)
        exit()

if mod2 == 1:
    print(31)
    print(" ".join([str(2**item) for item in range(31)]))
else:
    print(32)
    print("1 " + " ".join([str(2**item) for item in range(31)]))

for x, y in xy:
    if mod2 == 0:
        x -= 1
        print("R", end="")
    u = x + y
    v = x - y
    bits = [[0] * 31 for _ in range(2)]
    if u < 0:
        bits[0] = [1] * 31
        bits[0][30] = 0
    else:
        bits[0][30] = 1
    if v < 0:
        bits[1] = [1] * 31
        bits[1][30] = 0
    else:
        bits[1][30] = 1
    for i in range(30):
        if u >= 0 and abs(u)//2>>i & 1:
            bits[0][i] = 1
        if u < 0 and abs(u)//2>>i & 1:
            bits[0][i] = 0
        if v >= 0 and abs(v)//2>>i & 1:
            bits[1][i] = 1
        if v < 0 and abs(v)//2>>i & 1:
            bits[1][i] = 0
    for u_b, v_b in zip(bits[0], bits[1]):
        if u_b == 1 and v_b == 1:
            print("R", end="")
        elif u_b == 0 and v_b == 0:
            print("L", end="")
        elif u_b == 1 and v_b == 0:
            print("U", end="")
        elif u_b == 0 and v_b == 1:
            print("D", end="")
    print("")

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


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


def directions_str(fx, fy, tx, ty, arm):
    if fx == tx and fy == ty:
        return ''
    if abs(fx - arm - tx) + abs(fy - ty) < arm:
        return 'L' + directions_str(fx=fx - arm, fy=fy, tx=tx, ty=ty, arm=arm // 2)
    if abs(fx + arm - tx) + abs(fy - ty) < arm:
        return 'R' + directions_str(fx=fx + arm, fy=fy, tx=tx, ty=ty, arm=arm // 2)
    if abs(fx - tx) + abs(fy - arm - ty) < arm:
        return 'D' + directions_str(fx=fx, fy=fy - arm, tx=tx, ty=ty, arm=arm // 2)
    if abs(fx - tx) + abs(fy + arm - ty) < arm:
        return 'U' + directions_str(fx=fx, fy=fy + arm, tx=tx, ty=ty, arm=arm // 2)




arms = []
for n in range(39):
    arms.append(2 ** n)
    if 2 ** n > 10 ** 9:
        break
arms.sort(reverse=True)

if (X[0] + Y[0]) % 2 == 1:
    print(len(arms))
    print(' '.join(map(str, arms)))
    for x, y in zip(X, Y):
        print(directions_str(fx=0, fy=0, tx=x, ty=y, arm=arms[0]))
else:
    arms.append(1)
    print(len(arms))
    print(' '.join(map(str, arms)))
    for x, y in zip(X, Y):
        print(directions_str(fx=0, fy=0, tx=x, ty=y + 1, arm=arms[0]) + 'D')

Solution (Python):
inp = [[int(x) for x in input().split()] for _ in range(int(input()))]
inpsum = sum(map(lambda ij: abs(ij[0]+ij[1]) % 2, inp))
if not (inpsum == len(inp) or inpsum == 0):
    print(-1)
    exit(0)

seeds = ([] if inpsum == len(inp) else [1]) + [1 << i for i in range(0, 32)]


print(len(seeds))
print(' '.join(map(str, reversed(seeds))))

for x, y in inp:
    for k in reversed(seeds):
        res = ''
        if abs(x) > abs(y):
            if x > 0:
                res = 'R'
                x -= k
            else:
                res = 'L'
                x += k
        else:
            if y > 0:
                res = 'U'
                y -= k
            else:
                res = 'D'
                y += k
        
        print(res, end='')
    print('')

Solution (Python):
N = int(input())
XY = [list(map(int, input().split(" "))) for _ in range(N)]
parity = (XY[0][0] + XY[0][1]) % 2
maxXY = 0
for x, y in XY:
    if (x + y) % 2 != parity:
        print("-1")
        exit()
    maxXY = max(x+y, maxXY)
arm = [1, 1, ]
if parity == 1:
    arm[1] = 2

tmp = arm[1]
m = 2

for _ in range(40):
    tmp *= 2
    m += 1
    arm.append(tmp)
    if tmp > maxXY:
        break
print(m)
print(" ".join(map(str, arm)))
armR = arm[::-1]
for x, y in XY:
    nowX, nowY = [x, y]
    ansR = ""
    for l in armR:
        if abs(nowX) >= abs(nowY):
            if nowX >= 0:
                nowX -= l
                ansR += "R"
            else:
                nowX += l
                ansR += "L"
        else:
            if nowY >= 0:
                nowY -= l
                ansR += "U"
            else:
                nowY += l
                ansR += "D"
    print(ansR[::-1])

Solution (Python):
def cal(i,j):
    if i==1 and j==1: return "R"
    elif i==1 and j==0: return "U"
    elif i==0 and j==1: return "D"
    elif i==0 and j==0: return "L"



import sys

N=int(input())


a=[list(map(int,input().split())) for i in range(N)]
mod=sum(a[0])%2
for i in range(N):
    if sum(a[i])%2!=mod:
        print(-1)
        sys.exit()

if mod==0:
    a=[[ a[i][0]-1 ,a[i][1] ] for i in range(N)]

if mod==0:
    print(32)
    print(1,end=" ")
    for i in range(30): print(2**i, end=" ")
    print(2**30)
else:
    print(31)
    for i in range(30): print(2**i, end=" ")
    print(2**30)

for i in range(N):
    [x,y]=a[i]
    u=bin((x+y+2**31-1)//2)[2:].zfill(31)
    v=bin((x-y+2**31-1)//2)[2:].zfill(31)
    
    if mod==0: s="R"
    else: s=""

    for i in range(30,-1,-1): s=s+cal( int(u[i]),int(v[i]) )
    
    print(s)

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



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



Arms = [2 ** i for i in reversed(range(39))]


if (abs(Point[0][0]) + abs(Point[0][1])) % 2 == 0:
    Arms.append(1)



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



for x, y in Point:
    ans = ''
    for length in Arms:
        min_diff, tmp_s = float('inf'), ''
        next_x, next_y = None, None
        for order, dx, dy in (('L', 1, 0), ('R', -1, 0), ('D', 0, 1), ('U', 0, -1)):
            tmp_x, tmp_y = (x + length * dx), (y + length * dy)
            diff = abs(tmp_x) + abs(tmp_y)

            if diff < min_diff:
                min_diff = diff
                tmp_s = order
                next_x, next_y = tmp_x, tmp_y

        ans += tmp_s
        x, y = next_x, next_y
    print(ans)

Solution (Python):
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
mods = [sum(xy) % 2 for xy in XY]
if not(sum(mods) == 0 or sum(mods) == N):
    print(-1)
    quit()

mod = mods[0] % 2
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))