Problem p03240 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[-1]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[:-1]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)


def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)


def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = h + abs(cy-y) + abs(cx-x)
                if hh != ph:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)

def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = h + abs(cy-y) + abs(cx-x)
                if hh != ph:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)


def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])