Problem p03240 (python)

Fixed submission:
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if max(0,d-abs(x-cx)-abs(y-cy))!=h:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=[]
for i in range(n):
    p.append(tuple(map(int,input().split())))

for j in range(101):
    for k in range(101):
        H=None
        f=1
        for x,y,h in p:
            if h>0 and H==None:
                H=h+abs(x-j)+abs(y-k)
            else:
                if max(0,H-abs(x-j)-abs(y-k))!=h:
                    f=0
        if f:
            print(j,k,H)
            exit()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if max(0,abs(x-cx)+abs(y-cy)+h)!=d:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if abs(x-cx)+abs(y-cy)+h!=d:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            ans=cx,cy,*H
print(*ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            ans=cx,cy,*H
print(*ans)