Problem:


Score: 300 points

Problem Statement

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.  

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:  

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.  

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.  

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.  



Sample input:
4
2 3 5
2 1 5
1 2 5
3 2 5


Sample output:
2 2 6

Submission status: Runtime Error

Solution code:
import sys

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    x = [0] * N 
    y = [0] * N
    h = [0] * N
    for i in range(N):
      x[i], y[i], h[i] = map(int, input().split())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100

    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  for temp_x in range(101):
    for temp_y in range(101):
      for i in range(N):
        if i == 0:
          temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
        if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
          break
        if i == N -1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h

  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()

main()

Submission status: Runtime Error

Solution code:
import sys

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    x = [0] * N 
    y = [0] * N
    h = [0] * N
    for i in range(N):
      x[i], y[i], h[i] = map(int, input().split())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100

    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  for temp_x in range(101):
    for temp_y in range(101):
      for i in range(N):
        if i == 0:
          temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
        if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
          break
        if i == N -1:
          if temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h

  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()

main()

Submission status: Runtime Error

Solution code:
import sys
n=int(input())

xyh=[[int(l) for l in k] for k in [j.split() for j in [i.strip() for i in sys.stdin.readlines()]]]

#print(xyh)
ef=0

def hgh(c,p):
    return abs(c[0]-p[0])+abs(c[1]-p[1])+p[2]

#ans=[]

for x in range(101):
    if ef:
        break
    for y in range(101):
        th = 0
        for plc in xyh:
            c=1
            if not th:
                if not plc[2]:
                    continue
            h = hgh([x,y],plc)
            if not th:
                th = h
                continue
            if h!=th:
                c=0
                break
        if c:
            ef=1
            ans=[str(s) for s in [x,y,th]]
            break

print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import sys
n=int(input())

xyh=[[int(l) for l in k] for k in [j.split() for j in [i.strip() for i in sys.stdin.readlines()]]]

#print(xyh)
ef=0

def hgh(c,p):
    return abs(c[0]-p[0])+abs(c[1]-p[1])+p[2]

#ans=[]

for x in range(101):
    if ef:
        break
    for y in range(101):
        th = 0
        for plc in xyh:
            c=1
            if not th and not plc[2]:
                continue
            h = hgh([x,y],plc)
            if not th:
                th = h
                continue
            if h!=th:
                c=0
                break
        if c:
            ef=1
            ans=[str(s) for s in [x,y,th]]
            break

print(" ".join(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
import sys
place=[]
place_0=[]
for i in range(n):
    x,y,h=map(int,input().split())
    if h==0:
        place_0.append((x,y,h))
    else:
        place.append((x,y,h))
for x in range(0,101):
    for y in range(0,101):
        for i in range(len(place)-1):
            a=abs(place[i][0]-x)+abs(place[i][1]-y)
            b=abs(place[i+1][0]-x)+abs(place[i+1][1]-y)
            if b-a==place[i][2]-place[i+1][2]:
                count=1
            else:
                count=0
                break
        if count==1:
            H=abs(place[0][0]-x)+abs(place[0][1]-y)+place[0][2]
            print(x,y,H)
            sys.exit()

Submission status: Runtime Error

Solution code:
n=int(input())
import sys
place=[]
place_0=[]
for i in range(n):
    x,y,h=map(int,input().split())
    if h==0:
        place_0.append((x,y,h))
    else:
        place.append((x,y,h))
for x in range(0,101):
    for y in range(0,101):
        for i in range(n-1):
            a=abs(place[i][0]-x)+abs(place[i][1]-y)
            b=abs(place[i+1][0]-x)+abs(place[i+1][1]-y)
            if b-a==place[i][2]-place[i+1][2]:
                count=1
            else:
                count=0
                break
        if count==1:
            H=abs(place[0][0]-x)+abs(place[0][1]-y)+place[0][2]
            print(x,y,H)
            sys.exit()

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag = True
        flag_init = True
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if flag_init:
                    H0 = H
                    flag_init = False
                else:
                    if H != H0:
                        flag = False
        if flag == True and h >= 1:
            print(cx, cy, H)
            break

    else:
        continue
    break

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        # flag = True
        flag_init = True
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if flag_init:
                    H0 = H
                    flag_init = False
                else:
                    if H != H0:
                        flag = False
        if flag == True:
            print(cx, cy, H)

Submission status: Runtime Error

Solution code:
for cx in range(101):
    for cy in range(101):
        flag = True
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag = True
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H
                else:
                    if H != H0:
                        flag = False

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag = True
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H
                else:
                    if H != H0:
                        flag = False
            if _n == n-1 and flag == True:
                print(cx, cy, H)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag_success = 0
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H
                else:
                    if H != H0:
                        flag_success = 1 # miss break
                        break
            if _n == n-1:
                print(cx, cy, H)
                flag_success = 2 # sucess break

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag_success = 0
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H
                else:
                    if H != H0:
                        flag_success = 1 # miss break
                        break
            if _n == n-1:
                print(cx, cy, H)
                flag_success = 2 # sucess break

        if flag_success == 2:
            break
    if flag_success == 2:
        break

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag_success = 0
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H
                else:
                    if H != H0:
                        flag_success = 1 # miss break
            if _n == n-1:
                print(cx, cy, H)
                flag_success = 2 # sucess break

            if flag_success == 1 or flag_success == 2:
                break

        if flag_success == 2:
            break
    if flag_success == 2:
        break

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<math.h>
#include<vector>

using namespace std;

int H(int hi, int xi, int yi, int Cx, int Cy){
    return hi + abs(xi - Cx) + abs(yi -Cy);
}
bool isH(int hi, int xi, int yi, int Cx, int Cy, int H){
    int ans = H - abs(xi - Cx) - abs(yi - Cy);
    if(ans == hi)return true;
    return false;
}

int main(){
    int N;
    cin >> N;
    int x[N], y[N], h[N];
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    int ptn[101][101][2];
    for(int i = 0; i <= 100; i++){
        for(int j = i; j <= 100; j++){
            ptn[i][j][0] = H(h[0], x[0], y[0], i, j);
            ptn[i][j][1] = true;
            ptn[j][i][0] = H(h[0], x[0], y[0], j, i);
            ptn[j][i][1] = true;
        }
    }
    int ans_x, ans_y, ans_h;
    for(int n = 0; n < N; n++){
        for(int i = 0; i <= 100; i++){
            for(int j = i; j <= 100; j++){
                if(ptn[i][j][1]){
                    ptn[i][j][1] = isH(h[n], x[n], y[n], i, j, ptn[i][j][0]);
                    if(ptn[i][j][1] && n == N-1){
                        ans_x = i;
                        ans_y = j;
                        ans_h = ptn[i][j][0];
                    }
                }
                if(ptn[j][i][1]){
                    ptn[j][i][1] = isH(h[n], x[n], y[n], j, i, ptn[j][i][0]);
                    if(ptn[j][i][1] && n == N-1){
                        ans_x = j;
                        ans_y = i;
                        ans_h = ptn[j][i][0];
                    }
                }
            }
        }
    }

    cout << isH(h[3], x[3], y[3], ans_x, ans_y, ans_h) << endl;

    cout << ans_x << " " << ans_y << " " << ans_h;
}

Submission status: Runtime Error

Solution code:
N = int(input())
xyh = []
xyh1 = []
for _ in range(N):
	x0, y0, h0 = map(int, input().split())
	xyh.append([x0,y0,h0])
	if h0 > 0:
		xyh1.append([x0,y0,h0])

def absum(x, y, h, Cx, Cy):
	return abs(x - Cx) + abs(y - Cy) + h

if len(xyh1) > 1:
	for Cx in range(101):
		for Cy in range(101):
			for i in range(len(xyh1)-1):
				if absum(xyh1[i][0], xyh1[i][1], xyh1[i][2], Cx, Cy) != absum(xyh1[i+1][0], xyh1[i+1][1], xyh1[i+1][2], Cx, Cy):
					break
			else:
				H = absum(xyh1[i][0], xyh1[i][1], xyh1[i][2], Cx, Cy)
				print(Cx, Cy, H)
else:
	print(xyh1[i][0], xyh1[i][1], xyh1[i][2])

Submission status: Runtime Error

Solution code:
N = int(input())
xyh = []
xyh1 = []
for _ in range(N):
	x0, y0, h0 = map(int, input().split())
	xyh.append([x0,y0,h0])
	if h0 > 0:
		xyh1.append([x0,y0,h0])

def absum(x, y, h, Cx, Cy):
	return abs(x - Cx) + abs(y - Cy) + h


for Cx in range(101):
	for Cy in range(101):
		for i in range(len(xyh1)-1):
			if absum(xyh1[i][0], xyh1[i][1], xyh1[i][2], Cx, Cy) != absum(xyh1[i+1][0], xyh1[i+1][1], xyh1[i+1][2], Cx, Cy):
				break
		else:
			H = absum(xyh1[i][0], xyh1[i][1], xyh1[i][2], Cx, Cy)
			print(Cx, Cy, H)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        if len(l) == 1:
            result = (x, y, h)
            break
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])

Submission status: Runtime Error

Solution code:
n = int(input())
nums = [list(map(int,input().split()))for i in range(n)]


first = True
record = {}
target = None
for x, y, h in nums:
    if h != 0:
        target = x, y, h

if target is not None:
    x, y, h = target
    for i in range(0,101):
        for j in range(0, 101):
            if abs(x - i) + abs(x - j) + h >= 1:
                record[(i,j)] = abs(x - i) + abs(y - j) + h
    
    for x, y, h in nums:
        for (i, j) in list(record.keys()):
            if max(record[(i, j)] - abs(x-i) - abs(y-j), 0) != h:
                record.pop((i,j))
    key = list(record.keys())[0]

    print(*key, record[key])
else:
    for x, y, h in nums:
        record[(x,y)] = True
    ndone = True
    for i in range(101):
        for j in range(101):
            if (i, j) not in record and ndone:
                print(i, j, 1)
                ndone = False

Submission status: Runtime Error

Solution code:
n = int(input())
nums = [list(map(int,input().split()))for i in range(n)]


first = True
record = {}
target = None
for x, y, h in nums:
    if h != 0:
        target = x, y, h

if target is not None:
    x, y, h = target
    for i in range(0,101):
        for j in range(0, 101):
            if abs(x - i) + abs(x - j) + h >= 1:
                record[(i,j)] = abs(x - i) + abs(y - j) + h
    
    for x, y, h in nums:
        for (i, j) in list(record.keys()):
            if max(record[(i, j)] - abs(x-i) - abs(y-j), 0) != h:
                record.pop((i,j))
    key = list(record.keys())[0]

    print(*key, record[key])
else:
    for x, y, h in nums:
        record[(x,y)] = True

    for i in range(101):
        for j in range(101):
            if (i, j) not in record:
                print(i, j, 1)
                exit()

Submission status: Runtime Error

Solution code:
N = int(input())

xyh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    xyh.append((x, y, h))

# print(xyh)

# h = max(H - |x - Cx| - |y - Cy|, 0)

'''
  0 1 2 3
0
1     5
2   5   5
3     5

   99 100
0 192
1 191 192
'''


def f():
    for tx in range(101):
        for ty in range(101):
            th = xyh[0][2] + abs(xyh[0][0] - tx) + abs(xyh[0][1] - ty)
            if all(h == max(th - abs(tx - x) - abs(ty - y), 0) for x, y, h in xyh):
                return tx, ty, th
print(*f())

Submission status: Runtime Error

Solution code:
N = int(input())
input_list = []


#i,j = coordinate of x,y
for k in range(N):
    input_now = list(map(int, input().split()))
    input_list.append(input_now)

for i in range(101):
    Cx = i
    for j in range(101):
        Cy = j
        H_list = []
        for k in range(N):
            x,y,h = input_list[k][0],input_list[k][1],input_list[k][2]
            if h>=0:
                H = h+abs(x-Cx)+abs(y-Cy)
                H_list.append(H)
        if max(H_list)==sum(H_list)/len(H_list):
            Ans_H = H
            Ans_x = Cx
            Ans_y = Cy
            break
    else:
        continue
    break
# The value of Cx,Cy,H is determined.
print(str(Ans_x)+" "+str(Ans_y)+" "+str(Ans_H))

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append([int(i) for i in input().split()])
for x in range(101):
    for y in range(101):
        t = []
        for i in range(n):
            x_, y_, h = s[i]
            t.append(h + abs(x_ - x) + abs(y_ - y))
        if (len(set(t)) == 1):
            ttt = h + abs(x_ - x) + abs(y_ - y)
            ans = str(x) + " " + str(y) + " " + str(ttt)
            break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
XYH = []
for i in range(N):
    tmp = list(map(int, input().split()))
    if tmp[2] == 0:
        continue
    XYH.append(tmp)

def calc(XYH):
    tmp = 0
    res = [0,0,0]
    for tarx in range(101):
        for tary in range(101):
            xyh = XYH[0]
            tarh = xyh[2] + abs(xyh[0] - tarx) + abs(xyh[1] - tary)
            if all(h==max(h - abs(tarx - x) - abs(tary - y), 0) for x, y, h in XYH):
                print(" ".join(x,y,h))
                return
    
calc(XYH)

Submission status: Runtime Error

Solution code:
N = int(input())

X = [list(map(int, input().split())) for i in range(N)]

X.sort(key = lambda item: item[2] ,reverse = True)

for i in range(101):
    for j in range(101):
        h = X[0][2] + abs(X[0][0] - i) + abs(X[0][1] - j)
        
        ok = True
        for k in range(N):
            if X[0][2] != h - abs(X[k][0] - i) - abs(X[k][1] - j)
                ok = False
        
        if ok:
            print(i,j)
            exit()

Submission status: Runtime Error

Solution code:

def iabs(n):
    return n if n > 0 else -n

def main(ps):
    candidates = {}

    for x, y, h in ps:
        if h == 0:
            continue
        for Cx in range(0, 101):
            for Cy in range(0, 101):
                Hc =  max(h + iabs(x - Cx) + iabs(y - Cy), 0)
                if Hc < h:
                    continue
                candidates[Cx, Cy] = Hc
        break
    for x, y, h in ps:
        cs = list(candidates.keys())
        for Cx, Cy in cs:
            Hc = max(h + iabs(x - Cx) + iabs(y - Cy), 0)
            if candidates[Cx, Cy] != Hc:
                del candidates[Cx, Cy]

    if len(candidates) == 1:
        for (x, y), h in candidates.items():
            print(x, y, h)
    else:
        1 // 0 

N = int(input())
ps = []
for _ in range(N):
    x, y, h = [int(x) for x in input().split()]
    if h > 0:
        ps.append((x, y, h))

main(ps)

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
  if p[i][2]==0:
    p.del(i)
if len(p)==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(0,101):
    for j in range(0,101):
      k=1
      l=p[0][2]+abs(i-p[0][0])+abs(j-p[0][1])
      for x,y,h in p:
        if h==0:
          continue
        m=h+abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))for i in range(n)]
if n==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(0,101):
    for j in range(0,101):
      k=1
      l=p[0][2]+abs(i-p[0][0])+abs(j-p[0][1])
      for x,y,h in p:
        if h==0:
          continue
        m=h+abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))for i in range(n)]
if n==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(0,101):
    for j in range(0,101):
      k=1
      l=p[0][2]+abs(i-p[0][0])+abs(j-p[0][1])
      for x,y,h in p:
        m=h+abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))for i in range(n)]
if n==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(0,101):
    for j in range(0,101):
      k=1
      l=p[0][2]+abs(i-p[0][1])+abs(j-p[0][1])
      for x,y,h in p:
        m=h+abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))]
if n==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(0,101):
    for j in range(0,101):
      k=1
      l=p[0][2]+abs(i-p[0][1])+abs(j-p[0][1])
      for x,y,h in p:
        m=h+abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))]
if n==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(1,101):
    for j in range(1,101):
      k=1
      l=p[0][2]+abs(i-p[0][1])+abs(j-p[0][1])
      for x,y,h in p:
        m=abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import collections
import math
import sys
import itertools
n = int(input())
vs = list(map(int,input().split()))
guusuu = vs[1::2]
kisuu = vs[0::2]
kisuucount = collections.Counter(kisuu).most_common(2)
guusuucount = collections.Counter(guusuu).most_common(2)
kisuu.append((0,0))
guusuu.append((0,0))
if guusuucount[0][0]!=kisuucount[0][0]:
    print(n-guusuucount[0][1]-kisuucount[0][1])
elif len(guusuucount)==len(kisuucount):
    print(len(guusuu))
else:
    print(min(n-guusuucount[1][1]-kisuucount[0][1],(n-guusuucount[0][1]-kisuucount[1][1])))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

xyh = []
for _ in range(N):
    xyh.append(list(map(int, input().split())))
xyh = np.array(xyh)
xyh = xyh[np.argsort(xyh[:, 2])[::-1]]

cxylist = [[i, j] for i in range(101) for j in range(101)]

Hdict = [[] for i in range(101)]
for i in range(len(cxylist)):
    x, y, h =xyh[0]
    H = h + abs(x-cxylist[i][0]) + abs(y-cxylist[i][1])
    Hdict[cxylist[i][0]].append(H)

def calh(cxylist, x, y, h):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        H = h + abs(x-cx) + abs(y-cy)
        if Hdict[cx][cy] == H:
            newcxylist.append([cx, cy])
    return newcxylist

def checkh(cxylist, x, y):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        if Hdict[cx][cy] - abs(x-cx) - abs(y-cy) <= 0:
            newcxylist.append([cx, cy])
    return newcxylist

for n in range(N-1):
    if xyh[n][2] != 0:
        cxylist = calh(cxylist, xyh[n+1][0], xyh[n+1][1], xyh[n+1][2])
    else:
        cxylist = checkh(cxylist, xyh[n+1][0], xyh[n+1][1])

print(cxylist[0][0], cxylist[0][1], Hdict[cxylist[0][0]][cxylist[0][1]])

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

xyh = []
for _ in range(N):
    xyh.append(list(map(int, input().split())))
xyh = np.array(xyh)
xyh = xyh[np.argsort(xyh[:, 2])[::-1]]

cxylist = [[i, j] for i in range(101) for j in range(101)]

Hdict = [[] for i in range(101)]
for i in range(len(cxylist)):
    x, y, h =xyh[0]
    H = h + abs(x-cxylist[i][0]) + abs(y-cxylist[i][1])
    Hdict[cxylist[i][0]].append(H)

def calh(cxylist, x, y, h):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        H = h + abs(x-cx) + abs(y-cy)
        if Hdict[cx][cy] == H:
            newcxylist.append([cx, cy])
    return newcxylist

def checkh(cxylist, x, y):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        if Hdict[cx][cy] - abs(x-cx) - abs(y-cy) <= 0:
            newcxylist.append(cx)
    return newcxylist

for n in range(N-1):
    if xyh[n][2] != 0:
        cxylist = calh(cxylist, xyh[n+1][0], xyh[n+1][1], xyh[n+1][2])
    else:
        cxylist = checkh(cxylist, xyh[n+1][0], xyh[n+1][1])

print(cxylist[0][0], cxylist[0][1], Hdict[cxylist[0][0]][cxylist[0][1]])

Submission status: Runtime Error

Solution code:
N=int(input())
xyh=[list(map(int, input().split())) for _ in range(N)]

def find(cx, cy, H):
	for x,y,h in xyh:
		if h != max(H-abs(x-cx)-abs(y-cy), 0):
			return False
	return True

def solve():
	for cx in range(101):
		for cy in range(101):
			x,y,h = xyh[0]
			H = h + abs(x-cx) + abs(y-cy)
			if find(cx, cy, H):
				return "%d %d %d" % (cx, cy, H)
	raise Exception

print(solve())

Submission status: Runtime Error

Solution code:
def calc(X, Y, H, cx, cy):
	a = H - abs(X-cx) - abs(Y-cy)
	if a < 0: return 0
	else: return a
N = int(raw_input())
lst = []
x1, y1, h1 = map(int, raw_input().split())
for i in range(0, 101):
	for j in range(0, 101):
		lst.append([i, j, h1+abs(x1-i)+abs(y1-j)])
for i in range(1, N):
	now = map(int, raw_input().split())
	M = len(lst)
	for j in range(0, M):
		toppoint = lst.pop(0)
		if now[2] == calc(toppoint[0], toppoint[1], toppoint[2], now[0], now[1]):
			lst.append(toppoint)

print str(lst[0][0]) + ' ' + str(lst[0][1]) + ' ' + str(lst[0][2])

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
H = [list(map(int, input().split())) for i in range(N)]

H.sort(key=lambda x: x[2], reverse=True)

for i in H:
    x, y, h = i
    for c_x in range(101):
        for c_y in range(101):
            Height = h + abs(x-c_x) + abs(y-c_y)
            for j in range(N):
                if Height[j][2] != max(Height-abs(H[j][0]-c_x)-abs(H[j][1]-c_y), 0):
                    break
                if j == N-1:
                    print(c_x, c_y, Height)
                    sys.exit()

Submission status: Runtime Error

Solution code:
import copy

N = int(input())

Height = []
tmp = []
for i in range(N):
    x, y, h = map(int, input().split())
    if i == 0:
        for c_x in range(0, 101):
            for c_y in range(0, 101):
                if h != 0:
                    H = h + abs(x-c_x) + abs(y-c_y)
                    d = (c_x, c_y, H)
                    Height.append(d)
                else:
                    pass
    else:
        for c_x in range(0, 101):
            for c_y in range(0, 101):
                if h != 0:
                    H = h + abs(x-c_x) + abs(y-c_y)
                    d = (c_x, c_y, H)
                    if d in Height:
                        if d not in tmp:
                            tmp.append(d)
                else:
                    pass
        if i == N-1:
            Height.clear()
            break
        else:
            Height = copy.deepcopy(tmp)
            tmp.clear()

tmp[0] = [str(i) for i in tmp[0]]

print(' '.join(tmp[0]))

Submission status: Runtime Error

Solution code:
import copy

N = int(input())

Height = []
tmp = []
for i in range(N):
    x, y, h = map(int, input().split())
    if i == 0:
        for c_x in range(0, 101):
            for c_y in range(0, 101):
                H = h + abs(x-c_x) + abs(y-c_y)
                d = (c_x, c_y, H)
                Height.append(d)
    else:
        for c_x in range(0, 101):
            for c_y in range(0, 101):
                H = h + abs(x-c_x) + abs(y-c_y)
                d = (c_x, c_y, H)
                if d in Height:
                    if d not in tmp:
                        tmp.append(d)
        if i == N-1:
            Height.clear()
            break
        else:
            Height = copy.deepcopy(tmp)
            tmp.clear()

tmp[0] = [str(i) for i in tmp[0]]

print(' '.join(tmp[0]))

Submission status: Runtime Error

Solution code:
def main():
	n = int(input())
	xi, yi, hi = [0]*n, [0]*n, [0]*n
	stack = []
	result = []
	for i in range(n):
		xi[i], yi[i], hi[i] = map(int, input().split())
		if hi[i] > 0:
			stack = [xi[i], yi[i], hi[i]]
	for i in range(101):
		for j in range(101):
			guess = stack[2] + abs(stack[0]-i) + abs(stack[1]-j)
			is_result = True
			for k in range(n):
				result = guess - abs(xi[k]-i) - abs(yi[k]-j)
				result = max(result, 0)
				if hi[k] != result:
					is_result = False
					break
			if is_result:
				print(str(i)+" "+str(j)+" "+str(v))
				return


if __name__ == '__main__':
    main()