Problem p03240 (python)

Fixed submission:
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

ss = sorted(ss, key=lambda x: x[2], reverse=True)


cx, cy, ch = ss[0]
if len(ss) == 1:
    print(cx, cy, ch)
else:
    for a in range(101):
        for b in range(101):
            H = ch + abs(cx-a) + abs(cy - b)
            for x, y, h in ss[1:]:
                if h != max(H - abs(x-a) - abs(y - b), 0):
                    break
            else:
                print(a, b, H)
                flg = True

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


ans = []
for i in range(len(ss)-1):

    temp = [] if i == 0 else get_unique_list(ans)
    ans = []

    x1, y1, h1 = ss[i]
    x2, y2, h2 = ss[i+1]

    for a in range(101):
        for b in range(101):
            left = h1 + abs(x1-a) + abs(y1 - b)
            right = h2 + abs(x2-a) + abs(y2 - b)
            if left == right and left > 0 and right > 0:
                if i == 0 or [a, b] in temp:  # 2回目移行
                    ans.append([a, b])

h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])
print(ans[0][0], ans[0][1], h)

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
if flg:
    for i in range(len(ss)-1):

        temp = [] if i == 0 else get_unique_list(ans)
        ans = []

        x1 = ss[i][0]
        y1 = ss[i][1]
        h1 = ss[i][2]
        x2 = ss[i+1][0]
        y2 = ss[i+1][1]
        h2 = ss[i+1][2]

        for a in range(101):
            for b in range(101):
                left = h1 + abs(x1-a) + abs(y1 - b)
                right = h2 + abs(x2-a) + abs(y2 - b)
                if left == right and left > 0 and right > 0:
                    if i == 0:  # 1回目のループ
                        ans.append([a, b])
                    elif [a, b] in temp:  # 2回目移行
                        ans.append([a, b])

    h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])
    print(ans[0][0], ans[0][1], h)

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


# print(f'ss: {ss}')
for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
if flg:
    for i in range(len(ss)-1):

        temp = [] if i == 0 else get_unique_list(ans)
        ans = []

        x1 = ss[i][0]
        y1 = ss[i][1]
        h1 = ss[i][2]
        x2 = ss[i+1][0]
        y2 = ss[i+1][1]
        h2 = ss[i+1][2]

        for a in range(100):
            for b in range(100):
                left = h1 + abs(x1-a) + abs(y1 - b)
                right = h2 + abs(x2-a) + abs(y2 - b)
                if left == right and left > 0 and right > 0:
                    if i == 0:  # 1回目のループ
                        ans.append([a, b])
                    elif [a, b] in temp:  # 2回目移行
                        ans.append([a, b])

    h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])
    print(ans[0][0], ans[0][1], h)

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


# print(f'ss: {ss}')
for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
for i in range(len(ss)-1):

    temp = [] if i == 0 else get_unique_list(ans)
    ans = []

    x1 = ss[i][0]
    y1 = ss[i][1]
    h1 = ss[i][2]
    x2 = ss[i+1][0]
    y2 = ss[i+1][1]
    h2 = ss[i+1][2]

    for a in range(100):
        for b in range(100):
            left = h1 - abs(x1-a) - abs(y1 - b)
            right = h2 - abs(x2-a) - abs(y2 - b)
            if left == right and left > 0 and right > 0:
                if i == 0:  # 1回目のループ
                    ans.append([a, b])
                elif [a, b] in temp:  # 2回目移行
                    ans.append([a, b])

    # print(f'i: {i}, temp: {temp}, ans: {get_unique_list(ans)}')

h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])

print(ans[0][0], ans[0][1], h)
# print(get_unique_list(list_c))