Problem p02805 (python)

Fixed submission:
import itertools
import math
N = int(input())
p = []
for i in range(N):
    x, y = map(int, input().split())
    p.append([x, y])
ans = 10000
if len(p) >= 3:
    S = list(itertools.combinations(p,3))
    for X in S:
        ok = True
        a = X[0][0]
        b = X[0][1]
        c = X[1][0]
        d = X[1][1]
        e = X[2][0]
        f = X[2][1]
        if (a-c)*(b-f) == (a-e)*(b-d):
            continue
        py = ((e-a)*(a**2+b**2-c**2-d**2)-(c-a)*(a**2+b**2-e**2-f**2))/(2*(e-a)*(b-d)-2*(c-a)*(b-f))
        if c == a:
            px = (2*(b-f)*py-(a**2+b**2-e**2-f**2))/(2*(e-a))
        else:
            px = (2*(b-d)*py-(a**2+b**2-c**2-d**2))/(2*(c-a))
        r = math.sqrt((px-a)**2+(py-b)**2)
        for Y in p:
            if not (r+0.000001)**2 >= (px-Y[0])**2 + (py-Y[1])**2:
                ok = False
        if ok:
            ans = min(ans, r)
T = list(itertools.combinations(p,2))
for X in T:
    a = X[0][0]
    b = X[0][1]
    c = X[1][0]
    d = X[1][1]
    ok = True
    px = (a+c)/2
    py = (b+d)/2
    r = math.sqrt((px-a)**2+(py-b)**2)
    for Y in p:
        if not (r+0.000001)**2 >= (px-Y[0])**2 + (py-Y[1])**2:
            ok = False
    if ok:
        ans = min(ans, r)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
import math
N = int(input())
p = []
for i in range(N):
    x, y = map(int, input().split())
    p.append([x, y])
ans = 10000
if len(p) >= 3:
    S = list(itertools.combinations(p,3))
    for X in S:
        ok = True
        a = X[0][0]
        b = X[0][1]
        c = X[1][0]
        d = X[1][1]
        e = X[2][0]
        f = X[2][1]
        py = ((e-a)*(a**2+b**2-c**2-d**2)-(c-a)*(a**2+b**2-e**2-f**2))/(2*(e-a)*(b-d)-2*(c-a)*(b-f))
        if c == a:
            px = (2*(b-f)*py-(a**2+b**2-e**2-f**2))/(2*(e-a))
        else:
            px = (2*(b-d)*py-(a**2+b**2-c**2-d**2))/(2*(c-a))
        r = math.sqrt((px-a)**2+(py-b)**2)
        for Y in p:
            if r**2 < (px-Y[0])**2 + (py-Y[1])**2:
                ok = False
        if ok:
            ans = min(ans, r)
T = list(itertools.combinations(p,2))
for X in T:
    a = X[0][0]
    b = X[0][1]
    c = X[1][0]
    d = X[1][1]
    ok = True
    px = (a+c)/2
    py = (b+d)/2
    r = math.sqrt((px-a)**2+(py-b)**2)
    for Y in p:
        if r**2 < (px-Y[0])**2 + (py-Y[1])**2:
            ok = False
    if ok:
        ans = min(ans, r)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
import math
N = int(input())
p = []
for i in range(N):
    x, y = map(int, input().split())
    p.append([x, y])
S = list(itertools.combinations(p,3))
T = list(itertools.combinations(p,2))
ans = 10000
for X in S:
    ok = True
    a = X[0][0]
    b = X[0][1]
    c = X[1][0]
    d = X[1][1]
    e = X[2][0]
    f = X[2][1]
    py = ((e-a)*(a**2+b**2-c**2-d**2)-(c-a)*(a**2+b**2-e**2-f**2))/(2*(e-a)*(b-d)-2*(c-a)*(b-f))
    if c == a:
        px = (2*(b-f)*py-(a**2+b**2-e**2-f**2))/(2*(e-a))
    else:
        px = (2*(b-d)*py-(a**2+b**2-c**2-d**2))/(2*(c-a))
    r = math.sqrt((px-a)**2+(py-b)**2)
    for Y in p:
        if r**2 < (px-Y[0])**2 + (py-Y[1])**2:
            ok = False
    if ok:
        ans = min(ans, r)
for X in T:
    a = X[0][0]
    b = X[0][1]
    c = X[1][0]
    d = X[1][1]
    ok = True
    px = (a+c)/2
    py = (b+d)/2
    r = math.sqrt((px-a)**2+(py-b)**2)
    for Y in p:
        if r**2 < (px-Y[0])**2 + (py-Y[1])**2:
            ok = False
    if ok:
        ans = min(ans, r)
print(ans)