Problem p03247 (python)

Fixed submission:
import sys
stdin = sys.stdin

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

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

# 偶奇が一致しているか判定
consis = True    
odev = (xy[0][0] + xy[0][1]) % 2
for x,y in xy[1:]:
    if (x+y)%2 != odev:
        consis = False
        
if consis:
    # x+yが奇数なら2**31～2**0, x+yが偶数なら2**31～2**0,2**0の腕を用意
    m = 0
    if odev == 1:
        m = 32
        ds = [2**i for i in range(31,-1,-1)]
    else:
        m = 33
        ds = [2**i for i in range(31,-1,-1)] + [1]
        
    print(m)
    print(" ".join([str(d) for d in ds]))
    
    # それぞれのx,yをu-v座標に変換
    for x,y in xy:
        u = x+y
        v = x-y
        
        # res=0 から target=uに至るまでの足し算を考える
        us = []
        res = 0
        target = u
        for d in ds:
            if target > res:
                us.append(1)
                res += d
            else:
                us.append(-1)
                res -= d
           
        # res=0 から target=vに至るまでの足し算を考える
        vs = []
        res = 0
        target = v
        for d in ds:
            if target > res:
                vs.append(1)
                res += d
            else:
                vs.append(-1)
                res -= d
                
        # ( u, v) : command
        # (-1,-1) :   L
        # ( 1, 1) :   R
        # (-1, 1) :   D
        # ( 1,-1) :   U
        ans = []
        for u,v in zip(us, vs):
            if u==-1 and v==-1:
                ans.append("L")
            elif u==1 and v==1:
                ans.append("R")
            elif u==-1 and v==1:
                ans.append("D")
            elif u==1 and v==-1:
                ans.append("U")
            
        print("".join(ans))

else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

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

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

consis = True    
odev = (xy[0][0] + xy[0][1]) % 2
for x,y in xy[1:]:
    if (x+y)%2 != odev:
        consis = False
        
if consis:
    m = 0
    if odev == 1:
        m = 39
    else:
        m = 40
        
    print(m)
    print(" ".join(["1" for _ in range(m)]))
    for x,y in xy:
        nomove = (m - (abs(x)+abs(y))) // 2
        ans = "RL"*nomove
        if x<0:
            ans = ans + "L"*abs(x)
        else:
            ans = ans + "R"*abs(x)
            
        if y<0:
            ans = ans + "D"*abs(y)
        else:
            ans = ans + "U"*abs(y)
            
        print(ans)

else:
    print(-1)