Problem p03245 (python)

Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = [tuple(map(int, input().split())) for _ in [None]*N]
    p = set(z%2 for z in map(sum,Z))
    if len(p) == 2:
        res = '-1'
    else:
        res = ''
        mode, *_ = p
        mode = 1-mode
        D = [2**i for i in range(30,-1,-1)]
        res += str(31+mode)
        res += '\n' + ' '.join(str(d) for d in D+[1]*mode)
        wdict = {(True, True):('R', (1,0)), (True, False):('U', (0,1)), (False, False):('L',(-1,0)), (False, True):('D',(0,-1))}
        for x, y in Z:
            x -= mode
            W = '\n'
            for d in D:
                w, (a, b) = wdict[x+y>0, x-y>0]
                W += w
                x -= a*d
                y -= b*d
            W += 'R'*mode
            res += W
    return str(res)

if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    wdict = {(True, True):('R',-1,-1), (True, False):('U',-1,1), (False, False):('L',1,1), (False, True):('D',1,-1)}
    mode = None
    for _ in [None]*int(input()):
        x, y = map(int, input().split())
        u = x+y
        if mode is None:
            mode = 1-u%2
            res = str(31+mode) + '\n' + ' '.join(map(str, [1]*mode+list(map((2).__pow__, range(31)[::-1]))))
            W0 = '\n'+'R'*mode
        elif mode != 1-u%2:
            return('-1')
        res += W0
        u -= mode
        v = x-y-mode
        for d in D:
            w, a, b = wdict[u>0, v>0]
            res += w
            u += a*d
            v += b*d
    return str(res)

if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = [tuple(map(int, input().split())) for _ in [None]*N]
    p = set(z%2 for z in map(sum,Z))
    if len(p) == 2:
        res = '-1'
    else:
        res = ''
        mode, *_ = p,
        mode = 1-mode
        D = [2**i for i in range(30,-1)]
        res += str(31+mode)
        res += '\n' + ' '.join(str(d) for d in D+[1]*mode)
        wdict = {(True, True):('R', (1,0)), (True, False):('U', (0,1)), (False, False):('L',(-1,0)), (False, True):('D'(0,-1))}
        for x, y in Z:
            x -= mode
            W = '\n'
            for d in D:
                w, (a, b) = wdict[x+y>0, x-y>0]
                W += w
                x -= a*d
                y -= b*d
            W += 'R'*mode
            res += W
    return str(res)

if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = [tuple(map(int, input().split())) for _ in [None]*N]
    p = set(z%2 for z in map(sum,Z))
    print(N,Z,p)
    if len(p) == 2:
        res = '-1'
    elif 0 in p:
        res = '20\n' + ' '.join('1' for _ in range(20))
        for x,y in Z:
            w = ('R'*x if x > 0 else 'L'*-x) + ('U'*y if y > 0 else 'D'*-y) + ('LR'*10)[:(20-abs(x)-abs(y))]
            res += '\n'+w
    else:
        res = '21\n' + ' '.join('1' for _ in range(21))
        for x,y in Z:
            w = ('R'*x if x > 0 else 'L'*-x) + ('U'*y if y > 0 else 'D'*-y) + ('LR'*10)[:(21-abs(x)-abs(y))]
            res += '\n'+w

    return str(res)

if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = [set(map(int, input().split())) for _ in [None]*N]
    p = set(z%2 for z in map(sum,Z))
    if len(p) == 2:
        res = -1
    elif 0 in p:
        res = '20\n' + ' '.join('1' for _ in range(20))
        for x,y in Z:
            w = ('R'*x if x > 0 else 'L'*-x) + ('U'*y if y > 0 else 'D'*-y) + ('LR'*10)[:(20-abs(x)-abs(y))]
            res += '\n'+w
    else:
        res = '21\n' + ' '.join('1' for _ in range(21))
        for x,y in Z:
            w = ('R'*x if x > 0 else 'L'*-x) + ('U'*y if y > 0 else 'D'*-y) + ('LR'*10)[:(21-abs(x)-abs(y))]
            res += '\n'+w

    return str(res)

if __name__ == '__main__':
    print(solve())