Problem p03240 (python)

Fixed submission:
import itertools
N=int(input())
l=[]
#l:調査情報のリスト
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
M=max(item[2] for item in l)#高さの最大値(暫定)
s=list(itertools.product(range(0,101),repeat=2))
#s:中心座標の候補リスト
for A,B in itertools.combinations(range(N),2):
  #調査情報の全ての2つ組を用いて絞り込む
  if len(s)==1:
    break
  t=[]
  #t:新たな中心座標の候補リスト
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    #2地点の高さが異なる場合
    if l[B][2]==0:
      #B地点の高さが0ならB地点は中心から[Aの高さ]以上離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      #B地点の高さが0でなければA地点は中心から[Aの高さ-Bの高さ]だけ離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    #2地点の高さが等しく0ではない場合
    #2地点からM-[Aの高さ]以上離れた地点のみ残す
    for X,Y in s:
      MM=max(1,M-l[A][2])
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]) and abs(X-l[A][0])+abs(Y-l[A][1])>=MM and abs(X-l[B][0])+abs(Y-l[B][1])>=MM:
        t.append((X,Y))
  else:
    #2地点の高さが等しく0の場合
    #2地点からM以上離れた地点のみ残す
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]
#sの要素は唯一だと思いたい
a,b=s[0][0],s[0][1]
i=0
while l[i][2]==0:
  i+=1

h=abs(a-l[i][0])+abs(b-l[i][1])+l[i][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
#l:調査情報のリスト
M=max(item[2] for item in l)
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
#s:中心座標の候補リスト
for A,B in itertools.combinations(range(N),2):
  #調査情報の全ての2つ組を用いて絞り込む
  if len(s)==1:
    break
  t=[]
  #t:新たな中心座標の候補リスト
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    #2地点の高さが異なる場合
    if l[B][2]==0:
      #B地点の高さが0ならB地点は中心から[Aの高さ]以上離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      #B地点の高さが0でなければA地点は中心から[Aの高さ-Bの高さ]だけ離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    #2地点の高さが等しく0ではない場合
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    #2地点の高さが等しく0の場合
    #2地点が中心ではない
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]
#sの要素は唯一だと思いたい
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    if l[B][2]==0:
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  s=t[:]
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=set(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=set()
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.add((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.add((X,Y))
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.add((X,Y))
  else:
    t=s.copy()
    if (l[A][0],l[A][1]) in t:
      t.remove((l[A][0],l[A][1]))
    if (l[B][0],l[B][1]) in t:
      t.remove((l[B][0],l[B][1]))    

  s=t.copy()
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    t=[:]
  s=t[:]
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  s=t[:]
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  s=t[:]
if len(s)!=1:
  nya-n
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Buggy submission (verdict: Runtime Error):
import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  s=t[:]
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)