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):
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 = [x[0] + 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.insert(0, 2 ** pow_i)
        pow_i += 1
    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()

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 = [x[0] + 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()

Solution (Python):
N=int(input())
p=[[int(i) for i in input().split()] for i in range(N)]
p_copy=list(p)
p_copy.sort(key=lambda x:x[0]+x[1])
length=abs(p_copy[N-1][0])+abs(p_copy[N-1][1])
if length%2==0:
  edge=[1]
  a=1
  while a<length:
    edge.append(a)
    a=2*a
  edge.reverse()
else:
  edge=[]
  a=1
  while a<length:
    edge.append(a)
    a=2*a
  edge.reverse()
if len(edge)>40 or edge[len(edge)-1]>10**12:
  print(-1)
  exit()
w=[""]*N
for n in range(N):
  x,y=p[n][0],p[n][1]
  if (x+y)%2!=length%2:
    print(-1)
    exit()
  else:
    a,b=0,0
    for e in edge:
      R=abs(x-(a+e))+abs(y-(b))
      L=abs(x-(a-e))+abs(y-(b))
      U=abs(x-(a))+abs(y-(b+e))
      D=abs(x-(a))+abs(y-(b-e))
      if min([R,L,U,D])==R:
        a+=e
        w[n]+="R"
      elif min([R,L,U,D])==L:
        a+=-e
        w[n]+="L"
      elif min([R,L,U,D])==U:
        b+=e
        w[n]+="U"
      else:
        b+=-e
        w[n]+="D"
  
print(len(edge))
map_edge=map(str,edge)
print(" ".join(map_edge))
for n in range(N):
  print(w[n])

Solution (Python):

import math


def binary(n, m):
    lst = []
    while n != 0:
        lst.append(n % 2)
        n = n // 2
    lst = lst + [0] * (m - len(lst))
    return list(reversed(lst))


def calc(u, v, m):
    result = ""
    u_binary = binary(u, m)
    v_binary = binary(v, m)
    for i in range(m):
        if u_binary[i] == 1 and v_binary[i] == 1:
            result += "R"
        elif u_binary[i] == 0 and v_binary[i] == 0:
            result += "L"
        elif u_binary[i] == 1 and v_binary[i] == 0:
            result += "U"
        else:
            result += "D"
    return result


U = []
V = []
N = int(input())
even, odd = 0, 0
M = 0
for p in range(N):
    x, y = map(int, input().split())
    u = x + y
    v = x - y
    U.append(u)
    V.append(v)
    M = max(M, abs(u), abs(v))
    if (x + y) % 2 == 0:
        even += 1
    else:
        odd += 1

if even >= 1 and odd >= 1:
    print(-1)

else:
    m = math.floor(math.log2(M)) + 1 if M != 0 else 1
    lst = [2 ** i for i in range(m-1, -1, -1)]
    if odd == 0:
        lst.append(1)
    print(len(lst))
    print(" ".join(map(str, lst)))
    for u, v in zip(U, V):
        u = (u + 2 ** m - 1) // 2
        v = (v + 2 ** m - 1) // 2
        print(calc(u, v, m)+"R" if odd == 0 else calc(u, v, m))

Solution (Python):

import math


def binary(n):
    lst = []
    while n != 0:
        lst.append(n % 2)
        n = n // 2
    lst = lst + [0] * (31 - len(lst))
    return list(reversed(lst))


def calc(u, v):
    result = ""
    u_binary = binary(u)
    v_binary = binary(v)
    for i in range(31):
        if u_binary[i] == 1 and v_binary[i] == 1:
            result += "R"
        elif u_binary[i] == 0 and v_binary[i] == 0:
            result += "L"
        elif u_binary[i] == 1 and v_binary[i] == 0:
            result += "U"
        else:
            result += "D"
    return result


U = []
V = []
N = int(input())
even, odd = 0, 0

for p in range(N):
    x, y = map(int, input().split())
    U.append(x+y)
    V.append(x-y)
    if (x + y) % 2 == 0:
        even += 1
    else:
        odd += 1

if even >= 1 and odd >= 1:
    print(-1)

else:
    lst = [2 ** i for i in range(30, -1, -1)]
    if odd == 0:
        lst.append(1)
    print(len(lst))
    print(" ".join(map(str, lst)))
    for u, v in zip(U, V):
        u = (u + 2 ** 31 - 1) // 2
        v = (v + 2 ** 31 - 1) // 2
        print(calc(u, v)+"R" if odd == 0 else calc(u, v))

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


def calc(x, y):
    nowx, nowy = 0, 0
    t = ""
    for i in range(30, -1, -1):
        if nowx < x:
            nowx += 2 ** i
            p = 1
        else:
            nowx -= 2 ** i
            p = -1

        if nowy < y:
            nowy += 2 ** i
            q = 1
        else:
            nowy -= 2 ** i
            q = -1

        if p == 1 and q == 1:
            t += "R"
        elif p == 1 and q == -1:
            t += "U"
        elif p == -1 and q == 1:
            t += "D"
        else:
            t += "L"

    return t


if even >= 1 and odd >= 1:
    print(-1)
    exit()

else:
    d = [2 ** i for i in range(30, -1, -1)]
    if even == 0:
        print(31)
        print(" ".join(map(str, d)))
        for i in range(N):
            print(calc(X[i] + Y[i], X[i] - Y[i]))

    else:
        print(32)
        d.append(1)
        print(" ".join(map(str, d)))
        for i in range(N):
            print(calc(X[i] + Y[i] - 1, X[i] - Y[i] - 1) + "R")

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def func(X, Y, D):
    ans = ""
    x, y = 0, 0
    for i in range(len(D)):
        d = D[i]

        best_j = 0
        best = INF
        for j in range(4):
            nx, ny = x + dx4[j] * d - X, y + dy4[j] * d - Y
            if abs(nx) + abs(ny) < best:
                best = abs(nx) + abs(ny)
                best_j = j

        x, y = x + dx4[best_j] * d, y + dy4[best_j] * d
        ans += "RULD"[best_j]

    assert(x == X and y == Y)
    return ans


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

    for i in range(len(points) - 1):
        x1, y1 = points[i]
        x2, y2 = points[i + 1]
        if (x1 + y1) % 2 != (x2 + y2) % 2:
            print("-1")
            return

    D = [2 ** i for i in range(33)][::-1]
    if sum(points[0]) % 2 == 0:
        D.append(1)

    print(len(D))
    print(*D)

    for x, y in points:
        print(func(x, y, D))


if __name__ == '__main__':
    main()

Solution (Python):
import sys

N = int(input())
XY = [[int(_) for _ in input().split()] for i in range(N)]

mc = [0, 0]
maxl = 0

for x, y in XY:
    l = abs(x) + abs(y)
    maxl = max(maxl, l)
    mc[l % 2] += 1

if mc[0] > 0 and mc[1] > 0:
    print(-1)
    sys.exit()

def calc(sx, sy, ex, ey, d):
    dx, dy = ex - sx, ey - sy
    if dx > dy:
        if dx > -dy:
            return "R", sx + d, sy
        else:
            return "D", sx, sy - d
    else:
        if dx > -dy:
            return "U", sx, sy + d
        else:
            return "L", sx - d, sy

import math

l = math.ceil(math.log(maxl + 1, 2))

ms = [1 << i for i in range(l)][::-1]

rms = ms

if mc[0] > 0:
    rms = [1] + ms

print(len(rms))
print(*rms)

for ex, ey in XY:
    x, y = 0, 0
    w = ""
    if mc[0] > 0:
        w = "R"
        x += 1
    for m in ms:
        d, x, y = calc(x, y, ex, ey, m)
        w += d
    print(w)

Solution (Python):
def solution(x,y):
    ans = ''
    nowx, nowy = 0,0
    preX = [0]*31
    preY = [0]*31
    for i in range(31):
        if nowx < x:
            nowx += 2**(30-i)
            preX[i] = 1
        else:
            nowx -= 2**(30-i)
            preX[i] = -1
        if nowy < y:
            nowy += 2**(30-i)
            preY[i] = 1
        else:
            nowy -= 2**(30-i)
            preY[i] = -1
    for i in range(31):
        if preX[i] == -1 and preY[i] == -1:
            ans += 'L'
        elif preX[i] == 1 and preY[i] == 1:
            ans += 'R'
        elif preX[i] == -1 and preY[i] == 1:
            ans += 'D'
        else:
            ans += 'U'
    return ans
N = int( input())
X = [0]*N
Y = [0]*N
x, y = map( int, input().split())
X[0] = x
Y[0] = y
evod = (x+y)%2
Flag = True
for i in range(1,N):
    x, y = map( int, input().split())
    X[i] = x
    Y[i] = y
    if (x+y)%2 != evod:
        Flag = False

if Flag:
    D = [2**i for i in range(30,-1,-1)]
    if evod == 1:
        print(31)
        print(' '.join(map(str,D)))
        for i in range(N):
            print( solution(X[i]+Y[i],X[i]-Y[i]))
    else:
        print(32)
        D.append(1)
        print(' '.join(map(str,D)))
        for i in range(N):
            print( solution(X[i]+Y[i]-1,X[i]-1-Y[i]) + 'R')
else:
    print(-1)

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


tmp = set()
for X, Y in Q:
    tmp.add((X + Y) % 2)
if len(tmp) != 1:
    print(-1)
    exit()


D = [2 ** i for i in range(30, -1, -1)]


if 0 in tmp:
    D.append(1)


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

move = [(1, 0, "R"), (-1, 0, "L"), (0, 1, "U"), (0, -1, "D")]
for X, Y in Q:
    nx, ny = 0, 0
    ans = ""
    for d in D:
        tmp_move_ans = ""
        tmp_move = None
        min_move_cost = float('inf')
        for mx, my, s in move:
            cost = abs(nx + mx * d - X) + abs(ny + my * d - Y)
            if cost < min_move_cost:
                tmp_move_ans = s
                min_move_cost = cost
                tmp_move_x = mx
                tmp_move_y = my

        ans += tmp_move_ans
        nx, ny = nx + tmp_move_x * d, ny + tmp_move_y * d
    print(ans)

Solution (Python):


import sys
input = sys.stdin.readline
INF = float('inf')


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


def move_uv(x, y):
    ut = x + y
    vt = x - y
    command = ''
    u, v = 0, 0
    for i in range(len(D)):
        if u <= ut and v <= vt:
            command += 'R'
            u += D[i]
            v += D[i]
        elif u <= ut and v > vt:
            command += 'U'
            u += D[i]
            v -= D[i]
        elif u > ut and v <= vt:
            command += 'D'
            u -= D[i]
            v += D[i]
        else:
            command += 'L'
            u -= D[i]
            v -= D[i]

    return command


N = int(input())
point = []
max_length = 0
for i in range(N):
    x, y = inpl()
    max_length = max(max_length, abs(x) + abs(y))
    point.append([x, y])

parity = sum(point[0]) % 2
judge = True
for p in point:
    if parity ^ sum(p) % 2:
        judge = False
        break

if not judge:
    print(-1)
else:
    D = [2 ** i for i in range(len(bin(max_length)) - 1)]
    D.reverse()

    
    if parity == 0:
        D.append(1)
    print(len(D))
    print(' '.join(map(str, D)))
    for i in range(N):
        print(move_uv(point[i][0], point[i][1]))

Solution (Python):
n = int(input())
p,d = [],[]
for _ in range(n):
	x,y = (int(i) for i in input().split())
	p.append((x,y))
a = sum(p[0])%2
def f(i,j):
	s,s2,ans = bin((i+j+2**31-1)//2)[::-1][:-2],bin((i-j+2**31-1)//2)[::-1][:-2],""
	s,s2 = s+(31-len(s))*"0",s2+(31-len(s2))*"0"
	for i in range(31):
		if s[i]==s2[i]=="0": ans+="L"
		elif s[i]==s2[i]=="1": ans+="R"
		elif int(s[i]): ans+="U"
		else: ans+="D"
	return ans
if any(a!=sum(p[i])%2 for i in range(n)): print(-1)
else:
	if a-1: d.append("1")
	print(32-a)
	for i in range(31): d.append(str(2**i))
	print(" ".join(d))
	if a:
		for i,j in p: print(f(i,j))
	else:
		for i,j in p: print("R"+f(i-1,j))

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

mod = (xy[0][0] + xy[0][1]) % 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))

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 += "U"
            y -= d
        elif x-y >= 0 and x+y < 0:
            w += "D"
            y += d
        else:
            w += "L"
            x += d
    print(w)

Solution (Python):
def main():
    """
    ロボットアーム

    腕、関節
        arm_1, arm_2,...,arm_m
    k_0,  k_1,   k_2,...,  k_m

    k_i-1, arm_i, k_i
    arm_i_length: d_i

    mode: L, R, D, U

        (x0, y0) = (0, 0)
        L: (x_i, y_i) = (x_i-1 - d_i, y_i-1)
        R: (x_i, y_i) = (x_i-1 + d_i, y_i-1)
        U: (x_i, y_i) = (x_i-1,       y_i-1 - d_i)
        D: (x_i, y_i) = (x_i-1,       y_i-1 + d_i)

    input:
            1 <= N  <= 10^3
        -10^9 <= Xi <= 10^9
        -10^9 <= Yi <= 10^9

    output:
        NG: -1
        OK:

        m
        d1 d2 ... dm
        w1
        w2
        ...
        wN

        1 <= m   <= 40
        1 <= d_i <= 10^12
        w_i: {L, R, U, D}, w_i_lenght = m

    動かし方の例は、入力例1参照
    """
    N = int(input())
    X, Y = zip(*(
        map(int, input().split())
        for _ in range(N)
    ))

    
    m, d, w = ref(N, X, Y)

    if m == -1:
        print(-1)
    else:
        print(m)
        print(*d)
        print(*w, sep="\n")


def ex1(N, X, Y):
    m = 2
    d = [1, 2]
    w = ["RL", "UU", "DR"]
    return m, d, w


def part_300(N, X, Y):
    """
    1つ1つのクエリに対する操作は独立
    ただし、使うパラメータm, d は共通

    部分点は以下の制約
       -10 <= i <= 10
       -10 <= i <= 10

    探索範囲
        20 * 20
        この範囲においてm<=40で到達するためのd
    d=1のとき|X|+|Y|の偶奇
        揃っている場合、mは最大に合わせる、余っているときはRLのように移動なしにできる
        揃っていない場合, d=1では不可能？
        2と1およびLR,UDを駆使して-1を再現して偶奇を揃える?
            無理っぽい: 奇数しか作れない
    """
    dists = []
    for x, y in zip(X, Y):
        dist = abs(x) + abs(y)
        dists.append(dist)

    m = -1
    d = []
    w = []
    mod = list(map(lambda x: x % 2, dists))
    if len(set(mod)) == 1:
        m = max(dists)
        d = [1] * m
        for x, y, dist in zip(X, Y, dists):
            x_dir = "R" if x > 0 else "L"
            y_dir = "U" if y > 0 else "D"

            _w = x_dir * abs(x) + y_dir * abs(y)
            rest = m - len(_w)
            if rest > 0:
                _w += "LR" * (rest // 2)
            w.append(_w)

    return m, d, w


def editorial(N, X, Y):
    """
    2冪の数の組合せにより、どの点にでも移動できるようになる
        ※ただし、奇数のみ。偶数に対応させたいときは１での移動を追加する

      1,   2,   4,   8,
    2^0, 2^1, 2^2, 2^3, ...

    {1} だけでの移動、原点からの1の距離。当たり前
    x: 原点
            b
    -------cxa------
            d

    {1, 2} での移動、原点から1の距離から2移動できる
    a-d を基準に考えると
        a-d をa方向に2移動: a方向に菱形の移動範囲が増える
        a-d をb方向に2移動: b
        a-d をc方向に2移動: c
        a-d をd方向に2移動: d
            b
           b b
          c b a
         c cxa a
          c d a
           d d
            d

    https://twitter.com/CuriousFairy315/status/1046073372315209728
    https://twitter.com/schwarzahl/status/1046031849221316608
    どうして(u, v)=(x+y, x-y)的な変換を施す必要があるのか？
        https://twitter.com/ILoveTw1tter/status/1046062363831660544
        http://drken1215.hatenablog.com/entry/2018/09/30/002900
             x 座標, y 座標両方頑張ろうと思うと、60 個くらい欲しくなる。で、困っていた。

         U
         |
    L----o----R
         |
         D

    
      U＼        ／R
         ＼    ／
           ＼／
           ／ ＼
         ／     ＼
      L／         ＼D
    """
    pass


def ref(N, X, Y):
    dists = []
    for x, y in zip(X, Y):
        dist = (abs(x) + abs(y)) % 2
        dists.append(dist)

    m = -1
    d = []
    w = []
    mod = set(map(lambda x: x % 2, dists))
    if len(mod) != 1:
        return m, d, w

    for i in range(30, 0-1, -1):
        d.append(1 << i)
    if 0 in mod:
        d.append(1)
    m = len(d)

    w1 = transform_xy(N, X, Y, d)
    
    

    return m, d, w1


def transform_xy(N, X, Y, d):
    """
    http://kagamiz.hatenablog.com/entry/2014/12/21/213931
    """
    
    trans_x = []
    trans_y = []
    for x, y in zip(X, Y):
        trans_x.append(x + y)
        trans_y.append(x - y)

    plot = False
    if plot:
        import matplotlib.pyplot as plt

        plt.axhline(0, linestyle="--")
        plt.axvline(0, linestyle="--")

        
        deno = 2 ** 0.5
        plt.scatter(X, Y, label="src")
        plt.scatter([x / deno for x in trans_x],
                    [y / deno for y in trans_y],
                    label="trans")

        for x, y, x_src, y_src in zip(trans_x, trans_y, X, Y):
            plt.text(x_src, y_src, str((x_src, y_src)))
            plt.text(x / deno, y / deno, str((x_src, y_src)))

        plt.legend()
        plt.show()

    
    

    w = []
    dirs = {
        
        (-1, -1): "L",  
        (+1, +1): "R",  
        
        (+1, -1): "U",  
        (-1, +1): "D",  
    }
    for x, y in zip(trans_x, trans_y):
        x_sum = 0
        y_sum = 0
        _w = ""
        for _d in d:
            
            if x_sum <= x:
                x_dir = 1
                x_sum += _d
            else:
                x_dir = -1
                x_sum -= _d

            if y_sum <= y:
                y_dir = 1
                y_sum += _d
            else:
                y_dir = -1
                y_sum -= _d

            _w += dirs[(x_dir, y_dir)]

        w.append(_w)

    return w


def no_transform_xy(N, X, Y, d):
    w = []
    for x, y in zip(X, Y):
        x_sum, y_sum = 0, 0
        _w = ""
        for _d in d:
            
            if abs(x_sum - x) >= abs(y_sum - y):
                if x_sum >= x:
                    x_sum -= _d
                    _w += "L"
                else:
                    x_sum += _d
                    _w += "R"
            else:
                if y_sum >= y:
                    y_sum -= _d
                    _w += "D"
                else:
                    y_sum += _d
                    _w += "U"

        w.append(_w)

    return w


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    """
    ロボットアーム

    腕、関節
        arm_1, arm_2,...,arm_m
    k_0,  k_1,   k_2,...,  k_m

    k_i-1, arm_i, k_i
    arm_i_length: d_i

    mode: L, R, D, U

        (x0, y0) = (0, 0)
        L: (x_i, y_i) = (x_i-1 - d_i, y_i-1)
        R: (x_i, y_i) = (x_i-1 + d_i, y_i-1)
        U: (x_i, y_i) = (x_i-1,       y_i-1 - d_i)
        D: (x_i, y_i) = (x_i-1,       y_i-1 + d_i)

    input:
            1 <= N  <= 10^3
        -10^9 <= Xi <= 10^9
        -10^9 <= Yi <= 10^9

    output:
        NG: -1
        OK:

        m
        d1 d2 ... dm
        w1
        w2
        ...
        wN

        1 <= m   <= 40
        1 <= d_i <= 10^12
        w_i: {L, R, U, D}, w_i_lenght = m

    動かし方の例は、入力例1参照
    """
    N = int(input())
    X, Y = zip(*(
        map(int, input().split())
        for _ in range(N)
    ))

    
    m, d, w = ref(N, X, Y)

    if m == -1:
        print(-1)
    else:
        print(m)
        print(*d)
        print(*w, sep="\n")


def ex1(N, X, Y):
    m = 2
    d = [1, 2]
    w = ["RL", "UU", "DR"]
    return m, d, w


def part_300(N, X, Y):
    """
    1つ1つのクエリに対する操作は独立
    ただし、使うパラメータm, d は共通

    部分点は以下の制約
       -10 <= i <= 10
       -10 <= i <= 10

    探索範囲
        20 * 20
        この範囲においてm<=40で到達するためのd
    d=1のとき|X|+|Y|の偶奇
        揃っている場合、mは最大に合わせる、余っているときはRLのように移動なしにできる
        揃っていない場合, d=1では不可能？
        2と1およびLR,UDを駆使して-1を再現して偶奇を揃える?
            無理っぽい: 奇数しか作れない
    """
    dists = []
    for x, y in zip(X, Y):
        dist = abs(x) + abs(y)
        dists.append(dist)

    m = -1
    d = []
    w = []
    mod = list(map(lambda x: x % 2, dists))
    if len(set(mod)) == 1:
        m = max(dists)
        d = [1] * m
        for x, y, dist in zip(X, Y, dists):
            x_dir = "R" if x > 0 else "L"
            y_dir = "U" if y > 0 else "D"

            _w = x_dir * abs(x) + y_dir * abs(y)
            rest = m - len(_w)
            if rest > 0:
                _w += "LR" * (rest // 2)
            w.append(_w)

    return m, d, w


def editorial(N, X, Y):
    """
    2冪の数の組合せにより、どの点にでも移動できるようになる
        ※ただし、奇数のみ。偶数に対応させたいときは１での移動を追加する

      1,   2,   4,   8,
    2^0, 2^1, 2^2, 2^3, ...

    {1} だけでの移動、原点からの1の距離。当たり前
    x: 原点
            b
    -------cxa------
            d

    {1, 2} での移動、原点から1の距離から2移動できる
    a-d を基準に考えると
        a-d をa方向に2移動: a方向に菱形の移動範囲が増える
        a-d をb方向に2移動: b
        a-d をc方向に2移動: c
        a-d をd方向に2移動: d
            b
           b b
          c b a
         c cxa a
          c d a
           d d
            d

    https://twitter.com/CuriousFairy315/status/1046073372315209728
    https://twitter.com/schwarzahl/status/1046031849221316608
    どうして(u, v)=(x+y, x-y)的な変換を施す必要があるのか？
        https://twitter.com/ILoveTw1tter/status/1046062363831660544
        http://drken1215.hatenablog.com/entry/2018/09/30/002900
             x 座標, y 座標両方頑張ろうと思うと、60 個くらい欲しくなる。で、困っていた。


         U
         |
    L----o----R
         |
         D

      U＼        ／R
         ＼    ／
           ＼／
           ／ ＼
         ／     ＼
      L／         ＼D
    """
    pass


def ref(N, X, Y):
    dists = []
    for x, y in zip(X, Y):
        dist = (abs(x) + abs(y)) % 2
        dists.append(dist)

    m = -1
    d = []
    w = []
    mod = set(map(lambda x: x % 2, dists))
    if len(mod) != 1:
        return m, d, w

    for i in range(30, 0-1, -1):
        d.append(1 << i)
    if 0 in mod:
        d.append(1)
    m = len(d)

    
    w = no_transform_xy(N, X, Y, d)
    

    return m, d, w


def transform_xy(N, X, Y, d):
    w = []
    dirs = {
        
        (-1, -1): "L",  
        (+1, +1): "R",  
        (+1, -1): "U",  
        (-1, +1): "D",  
    }
    for x, y in zip(X, Y):
        x_sum = 0
        y_sum = 0
        _w = ""
        for _d in d:
            
            if x_sum <= x:
                x_dir = 1
                x_sum += _d
            else:
                x_dir = -1
                x_sum -= _d

            if y_sum <= y:
                y_dir = 1
                y_sum += _d
            else:
                y_dir = -1
                y_sum -= _d

            _w += dirs[(x_dir, y_dir)]

        w.append(_w)

    return w


def no_transform_xy(N, X, Y, d):
    w = []
    for xt, yt in zip(X, Y):
        x, y = 0, 0
        _w = ""
        for _d in d:
            if abs(x - xt) >= abs(y - yt):
                if x >= xt:
                    x -= _d
                    _w += "L"
                else:
                    x += _d
                    _w += "R"
            else:
                if y >= yt:
                    y -= _d
                    _w += "D"
                else:
                    y += _d
                    _w += "U"

        w.append(_w)

    return w


if __name__ == '__main__':
    main()

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 += "U"
            y -= d
        elif x-y >= 0 and x+y < 0:
            w += "D"
            y += d
        else:
            w += "L"
            x += d
    print(w)

Solution (Python):
import sys



def 解():
    iN = int(input())
    aP = [[int(_) for _ in sLine.rstrip("\n").split()] for sLine in sys.stdin.readlines()]

    iMod = sum(aP[0]) % 2
    for i in range(1,iN):
        if sum(aP[i]) % 2 != iMod :
            print("-1")
            exit()

    i最遠 = max([ abs(iX)+abs(iY) for iX , iY in aP])

    a腕 = [1]
    if iMod == 0 :
        a腕 = [1,1]

    for i in range(32):
        a腕.append(a腕[-1] * 2)
        if i最遠 // 2 < a腕[-1]:
            break

    a腕.reverse()
    iLen腕 = len(a腕)
    aRet = []
    for iX,iY in aP:
        aCommand=[]
        for i in range(iLen腕):
            if abs(iX) > abs(iY):
                if iX < 0 :
                    iX += a腕[i]
                    aCommand.append("L")
                else:
                    iX -= a腕[i]
                    aCommand.append("R")
            else:
                if iY < 0 :
                    iY += a腕[i]
                    aCommand.append("D")
                else:
                    iY -= a腕[i]
                    aCommand.append("U")
        aRet.append("".join(aCommand))

    print(iLen腕)
    print(" ".join([str(_) for _ in a腕]))
    sys.stdout.write("\n".join(aRet) + "\n")

if __name__ == '__main__':
    解()