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

Solution (Python):









def solve(N, XY):
    tmp = 0
    for x, y in XY:
        tmp += (abs(x) + abs(y)) % 2
    if tmp % N != 0:
        print(-1)
        return
    import math
    m = math.ceil(math.log2(2 * 10 ** 9)) + 1
    d = [2 ** (m - i) for i in range(m)] + [1]
    d += [1] if tmp == 0 else []
    m = len(d)
    w = []
    for xi, yi in XY:
        xx = 0
        yy = 0
        W = ''
        for di in d:
            if abs(xi - xx) >= abs(yi - yy):
                if xx <= xi:
                    xx += di
                    W += 'R'
                else:
                    xx -= di
                    W += 'L'
            else:
                if yy <= yi:
                    yy += di
                    W += 'U'
                else:
                    yy -= di
                    W += 'D'
        w.append(W)
    print(m)
    print(' '.join([str(i) for i in d]))
    [print(wi) for wi in w]


if __name__ == '__main__':
    
    N = int(input())
    
    
    
    XY = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, XY)

Solution (Python):
n,*t=map(int,open(0).read().split())
*z,=zip(t[::2],t[1::2])
s=set((a+b)%2for a,b in z)
if len(s)>1:
    print(-1)
    exit()
s,*_=s
d=[2**(38-i)for i in range(39)]+[1]*(s<1)
print(len(d))
print(*d)
for a,b in z:
    x=y=0
    for i in d:
        if abs(a-x)>abs(b-y):
            if a-x>0:
                print('R',end='')
                x+=i
            else:
                print('L',end='')
                x-=i
        else:
            if b-y>0:
                print('U',end='')
                y+=i
            else:
                print('D',end='')
                y-=i
    print()

Solution (Python):
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
  if(abs(x[i])+abs(y[i]))%2!=(abs(x[0])+abs(y[0]))%2:
    print(-1)
    exit()
D=[]
for i in reversed(range(33)):D.append(1<<i)
D+=[1,1]
if(abs(x[0])+abs(y[0]))%2==0:D.append(1)
print(len(D))
print(*D)
for i in range(n):
  X,Y=x[i],y[i]
  s=''
  for d in D:
    if abs(X)>abs(Y):
      if X>0:
        X-=d
        s+='R'
      else:
        X+=d
        s+='L'
    else:
      if Y>0:
        Y-=d
        s+='U'
      else:
        Y+=d
        s+='D'
  
  print(s)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()



A,B = [],[]
for i in range(N):
    x,y = MI()
    if i == 0:
        A.append(x-y)
        B.append(x+y)
        r = (x-y) % 2
    else:
        if (x-y) % 2 != r:
            print(-1)
            exit()
        A.append(x-y)
        B.append(x+y)

if r == 1:
    ANS = [[''] * 31 for _ in range(N)]
    for i in range(N):
        a, b = A[i], B[i]
        for j in range(30, -1, -1):
            if a > 0 and b > 0:
                a -= 2 ** j
                b -= 2 ** j
                ANS[i][j] = 'R'
            elif a > 0 and b < 0:
                a -= 2 ** j
                b += 2 ** j
                ANS[i][j] = 'D'
            elif a < 0 and b > 0:
                a += 2 ** j
                b -= 2 ** j
                ANS[i][j] = 'U'
            else:
                a += 2 ** j
                b += 2 ** j
                ANS[i][j] = 'L'
    print(31)
    print(*[2 ** i for i in range(31)])
    for i in range(N):
        print(''.join(ANS[i]))

else:
    ANS = [[''] * 31 + ['R'] for _ in range(N)]
    for i in range(N):
        a, b = A[i] - 1, B[i] - 1
        for j in range(30, -1, -1):
            if a > 0 and b > 0:
                a -= 2 ** j
                b -= 2 ** j
                ANS[i][j] = 'R'
            elif a > 0 and b < 0:
                a -= 2 ** j
                b += 2 ** j
                ANS[i][j] = 'D'
            elif a < 0 and b > 0:
                a += 2 ** j
                b -= 2 ** j
                ANS[i][j] = 'U'
            else:
                a += 2 ** j
                b += 2 ** j
                ANS[i][j] = 'L'
    print(32)
    print(*([2 ** i for i in range(31)] + [1]))
    for i in range(N):
        print(''.join(ANS[i]))

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

def parity():
  res=sum(xy[0])%2
  for x,y in xy:
    if (x+y)%2!=res:
      return -1
  return res
 
p=parity()
if p==-1:
  print(-1)
  exit()

dd=[1]
if p==0:dd.append(1)
lim=10**12
while len(dd)<40 and dd[-1]*2<=lim:
    dd.append(dd[-1]*2)
print(40)
print(*dd)
 
for x,y in xy:
  ans=""
  for d in dd[::-1]:
    if abs(x)>abs(y):
      if x>0:
        x-=d
        ans+="R"
      else:
        x+=d
        ans+="L"
    else:
      if y>0:
        y-=d
        ans+="U"
      else:
        y+=d
        ans+="D"
  print(ans[::-1])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def parity():
    res=sum(xy[0])%2
    for x,y in xy:
        if (x+y)%2!=res:return -1
    return res

n=II()
xy=LLI(n)

p=parity()
if p==-1:
    print(-1)
    exit()

dd=[1]
if p==0:dd.append(1)
lim=10**12
while len(dd)<40 and dd[-1]*2<=lim:
    dd.append(dd[-1]*2)
print(40)
print(*dd)

for x,y in xy:
    ans=""
    for d in dd[::-1]:
        if abs(x)>abs(y):
            if x>0:
                x-=d
                ans+="R"
            else:
                x+=d
                ans+="L"
        else:
            if y>0:
                y-=d
                ans+="U"
            else:
                y+=d
                ans+="D"
    print(ans[::-1])

Solution (Python):
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
p = x[0] + y[0] & 1
for i in range(n):
    if x[i] + y[i] & 1 != p:
        print(-1)
        exit()
d = ([1] if p == 0 else []) + [2 ** i for i in range(39)]
print(len(d))
print(*d)

dx = [1,0,-1,0]
dy = [0,1,0,-1]
ch = 'LDRU'

for i in range(n):
    s, t = x[i], y[i]
    ans = []
    now = 2 ** 38
    for _ in range(len(d)):
        min_cur = 10 ** 18
        for i in range(4):
            ts, tt = s + dx[i] * now, t + dy[i] * now
            tm = abs(ts) + abs(tt)
            if tm < min_cur:
                ns, nt = ts, tt
                nc = ch[i]
                min_cur = tm
        s, t = ns, nt
        ans.append(nc)
        now = now // 2 if now > 1 else 1
    print(''.join(reversed(ans)))

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

m = [0]*2
for i,j in l:
    m[(i+j)%2] += 1
if m[0]*m[1]>0:
    print(-1)
    exit()

if m[1]>0:
    arm = [2**i for i in range(32)]
else:
    arm = [1]+[2**i for i in range(32)]

print(len(arm))
print(*arm)
for x,y in l:
    ans = []
    nx = x
    ny = y
    for i in arm[::-1]:
        if abs(nx) >= abs(ny):
            if nx >= 0:
                ans.append("R")
                nx -= i
            else:
                ans.append("L")
                nx += i
        else:
            if ny >= 0:
                ans.append("U")
                ny -= i
            else:
                ans.append("D")
                ny += i
    
    print(*ans[::-1],sep="")

Solution (Python):

import sys
input = sys.stdin.readline









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


p = set()
for i in range(N):
    p.add((XY[i][0] + XY[i][1]) % 2)
if len(p) > 1:
    print(-1)
    sys.exit()



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


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

Ans = []

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


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

else:
    print(len(D))
    print(" ".join(map(str,D)))
    for ans in Ans:
        print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def direction_odd(x, y, m):
    """
    m本の腕で(0, 0)から(x, y)に移動する手順を出力する（x + yは奇数を想定）
    """
    ans = ""
    for i in range(m - 1, -1, -1):
        if y < x and y > -x:
            ans += "R"
            x -= 2 ** i
        elif y > x and y > -x:
            ans += "U"
            y -= 2 ** i
        elif y > x and y < -x:
            ans += "L"
            x += 2 ** i
        elif y < x and y < -x:
            ans += "D"
            y += 2 ** i
    return ans

def direction_even(x, y, m):
    if y <= x and y >= -x:
        last = "R"
        x -= 1
    elif y >= x and y >= -x:
        last = "U"
        y -= 1
    elif y >= x and y <= -x:
        last = "L"
        x += 1
    elif y <= x and y <= -x:
        last = "D"
        y += 1
    ans = direction_odd(x, y, m)
    return ans + last


def main():
    N = int(input())
    joint = []
    for _ in range(N):
        x, y = map(int, input().split())
        joint.append((x, y))
    
    """
    まず移動可能な頂点の１つを(x, y)として、(x, y)は\pm (dx, dy)の総和として求まるので
    mod 2でx+yは到着可能な位置に依らず不変量になる。
    なので到着したい位置N子に対してx+yの偶奇がすべて一致するかをまずチェックすれば、それで
    答えが-1になるケースは正答できる。

    問題はこの偶奇がすべて一致している場合だが、実はその場合は必ず題を満たすロボットアームが作れる。
    まず直感として最初に長い腕で移動してからだんだん長さの短い腕で微調整すればよさそうである。
    これを２べきにそろえると、なんと到着可能点がぴったり市松模様になる！！！
    """

    even_odd = {0: 0, 1: 0}
    sum_max = 0
    for x, y in joint:
        even_odd[(x + y) % 2] += 1
        sum_max = max(sum_max, abs(x) + abs(y))
    if even_odd[0] > 0 and even_odd[1] > 0:
        print(-1)
        return

    m = 0
    while (2 ** m - 1 < sum_max): m += 1
    arms = [2 ** i for i in range(m - 1, -1, -1)]
    if even_odd[0] == 0:
        print(m)
        print(" ".join(map(str, arms)))
        for x, y in joint: print(direction_odd(x, y, m))
    if even_odd[0] != 0:
        print(m + 1)
        print(" ".join(map(str, arms)) + " 1")
        for x, y in joint: print(direction_even(x, y, m))
    

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
m=39
ans=[]
if sum(xy[0])%2==0:ans.append(1)
for i in range(m):
    ans.append(2**i)
c=sum(xy[0])%2
for x,y in xy:
    if (x+y)%2!=c:exit(print(-1))
print(len(ans))
print(*ans[::-1])
def chk(s):
    a=[]
    for d in ans[::-1]:
        if abs(s-d)<abs(s+d):
            a.append(-1)
            s-=d
        else:
            a.append(1)
            s+=d
    return a
xpy,xmy=[],[]
for x,y in xy:
    xpy=chk(x+y)
    xmy=chk(x-y)
    s=[]
    for p,m in zip(xpy,xmy):
        if p==1 and m==1:s.append('L')
        if p==-1 and m==-1:s.append('R')
        if p==1 and m==-1:s.append('D')
        if p==-1 and m==1:s.append('U')
    print(*s,sep='')

Solution (Python):
import sys
import itertools
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
c = ['R', 'U', 'L', 'D']
n = int(input())
x = []
y = []
for i in range(n):
  xi, yi = map(int, input().split())
  x.append(xi)
  y.append(yi)
parity = None
for i in range(n):
  if i == 0:
    parity = (x[i] + y[i]) % 2
  elif (x[i] + y[i]) % 2 != parity:
    print(-1)
    sys.exit()
print(40)
d = []
for i in range(20):
  d.append(3**i)
  d.append(3**i)
d[1] += parity
print(*d)
d = [1] * 40
d[1] += parity
for i in range(n):
  for m in range(20):
    for j, k in itertools.product(range(4), range(4)):
      xnew = x[i] - (d[2*m] * dx[j] + d[2*m+1] * dx[k])
      ynew = y[i] - (d[2*m] * dy[j] + d[2*m+1] * dy[k])
      if xnew % 3 == 0 and ynew % 3 == 0:
        x[i] = xnew // 3
        y[i] = ynew // 3
        print(c[j] + c[k], end='')
        break
  print('')

Solution (Python):
n=int(input())
xy=[list(map(int,input().split()))for _ in range(n)]
g=39
a=[]
if sum(xy[0])%2==0:a.append(1)
for i in range(g):a.append(1<<i)
g=len(a)
for x,y in xy:
  if (x+y)%2!=sum(xy[0])%2:exit(print(-1))
print(g)
print(*a)
def f(s):
  t=s
  ans=[]
  for i in a[::-1]:
    if abs(t-i)<abs(t+i):
      ans.append(-i)
      t-=i
    else:
      ans.append(i)
      t+=i
  return ans[::-1]
for x,y in xy:
  xpy=f(-(x+y))
  xmy=f(-(x-y))
  ans=""
  for p,m in zip(xpy,xmy):
    if 0<p and 0<m:ans+="R"
    if p<0 and m<0:ans+="L"
    if 0<p and m<0:ans+="U"
    if p<0 and 0<m:ans+="D"
  print(ans)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, X: "List[int]", Y: "List[int]"):
    parities = {(Xi + Yi) % 2 for Xi, Yi in zip(X, Y)}
    if len(parities) > 1:
        print(-1)
        return

    d = [1 << i for i in range(39)]
    if next(iter(parities)) == 0:
        d.append(1)

    print(len(d))
    print(*d)

    x0 = -sum(d)
    for Xi, Yi in zip(X, Y):
        u = (Xi - x0 - Yi) // 2
        v = (Xi - x0 + Yi) // 2
        modes = []
        for i in range(39):
            ui = (u & (1 << i)) != 0
            vi = (v & (1 << i)) != 0
            modes.append({
                (False, False): "L",
                (False, True): "U",
                (True, False): "D",
                (True, True): "R",
            }[ui, vi])
        if len(d) > len(modes):
            modes.append("L")
        print("".join(modes))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int()] * (N)  
    Y = [int()] * (N)  
    for i in range(N):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, X, Y)


if __name__ == '__main__':
    main()

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):
import sys
input = sys.stdin.readline
N = int(input())
a = []
mx = 0
for _ in range(N):
  x, y = map(int, input().split())
  u = x + y
  v = x - y
  a.append((u, v))
  mx = max(mx, max(abs(u), abs(v)))
t = a[0][0] % 2
for u, _ in a:
  if u % 2 != t:
    print(-1)
    exit(0)
d = [pow(2, i) for i in range(mx.bit_length())]
if t == 0: d = [1] + d
print(len(d))
print(*d)
for u, v in a:
  s = [0] * len(d)
  t = [0] * len(d)
  x = 0
  y = 0
  res = []
  for i in range(len(d) - 1, -1, -1):
    z = d[i]
    if u < x:
      x -= z
      s[i] = -1
    else:
      x += z
      s[i] = 1
    if v < y:
      y -= z
      t[i] = -1
    else:
      y += z
      t[i] = 1
  for i in range(len(d)):
    if s[i] == 1 and (t[i] == 1):
      res.append("R")
    elif s[i] == -1 and (t[i] == -1):
      res.append("L")
    elif s[i] == 1 and (t[i] == -1):
      res.append("U")
    elif s[i] == -1 and (t[i] == 1):
      res.append("D")
  print("".join(res))

Solution (Python):
N=int(input())
XY=[]
for i in range(N):
  XY.append(list(map(int,input().split())))
mr=abs(XY[0][0])+abs(XY[0][1])  
for i in range(1,N):
  if abs(XY[i][0])+abs(XY[i][1])>mr:
    mr=abs(XY[i][0])+abs(XY[i][1])
import math
m=int(math.log(mr,2)//1+1)
g=(XY[0][0]+XY[0][1])%2
cnt=0
for i in range(N):
  if (XY[i][0]+XY[i][1])%2==g:
    cnt+=1
if cnt!=N:
  print(-1)
else:
  if g==1:
    W=['']*N
    for i in range(N):
      for j in range(m):
        if abs(XY[i][0])>=abs(XY[i][1]) and XY[i][0]>=0:
          W[i]+='R'
          XY[i][0]-=2**(m-j-1)
        elif abs(XY[i][0])>=abs(XY[i][1]) and XY[i][0]<0:
          W[i]+='L'
          XY[i][0]+=2**(m-j-1)
        elif abs(XY[i][0])<abs(XY[i][1]) and XY[i][1]>=0:
          W[i]+='U'
          XY[i][1]-=2**(m-j-1)
        elif abs(XY[i][0])<abs(XY[i][1]) and XY[i][1]<0:
          W[i]+='D'
          XY[i][1]+=2**(m-j-1)
    print(m)
    for i in range(m):
       print(2**i,end=' ')
    print()
    for j in range(N):
      print(W[j][::-1])
  else:
    for i in range(N):
      XY[i][0]+=1
    W=['']*N
    for i in range(N):
      for j in range(m):
        if abs(XY[i][0])>=abs(XY[i][1]) and XY[i][0]>=0:
          W[i]+='R'
          XY[i][0]-=2**(m-j-1)
        elif abs(XY[i][0])>=abs(XY[i][1]) and XY[i][0]<0:
          W[i]+='L'
          XY[i][0]+=2**(m-j-1)
        elif abs(XY[i][0])<abs(XY[i][1]) and XY[i][1]>=0:
          W[i]+='U'
          XY[i][1]-=2**(m-j-1)
        elif abs(XY[i][0])<abs(XY[i][1]) and XY[i][1]<0:
          W[i]+='D'
          XY[i][1]+=2**(m-j-1)
    print(m+1)
    print(1,end=' ')
    for i in range(m):
      print(2**i,end=' ')
    print()
    for j in range(N):
      W[j]+='L'
      print(W[j][::-1])

Solution (Python):

n = int(input())
raw = []
eo = []
h = 30
for _ in range(n):
  x,y = map(int,input().split())
  raw.append([x,y])
  eo.append((x+y)%2)
if sum(eo) == 0:
  print(h+2)
  d = [2**(h-i) for i in range(h+1)]
  d.append(1)
  print(' '.join(map(str,d)))
elif sum(eo) == n:
  print(h+1)
  d = [2**(h-i) for i in range(h+1)]
  print(' '.join(map(str,d)))
else:
  print(-1)
  exit()
for xy in raw:
  x,y = xy
  scale = 2 ** h
  ans = ''
  while scale != 0:
    tmp = [[0,0,'U'],[0,1,'D'],[0,2,'R'],[0,3,'L']]
    tmp[0][0] =   x   ** 2 + (y-1) ** 2
    tmp[1][0] =   x   ** 2 + (y+1) ** 2
    tmp[2][0] = (x-1) ** 2 +   y   ** 2
    tmp[3][0] = (x+1) ** 2 +   y   ** 2
    d,dr = min(tmp)[1],min(tmp)[2]
    ans += dr
    if d == 0:
      y -= scale
    elif d == 1:
      y += scale
    elif d == 2:
      x -= scale
    else:
      x += scale
    scale //= 2
  if x+y != 0:
    if y == 1:
      ans += 'U'
    elif y == -1:
      ans += 'D'
    elif x == 1:
      ans += 'R'
    else:
      ans += 'L'
  print(ans)

Solution (Python):
N, *XY = map(int, open(0).read().split())
XY = list(zip(*[iter(XY)] * 2))

S = set((x + y) % 2 for x, y in XY)
if len(S) == 2:
    print(-1)
    quit()
mod = S.pop()

D = [2 ** i for i in reversed(range(32))] + [1] * (mod == 0)
print(len(D))
print(*D)

for x, y in XY:
    A = []
    for d in D:
        if 0 <= x - y and 0 <= x + y:
            A.append("R")
            x -= d
        elif x - y < 0 and 0 <= x + y:
            A.append("U")
            y -= d
        elif 0 <= x - y and x + y < 0:
            A.append("D")
            y += d
        else:
            A.append("L")
            x += d

    print("".join(A))

Solution (Python):
N, *XY = map(int, open(0).read().split())
XY = list(zip(*[iter(XY)] * 2))

mod = sum(XY[0]) % 2
if any((x + y) % 2 != mod for x, y in XY):
    print(-1)
    quit()

D = [2 ** i for i in reversed(range(32))] + [1] * (mod == 0)
print(len(D))
print(*D)

for x, y in XY:
    A = []
    for d in D:
        if 0 <= x - y and 0 <= x + y:
            A.append("R")
            x -= d
        elif x - y < 0 and 0 <= x + y:
            A.append("U")
            y -= d
        elif 0 <= x - y and x + y < 0:
            A.append("D")
            y += d
        else:
            A.append("L")
            x += d

    print("".join(A))

Solution (Python):
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
  if(abs(x[i])+abs(y[i]))%2!=(abs(x[0])+abs(y[0]))%2:
    print(-1)
    exit()
D=[]
for i in reversed(range(33)):D.append(1<<i)
D+=[1,1]
if(abs(x[0])+abs(y[0]))%2==0:D.append(1)
print(len(D))
print(*D)
for i in range(n):
  X,Y=x[i],y[i]
  s=''
  for d in D:
    if abs(X)>abs(Y):
      if X>0:
        X-=d
        s+='R'
      else:
        X+=d
        s+='L'
    else:
      if Y>0:
        Y-=d
        s+='U'
      else:
        Y+=d
        s+='D'
  print(s)

Solution (Python):
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]
uv = [[XY[i][0]+XY[i][1],XY[i][0]-XY[i][1]] for i in range(N)]

mod = [uv[i][0]%2 for i in range(N)]
if sum(mod)==N:
    print(40)
    print(*[2**i for i in range(40)])
    for i in range(N):
        u,v = uv[i]
        u += 2**40-1
        u //= 2
        v += 2**40-1
        v //= 2
        u = '{:040b}'.format(u)[::-1]
        v = '{:040b}'.format(v)[::-1]
        w = [0]*40
        for j in range(40):
            if (u[j],v[j])==('1','1'):
                w[j] = 'R'
            if (u[j],v[j])==('0','0'):
                w[j] = 'L'
            if (u[j],v[j])==('1','0'):
                w[j] = 'U'
            if (u[j],v[j])==('0','1'):
                w[j] = 'D'
        print(''.join(w))
elif sum(mod)==0:
    print(40)
    print(*([1]+[2**i for i in range(39)]))
    for i in range(N):
        u,v = uv[i]
        u += 2**39
        u //= 2
        v += 2**39
        v //= 2
        u = '{:039b}'.format(u)[::-1]
        v = '{:039b}'.format(v)[::-1]
        w = [0]*39
        for j in range(39):
            if (u[j],v[j])==('1','1'):
                w[j] = 'R'
            if (u[j],v[j])==('0','0'):
                w[j] = 'L'
            if (u[j],v[j])==('1','0'):
                w[j] = 'U'
            if (u[j],v[j])==('0','1'):
                w[j] = 'D'
        w = ['L'] + w
        print(''.join(w))
else:
    print(-1)

Solution (Python):
import sys

n = int(sys.stdin.readline().rstrip())
xy = list(zip(*[map(int, sys.stdin.read().split())] * 2))

mask = (1 << 31) - 1
def solve(x, y, mode):
    u = x + y
    v = x - y
    if mode == 0:
        u -= 1
        v -= 1

    s = (u + mask) >> 1
    t = (v + mask) >> 1

    l = (~(s | t)) & mask
    r = s & t & mask
    d = (~s) & t & mask
    u = s & (~t) & mask

    res = ''
    for i in range(31):
        if l >> i & 1:
            res += 'L'
        elif r >> i & 1:
            res += 'R'
        elif d >> i & 1:
            res += 'D'
        elif u >> i & 1:
            res += 'U'
    if mode == 0:
        res += 'R'
    
    return [res]

def main():
    oe = (xy[0][0] + xy[0][1]) % 2
    for x, y in xy:
        if (x + y) % 2 != oe:
            print(-1)
            sys.exit()

    m = 31
    d = [2 ** i for i in range(31)]
    if oe == 0:
        d += [1]
        m += 1
    yield [m]
    yield d

    for x, y in xy:
        yield solve(x, y, oe)

if __name__ == '__main__':
    ans = main()
    for i in ans:
        print(*i, sep=' ')

Solution (Python):
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
R = [abs(x-y)&1 for x, y in XY]
if not all(R[0] == r for r in R[1:]):
    print(-1)
    exit()
RM = max(abs(x)+abs(y) for x, y in XY)
D = [1 << i for i in range(32, -1, -1)]
if RM & 1 == 0:
    D.append(1)
W = ["" for _ in range(N)]
for d in D:
    for i in range(N):
        x, y = XY[i]
        if abs(x) > abs(y):
            if x > 0:
                x -= d
                W[i] += "R"
            else:
                x += d
                W[i] += "L"
        else:
            if y > 0:
                y -= d
                W[i] += "U"
            else:
                y += d
                W[i] += "D"
        XY[i] = (x, y)
print(len(D))
print(*D)
print(*W, sep="\n")

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.buffer.readline())
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]


x, y = XY[0]
odd = (abs(x) + abs(y)) % 2
ok = True
for x, y in XY:
    ok &= (abs(x) + abs(y)) % 2 == odd

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


def solve(x):
    
    
    
    
    n = int((2 ** 39 - 1 + x) // 2)
    ret = []
    for _ in range(39):
        if n & 1:
            ret.append(1)
        else:
            ret.append(-1)
        n >>= 1
    ret = np.array(ret, dtype=int)
    return ret


P = [complex(x, y) for x, y in XY]
P = np.array(P)


if not odd:
    P -= 1


P *= 1 + 1j

D = (2 ** np.arange(39, dtype=int)).tolist()
ans = []
for p in P:
    xd = solve(p.real)
    yd = solve(p.imag)
    W = np.empty_like(D, dtype='U1')
    W[(xd > 0) & (yd > 0)] = 'R'
    W[(xd > 0) & (yd < 0)] = 'D'
    W[(xd < 0) & (yd > 0)] = 'U'
    W[(xd < 0) & (yd < 0)] = 'L'
    ans.append(''.join(W))

if not odd:
    D.append(1)
    for i in range(len(ans)):
        ans[i] += 'R'
print(len(D))
print(*D)
print(*ans, sep='\n')

Solution (Python):
def solve(n, x, y):
    ws = []
    S = set()
    for i in range(n):
        u = x[i] + y[i]
        v = x[i] - y[i]
        S.add(u % 2)
        if len(S) > 1:
            print(-1)
            return
        ds = [2**k for k in range(30, -1, -1)]
        if u % 2 == 0:
            ds.append(1)
        w = ""
        for d in ds:
            if (u >= 0) and (v >= 0):
                w += "R"
                u, v = u-d, v-d
            elif (u <= 0) and (v <= 0):
                w += "L"
                u, v = u+d, v+d
            elif (u >= 0) and (v <= 0):
                w += "U"
                u, v = u-d, v+d
            else: 
                w += "D"
                u, v = u+d, v-d
        ws.append(w)
    print(len(ds)) 
    print(" ".join(map(str, ds)))
    print("\n".join(ws))

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

Solution (Python):
import sys

def f(s,t):
    if s>=t and -s<=t:
        return 0
    elif s<=t and -s<=t:
        return 1
    elif s<=t and -s>=t:
        return 2
    else:
        return 3

n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(1,n):
    if sum(xy[i])%2!=sum(xy[i-1])%2:
        print(-1)
        sys.exit()
        
data_1=["R","U","L","D"]
data_2=[[1,0],[0,1],[-1,0],[0,-1]]
    
arms=[2**i for i in range(32)]

if sum(xy[0])%2==1:
    print(len(arms))
    print(*arms)
    for X,Y in xy:
        x,y=X,Y
        ans=[]
        i=31
        while i>=0:
            c=f(x,y)
            ans.append(data_1[c])
            x-=arms[i]*data_2[c][0]
            y-=arms[i]*data_2[c][1]
            i-=1
        print("".join(ans[::-1]))
else:
    arms=[1]+arms
    print(len(arms))
    print(*arms)
    for X,Y in xy:
        x,y=X,Y
        ans=[]
        i=32
        while i>=1:
            c=f(x,y)
            ans.append(data_1[c])
            x-=arms[i]*data_2[c][0]
            y-=arms[i]*data_2[c][1]
            i-=1
        if x==1:
            ans.append("R")
        elif x==-1:
            ans.append("L")
        elif y==1:
            ans.append("U")
        else:
            ans.append("D")
        print("".join(ans[::-1]))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    XY=[tuple(map(int,input().split())) for _ in range(n)]
    parity=[0]*2
    for x,y in XY:
        parity[(x+y)%2]=1

    
    if(parity[0] and parity[1]):
        print(-1)
        return

    m=31
    D=[pow(2,i) for i in range(m)]
    
    if(parity[0]):
        XY=[(x-1,y) for x,y in XY]
        D=[1]+D

    U=[x-y for x,y in XY]
    V=[x+y for x,y in XY]

    W=[0]*n
    for j in range(n):
        res=[0]*m
        u=(U[j]+pow(2,m)-1)//2
        v=(V[j]+pow(2,m)-1)//2
        for i in range(m):
            ub=u&1; vb=v&1
            if(ub and vb):
                res[i]='R'
            elif(ub and (not vb)):
                res[i]='D'
            elif((not ub) and vb):
                res[i]='U'
            else:
                res[i]='L'
            u>>=1; v>>=1
        ans=''.join(res)
        W[j]=ans

    m=m+parity[0]
    print(m)
    print(*D)
    for j in range(n):
        ans=W[j] if(parity[1]) else 'R'+W[j]
        print(ans)
resolve()