Problem p03240 (python)

Fixed submission:
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H, H_max, flag = None, None, True
  for x,y,h in cols:
    if h <= 0:
      tmp_H_max = abs(x-cx) + abs(y-cy)
      if tmp_H_max < 1:
        flag = False
        break
      else:
        H_max = min(H_max, tmp_H_max) if H_max else tmp_H_max
      if H and H_max < H:
        flag = False
        break
    else:
      tmp_H = h + abs(x-cx) + abs(y-cy)
      if not H:
        H = tmp_H
      elif H and H != tmp_H:
        flag = False
        break
      if H_max and H_max < tmp_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H, H_max, flag = None, None, True
  for x,y,h in cols:
    if h <= 0:
      tmp_H_max = abs(x-cs) + abs(y-cy)
      if tmp_H_max < 1:
        flag = False
        break
      else:
        H_max = tmp_H_max if not H_max else min(H_max, tmp_H_max)
    else:
      tmp_H = h + abs(x-cx) + abs(y-cy)
      if not H:
        H = tmp_H
      if H and H != tmp_H:
        flag = False
        break
      if H_max and H_max < tmp_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

def calcH(cx, cy, x, y, h):
  if h > 0:
  	return h + abs(x-cx) + abs(y-cy)
  else:
    return h - abs(x-cs) - abs(y-cy) <= 0

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H = None
  flag = True
  for x,y,h in cols:
    now_H = calcH(cx, cy, x, y, h)
    if not H:
      flag = False
      break
    if H is None:
      H = now_H
    else:
      if not H == now_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
import sys
import itertools

def calcH(cx, cy, x, y, h):
  if h > 0:
  	return h - abs(x-cx) + abs(y-cy)
  else:
    return h - abs(x-cs) + abs(y-cy) <= 0

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H = None
  flag = True
  for x,y,h in cols:
    now_H = calcH(cx, cy, x, y, h)
    if H is False:
      flag = False
      break
    if H is None:
      H = now_H
    else:
      if not H == now_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
import sys
import itertools

def calcH(cx, cy, x, y, h):
  if h > 0:
  	return h + abs(x-cx) + abs(y-cy)
  else:
    return h - abs(x-cs) + abs(y-cy) <= 0

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H = None
  flag = True
  for x,y,h in cols:
    now_H = calcH(cx, cy, x, y, h)
    if H is False:
      flag = False
      break
    if H is None:
      H = now_H
    else:
      if not H == now_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)