Problem p03004 (python)

Fixed submission:
def timecalc(p1,p2,speed):
    h1,h2= p1
    l1,l2= p2
    return ((h1-l1)/speed,(h1-l2)/speed,(h2-l1)/speed,(h2-l2)/speed)

n=int(input())
ans=2**62
X = []
Y = []
U = []
D = []
L = []
R = []

for i in range(n):
    xin = input().split()
    x,y,dir = int(xin[0]),int(xin[1]),xin[2]
    if dir=='U':
        X.append(x)
        U.append(y)
    elif dir=='D':
        X.append(x)
        D.append(y)
    elif dir=='L':
        Y.append(y)
        L.append(x)
    else:
        Y.append(y)
        R.append(x)
if n==1:
    print(0)
    exit(0)

if X:
    X = [max(X),min(X)]
if Y:
    Y = [max(Y),min(Y)]
if U:
    U = [max(U),min(U)]
if D:
    D = [max(D),min(D)]
if L:
    L = [max(L),min(L)]
if R:
    R = [max(R),min(R)]
T = []

if X and R:
    T.extend( [i for i in timecalc(X,R,1) if i>0] )
if L and X:
    T.extend( [i for i in timecalc(L,X,1) if i>0] )
if Y and U:
    T.extend( [i for i in timecalc(Y,U,1) if i>0] )
if D and Y:
    T.extend( [i for i in timecalc(D,Y,1) if i>0] )
if L and R:
    T.extend( [i for i in timecalc(L,R,2) if i>0] )
if D and U:
    T.extend( [i for i in timecalc(D,U,2) if i>0] )

T = list(set(T))
T.append(0)

for i in T:
    xmax = -10**9
    ymax = -10**9
    xmin = 10**9
    ymin = 10**9
    if X:
        xmax = max(xmax,X[0])
        xmin = min(xmin,X[1])
    if Y:
        ymax = max(ymax,Y[0])
        ymin = min(ymin,Y[1])
    if U:
        ymax = max(ymax,U[0]+i)
        ymin = min(ymin,U[1]+i)
    if D:
        ymax = max(ymax,D[0]-i)
        ymin = min(ymin,D[1]-i)
    if L:
        xmax = max(xmax,L[0]-i)
        xmin = min(xmin,L[1]-i)
    if R:
        xmax = max(xmax,R[0]+i)
        xmin = min(xmin,R[1]+i)
    
    ans = min(ans,((xmax-xmin)*(ymax-ymin)))

print(ans)

Buggy submission (verdict: Runtime Error):
def timecalc(p1,p2,speed):
    h1,h2= p1
    l1,l2= p2
    return ((h1-l1)/speed,(h1-l2)/speed,(h2-l1)/speed,(h2-l2)/speed)

n=int(input())
ans=2**62
X = []
Y = []
U = []
D = []
L = []
R = []

for i in range(n):
    xin = input().split()
    x,y,dir = int(xin[0]),int(xin[1]),xin[2]
    if dir=="U":
        X.append(x)
        U.append(y)
    elif dir=="D":
        X.append(x)
        D.append(y)
    elif dir=="L":
        Y.append(y)
        L.append(x)
    else:
        Y.append(y)
        R.append(x)

X = [max(X),min(X)]
Y = [max(Y),min(Y)]
if U:
    U = [max(U),min(U)]
if D:
    D = [max(D),min(D)]
if L:
    L = [max(L),min(L)]
if R:
    R = [max(R),min(R)]
T = []

if X and R:
    T.extend( [i for i in timecalc(X,R,1) if i>0] )
if L and X:
    T.extend( [i for i in timecalc(L,X,1) if i>0] )
if Y and U:
    T.extend( [i for i in timecalc(Y,U,1) if i>0] )
if D and Y:
    T.extend( [i for i in timecalc(D,Y,1) if i>0] )
if L and R:
    T.extend( [i for i in timecalc(L,R,2) if i>0] )
if D and U:
    T.extend( [i for i in timecalc(D,U,2) if i>0] )

T = list(set(T))
T.append(0)

for i in T:
    xmax = X[0]
    ymax = Y[0]
    xmin = X[1]
    ymin = Y[1]
    if U:
        ymax = max(ymax,U[0]+i)
        ymin = min(ymin,U[1]+i)
    if D:
        ymax = max(ymax,D[0]-i)
        ymin = min(ymin,D[1]-i)
    if L:
        xmax = max(xmax,L[0]-i)
        xmin = min(xmin,L[1]-i)
    if R:
        xmax = max(xmax,R[0]+i)
        xmin = min(xmin,R[1]+i)
    
    ans = min(ans,((xmax-xmin)*(ymax-ymin)))

print(ans)