Problem p03240 (python)

Fixed submission:
N = int(input())

xs, ys, hs = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        cand = []
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            if hs[i] == 0:
                cand.append((h, False))
            else:
                cand.append((h, True))

    
        cand2 = set([c[0] for c in cand if c[1]])
        if len(cand2) != 1:
            continue

        assert len(cand2) == 1
        ans = cand2.pop()

        if all([c[0] >= ans for c in cand if not c[1]]):
            print(x, y, ans)
            ok = True





assert ok

Buggy submission (verdict: Runtime Error):
N = int(input())

xs, ys, hs = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        cand = []
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            if hs[i] == 0:
                cand.append((h, False))
            else:
                cand.append((h, True))

    
        cand2 = set([c[0] for c in cand if c[1]])
        if len(cand2) != 1:
            continue

        assert len(cand2) == 1
        ans = cand2.pop()

        if all([c[0] <= ans for c in cand if not c[1]]):
            print(x, y, ans)
            ok = True





assert ok

Buggy submission (verdict: Runtime Error):
N = int(input())

xs, ys, hs = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        ans = set()
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            ans.add(h)

        if len(ans) == 1:
            h = ans.pop()
            if h > 0:
                ok = True
                print(x, y, h)

assert ok

Buggy submission (verdict: Runtime Error):
N = int(input())

xs, ys, hs = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        ans = set()
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            ans.add(h)

        if len(ans) == 1 and ok2:
            h = ans.pop()
            if h > 0:
                ok = True
                print(x, y, h)

assert ok

Buggy submission (verdict: Runtime Error):
N = int(input())

xs, ys, hs = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        ans = set()
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            assert h != 1
            ans.add(h)

        if len(ans) == 1:
            ok = True
            print(x, y, ans.pop())