Problem: In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.   The pyramid had _center coordinates_ (C_X, C_Y) and _height_ H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).  Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:    * C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.    * Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."   This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Submission attempts (in order):
def main():
    n, *xyh = map(int, open(0).read().split())
    xyh = list(zip(*[iter(xyh)] * 3))
    xyh.sort(key=lambda x: x[0])

    x, y, now = xyh[0]
    c, r = -1, -1

    for i, j, h in xyh[1:]:
        if h > now:
            x, y, now = i, j, h
        elif h == now:
            if i == x:
                r = (j + y) // 2
            elif j == y:
                c = (i + x) // 2
            x, y, now = i, j, h

    if c == -1 and r != -1:
        c = 50 + 50 * (-1) ** (y < 50)
    elif r == -1 and c != -1:
        r = 50 + 50 * (-1) ** (x < 50)
    elif r == -1 and c == -1:
        c = 50 + 50 * (-1) ** (x < 50)
        r = 50 + 50 * (-1) ** (y < 50)

    h = now + abs(c - x) + abs(r - y)
    print(x,y)
    print(c, r, h)


if __name__ == '__main__':
    main()


def main():
    from itertools import product

    n, *xyh = map(int, open(0).read().split())
    a = range(101)

    if n - xyh[2::3].count(0) == 1:
        i = xyz[2::3].index(1)
        print(xyh[i])
        return
    a = range(101)
    for x, y in product(a, a):
        l = None
        for i, j, h in zip(*[iter(xyh)] * 3):
            ll = h + abs(x - i) + abs(y - j)
            if l:
                if ll != l:
                    break
            else:
                l = ll
    else:
        print(x, y, l)
        return


if __name__ == '__main__':
    main()


def main():
    from itertools import product

    n, *xyh = map(int, open(0).read().split())
    a = range(101)

    if n - xyh[2::3].count(0) == 1:
        i = xyz[2:;
        3].index(1)
        print(xyh[i])
        return
    a = range(101)
    for x, y in product(a, a):
        l = None
        for i, j, h in zip(*[iter(xyh)] * 3):
            ll = h + abs(x - i) + abs(y - j)
            if l:
                if ll != l:
                    break
            else:
                l = ll
    else:
        print(x, y, l)
        return


if __ name__ == '__main__':
    main()


def main():
    from operator import itemgetter
    n, *xyh = map(int, open(0).read().split())
    xyh = list(zip(*[iter(xyh)] * 3))
    xyh.sort(key=itemgetter(2,0,1))
    
    x, y, now = xyh[0]
    c, r = -1, -1

    for i, j, h in xyh[1:]:
        if h > now:
            x, y, now = i, j, h
        elif h == now:
            if i == x:
                r = (j + y) // 2
                x, y = i, j
            elif j == y:
                c = (i + x) // 2
                x, y = i, j

    if c == -1 and r != -1:
        c = 50 + 50 * (-1) ** (y < 50)
    elif r == -1 and c != -1:
        r = 50 + 50 * (-1) ** (x < 50)
    elif r == -1 and c == -1:
        c = 50 + 50 * (-1) ** (x < 50)
        r = 50 + 50 * (-1) ** (y < 50)

    h = now + abs(c - x) + abs(r - y)
    print(c, r, h)


if __name__ == '__main__':
    main()


def main():
    from itertools import product

    n, *xyh = map(int, open(0).read().split())
    a = range(101)

    if n - xyh[2::3].count(0) == 1:
        i = xyh[2::3].index(1)
        print(xyh[3*i], xyh[3*i+1], xyh[3*i+2])
        return
    a = range(101)
    for x, y in product(a, a):
        l = None
        for i, j, h in zip(*[iter(xyh)] * 3):
            if h == 0:
                continue
            ll = h + abs(x - i) + abs(y - j)
            if l:
                if ll != l:
                    break
            else:
                l = ll
        else:
            print(x, y, l)
            return


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted