Harryxun/stf_run huggingface dataset:
from collections import deque
f = open("/Users/naoki/Documents/Atcoder/input.txt")

H,W = map(int,f.readline().split())
Ss = [str(f.readline()) for _ in range(H)]

directions = [[-1,0],
              [0,-1],
              [1,0],
              [0,1]]

answer = 0
import copy
for i in range(H):
    for j in range(W):
        if Ss[i][j]==".":
            todo = deque([[i,j]])
        else:
            continue
        candidate = 0
        while len(todo) > 0:
            base = todo.pop()
            candidate += 1
            
            for direction in directions:
                checking = copy.deepcopy(base)
                for k in range(max(H,W)):
                    checking = [checking[0]+direction[0],checking[1]+direction[1]]
                    if checking[0] < 0 or checking[0] >= H or checking[1] < 0 or checking[1] >= W:
                        break
                    if Ss[checking[0]][checking[1]] == "#":
                        break
                    candidate += 1
        if candidate > answer:
            answer = candidate
print(answer)

### FIXED CODE ###

from collections import deque

H,W = map(int, input().split())
Ss = [str(input()) for _ in range(H)]

yoko = [[0 for _ in range(W)] for _ in range(H)]
tate = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if Ss[i][j] == "#" or yoko[i][j] != 0:
            continue
        else:
            paths = [[i,j]]
            temp = 1
            for k in range(j+1, W):
                if Ss[i][k] == ".":
                    temp+=1
                    paths.append([i,k])
                else:
                    break
            for path in paths:
                yoko[path[0]][path[1]] = temp

for i in range(H):
    for j in range(W):
        if Ss[i][j] == "#" or tate[i][j] != 0:
            continue
        else:
            paths = [[i,j]]
            temp = 1
            for k in range(i+1, H):
                if Ss[k][j] == ".":
                    temp+=1
                    paths.append([k,j])
                else:
                    break
            for path in paths:
                tate[path[0]][path[1]] = temp

answer = 0
for i in range(H):
    for j in range(W):
        if answer < tate[i][j]+yoko[i][j]-1:
            answer = tate[i][j]+yoko[i][j]-1
print(answer)
a, b = input()
return a * b, 2 * (a + b)

### FIXED CODE ###

a, b = map(int, raw_input(). split())
print a * b, 2 * (a + b)
n, t= map(int, input().split())
m = 1001
for i in range(n):
  c, t = map(int, input().split())
  if t < T:
    m = min(c, m)
print(c)

### FIXED CODE ###

n, T= map(int, input().split())
m = 1001
for i in range(n):
  c, t = map(int, input().split())
  if t <= T:
    m = min(c, m)
if m == 1001:
  print("TLE")
else:
  print(m)
n = input()
a = list(map(int,input().split()))
a.insert(0.5)
alen = len(a)
a.append(0.5)

ans = 0
 
med = [0 for x in range(alen +1)]
 
for i in range(alen):
    if a[i] == i:
        med[i+1] = 1
 
for i in range(len(med)):
    if med[i] == 1:
        if med[i+1] == 1:
            med[i+1] = 0
            ans += 1
        else:
            ans += 1
        
print(ans)

### FIXED CODE ###

n = input()
a = list(map(int,input().split()))
a.insert(0,0.5)
alen = len(a)
a.append(0.5)
a.append(0.5)

ans = 0
 
med = [0 for x in range(alen +2)]
 
for i in range(alen):
    if a[i] == i:
        med[i+1] = 1

for i in range(len(med)):
    if med[i] == 1:
        if med[i+1] == 1:
            med[i+1] = 0
            ans += 1
        else:
            ans += 1
        
print(ans)
print('\n'.join([l[2] for l in sorted(sorted([[l[1][0], int(l[1][1]), l[0] + 1] for l in enumerate(input().split() for _ in range(int(input())))], key=lambda l: l[1], reverse=True), key=lambda l: l[0])]))

### FIXED CODE ###

print('\n'.join([l[2] for l in sorted(sorted([[l[1][0], int(l[1][1]), str(l[0] + 1)] for l in enumerate(input().split() for _ in range(int(input())))], key=lambda l: l[1], reverse=True), key=lambda l: l[0])]))
N,A,B,C = map(int,input().split())
data = {
  "A":A,
  "B":B,
  "C":C
}
select = []
S = list(input() for _ in range(N))
for i in range(N):
  s = S[i]
  if data[s[0]] == data[s[1]] ==0:
    print("No")
    exit(0)
  elif data[s[0]] > data[s[1]]:
    data[s[0]] -= 1
    data[s[1]] += 1
    select.append(s[1])
  elif data[s[0]] < data[s[1]]:
    data[s[0]] += 1
    data[s[1]] -= 1
    select.append(s[0])
  else:
    ss = S[i+1]
    if i == N -1:
      select.append(s[0])
    elif s[0] in ss:
      data[s[0]] += 1
      data[s[1]] -= 1
      select.append(s[0])
    else:
      data[s[0]] -= 1
      data[s[1]] += 1
      select.append(s[1])

print("Yes")
for i in select:
  print(i)

### FIXED CODE ###

N,A,B,C = map(int,input().split())
data = {
  "A":A,
  "B":B,
  "C":C
}
select = []
S = list(input() for _ in range(N))
for i in range(N):
  s = S[i]
  if data[s[0]] == data[s[1]] ==0:
    print("No")
    exit(0)
  elif data[s[0]] > data[s[1]]:
    data[s[0]] -= 1
    data[s[1]] += 1
    select.append(s[1])
  elif data[s[0]] < data[s[1]]:
    data[s[0]] += 1
    data[s[1]] -= 1
    select.append(s[0])
  elif i == N-1:
    select.append(s[0])
  elif s[0] in S[i+1]:
    data[s[0]] += 1
    data[s[1]] -= 1
    select.append(s[0])
  else:
    data[s[0]] -= 1
    data[s[1]] += 1
    select.append(s[1])
print("Yes")
for i in select:
  print(i)
D,N=map(int,input().split())
print((100**D)*N if N<100 else print((N+1)*(100+D))

### FIXED CODE ###

A,B= map(int,input().split())
print(":(" if A>8 or B>8 else "Yay!")
import numpy as np

N,M = map(int, input().split())
A_array = np.array([int(i) for i in input().split()])
Current_Min = A_array[A_array.argmin()]
for j in range(M):
    B_tmp, C_tmp = map(int,input().split())
    if Current_Min >= C_tmp:
        continue
    for k in range(B_tmp):
        A_array[A_array.argmin()] = C_tmp
    
    Current_Min = A_array[A_array.argmin()]
    

print(sum(A_array))

### FIXED CODE ###

A,B = (int(i) for i in input().split())

if A>=13:
    print(B)
elif 6<=A and A<=12:
    print(int(B/2))
else:
    print(0)
s = input()
print(f'{s[0]}{s.len()-2}{s[-1]}')


### FIXED CODE ###

s = input()
print(s[0], end='')
print(len(s)-2, end='')
print(s[-1])
k = int(input())
a = list(map(int, input().split()))

def solve():
    can = []
    res = []

    for i in range(k):
        a_ = a[k-i-1]

        if i==0:
            res = [2]
        else:
            res = []
            for c in can:
                if c % a_ == 0:
                    res.append(c)
            if len(res) == 0:
                print(-1)
                return

        can = []
        for r in res:
            can = can + list(range(r, r+a_))
            can = list(set(can))

        #print(i, res, a_, can)
    print(min(can), max(can))
solve()

### FIXED CODE ###

k = int(input())
a = list(map(int, input().split()))
def solve():

    if a[k-1] != 2:
        print(-1)
        return

    mi = 2
    mx = 2

    for i in range(k):
        j = k-i-1

        mx = mx + a[j] - 1

        if j == 0:
            pass
        else:
            na = a[j-1]
            
            if mx % na != 0 and mi % na != 0 and ((mx % na) - (mi % na)) == (mx - mi):
                print(-1)
                return

            if mi%na != 0:
                mi = mi + (na - mi%na)

            if mx%na != 0:
                mx = mx - (mx % na)

    print(mi, mx)
solve()
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    h = inputIntList()
    dp = [math.inf for _ in range(N)]
    dp[0] = 0
    for i in range(N - 2):
        if abs(h[i] - h[i + 1]) + dp[i] < dp[i + 1]:
            dp[i + 1] = abs(h[i] - h[i + 1]) + dp[i]

        if abs(h[i] - h[i + 2]) + dp[i] < dp[i + 2]:
            dp[i + 2] = abs(h[i] - h[i + 2]) + dp[i]
    
    return dp[N-1]


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    h = inputIntList()
    h.append(0)
    dp = [float("inf") for _ in range(N + 2)]
    dp[0] = 0
    for i in range(N - 1):
        if abs(h[i] - h[i + 1]) + dp[i] < dp[i + 1]:
            dp[i + 1] = abs(h[i] - h[i + 1]) + dp[i]

        if abs(h[i] - h[i + 2]) + dp[i] < dp[i + 2]:
            dp[i + 2] = abs(h[i] - h[i + 2]) + dp[i]

    return dp[N - 1]


if __name__ == "__main__":
    print(main())
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

n = i_i()
a = i_l()

print(*a[::-2],*a[n%2::2])



### FIXED CODE ###

from collections import deque

n = int(input())
a = list(map(int, input().split()))

d = deque()
for i in range(n):
    if i % 2 != 0:
        d.append(a[i])
    else:
        d.appendleft(a[i])

if n % 2 == 0:
    print(*list(reversed(d)))
else:
    print(*d)
import math
A, B, C, D = map(int, input().split())
cd = gcd(C,D)
wari_A = (A-1) - ((A-1) // C + (A-1) // D - (A-1)//cd)
wari_B = B - (B// C + B // D - B//cd)
print(wari_B -wari_A)


### FIXED CODE ###

import fractions
A, B, C, D = map(int, input().split())
lcm = C * D // fractions.gcd(C,D)
wari_A = (A-1) - ((A-1) // C + (A-1) // D - (A-1)//lcm)
wari_B = B - (B// C + B // D - B//lcm)
print(wari_B -wari_A)
N=int(input())
X=list(map(int,input().split()))
i=1
XT=list(map(tairyoku,X))
ans=sum(XT)
for i in range(2,101):
    XT=list(map(tairyoku,X))
    ans=min(ans,sum(XT))
print(ans)

### FIXED CODE ###

N=int(input())
X=list(map(int,input().split()))
def tairyoku(n):
    return (n-i)**2
i=1
XT=list(map(tairyoku,X))
ans=sum(XT)
for i in range(2,101):
    XT=list(map(tairyoku,X))
    ans=min(ans,sum(XT))
print(ans)
def gcd(a, b):
	if rest == 0:
		return 1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

N, X = map(int, raw_input().split())
x = map(int, raw_input().split())

for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		N += 1
diff = []
for i in range(N - 1):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 2):
	res = gcd(res, diff[i + 1])
print res



### FIXED CODE ###

def gcd(a, b):
	if b == 0:
		return 1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

N, X = map(int, raw_input().split())
x = map(int, raw_input().split())
x.sort()
	
for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		break
if len(x) == N:
	x.append(X)
diff = []
for i in range(N):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 1):
	res = gcd(res, diff[i + 1])
print res
S
a=S[::2]
b=S[1::2]
if 'L' not in a:
	pass
	if 'R' not in b:
		print('Yes')
else:
	print('No')

### FIXED CODE ###

S=input()
a=S[::2]
b=S[1::2]
if 'L' not in a:
	if 'R' not in b:
		print('Yes')
	elif 'R' in b:
		print('No')
elif 'L' in a:
	print('No')
def main():
  import bisect
  import sys
  from itertools import accumulate
  input = sys.stdin.readline
  def hsnum(x):
    num = 0
    for i in a:
      y = x-i
      num += n-bisect.bisect_left(ls,y)
    return num
  n,m = map(int, input().split())
  a = list(map(int, input().split()))
  a.sort()
  suma = [0]+list(accumulate(a))
  lx = 0
  rx = 2*10**5+2
  error = 0
  while lx < rx:
    mx = (lx+rx)//2
    if hsnum(mx) < m:
      rx = mx
    elif hsnum(mx) > m:
      if hsnum(mx+1) < m:
        error = hsnum(mx)-m
        lx = mx
        break
      lx = mx + 1
    else:
      lx = mx
      break
  ans = 0
  for i in a:
    rema = lx - i
    j = bisect.bisect_left(a,rema)
    ans += (n-j)*i+suma[n]-suma[j]
  print(ans-error*lx)
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
  import bisect
  import sys
  from itertools import accumulate
  input = sys.stdin.readline
  def hsnum(x):
    num = 0
    for i in a:
      y = x-i
      num += n-bisect.bisect_left(a,y)
    return num
  n,m = map(int, input().split())
  a = list(map(int, input().split()))
  a.sort()
  suma = [0]+list(accumulate(a))
  lx = 0
  rx = 2*10**5+2
  error = 0
  while lx+1 < rx:
    mx = (lx+rx)//2
    if hsnum(mx) < m:
      rx = mx
    elif hsnum(mx) > m:
      lx = mx + 1
    else:
      lx = mx
      break
  if hsnum(lx)<m:
    lx -= 1
  error = hsnum(lx)-m
  ans = 0
  for i in a:
    rema = lx - i
    j = bisect.bisect_left(a,rema)
    ans += (n-j)*i-suma[j]
  ans += suma[n]*n
  print(ans-error*lx)
if __name__ == "__main__":
    main()
import copy
N=int(input())
li=[]

for n in range(N):
  li.append(int(input()))

li.sort()
li2=copy.copy(li)
S=sum(li)

for n in range(N):
  if li[n]%10==0:
    li2.pop(n)

while S%10==0 and li2!=[]:
  S-=li2.pop(0)
  
print(S)

### FIXED CODE ###

N=int(input())
li=[]

for n in range(N):
  li.append(int(input()))

li.sort()
S=sum(li)


while S%10==0 and li!=[]:
  if li[0]%10==0:
    li.pop(0)
  else:
    S-=li.pop(0)
if li==[]:
  print(0)
else:
  print(S)
n, k = map(int, input().split())

array = (list(map(int, input().split())))

product_array = []

for i in range(n):
    for j in range(n - (i + 1)):
        product_array.append(array[i] * array[i + j + 1])

product_array.sort()

print(product_array[k - 1])



### FIXED CODE ###

array = list(map(int, input().split()))

if (array[0] == array[1]) & (array[1] == array[2]) & (array[2] == array[0]):
    print('No')

elif (array[0] != array[1]) & (array[1] != array[2]) & (array[2] != array[0]):
    print('No')

else:
    print('Yes')
from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]

result = "0"

for d in range(A, B+1):
    # 排他的論理和
    result = (bin(int(result) ^ d))

print(int(result, 2))

### FIXED CODE ###

from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]

def isOdd(num):
    if num % 2 == 0:
        return False
    else:
        return True

def solve(num):
    if isOdd(num):
        if (num // 2) % 2 == 0:
            return 1
        else:
            return 0
    else:
        return solve(num+1) ^ (num+1) 


print(solve(B) ^ solve(A-1))
N=int(input())
H=list(map(int,input().split()))

for i in range(N):
  if i == 0:
    ans=='YES'
  if H[i-1] < H[i]:
    H[i] -= 1
  elif H[i-1]==H[i]:
    continue
  else:
    ans = "NO"
    break;
print(ans)

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))

for i in range(N):
  ans='Yes'
  if N == 1:
    ans='Yes'
    break;
  if i== 0:
    H[i]-=1
    continue
    
  if H[i-1] < H[i]:
    H[i] -= 1
  elif H[i-1]==H[i]:
    continue
  else:
    ans = "No"
    break;
print(ans)
A,B,C = map(int,input().split())
abc = [A,B,C]
Even = []
Odd = []
for i in range(3):
    if min(abc) == abc[i]:
        idx1 = i
    elif max(abc) == abc[i]:
        idx3 = i
    else:
        idx2 = i
    if abc[i]%2 == 0:
       Even += [i]
    else:
       Odd += [i]
       
ans = 0

if len(Even) == 3 or len(Odd) == 3:
    ans = (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Even) == 2:
    ans += 1
    abc[Even[0]] += 1
    abc[Even[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Odd) == 2:
    ans += 1
    abc[Odd[0]] += 1
    abc[Odd[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
    
print(ans)
    



### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))

def GCD(a,b):
    c = a%b
    if c == 0:
        return b
    else:
        return GCD(b,c)


def modsum(m):
    s = 0
    for a in A:
        s += m % a
    return s


tmp = 1
for i in range(N):
    tmp = tmp * A[i] // GCD(tmp,A[i])
    
ans = modsum(tmp-1)
print(ans)
x = input().split()
N = int(x[0])
M = int(x[1])
w = []
v = [] 
for i in range(N):
    temp = input().split()
    w.append(int(temp[0]))
    v.append(int(temp[1]))

mem = [-1] * (M+1)

def maxVal(i,C):
            # index i, capacity C
    if mem[C] == -1:
        if i == N:
            return 0
        else:
            skip = maxVal(i+1,C)
            if w[i] <= C:   # w[i] does not exceed capacity
                take = v[i] + maxVal(i+1,C-w[i])
            else:
                take = -1
            mem[C] =  max(skip, take)
    return mem[C]
    

print(maxVal(0,M))

### FIXED CODE ###


class obj:
    def __init__(self,w,v):
        self.w = w
        self.v = v
        self.r = v/w

x = input().split()
N = int(x[0])
M = int(x[1])
item = []
item = []
for i in range(N):
    x = input().split()
    item.append(obj(int(x[0]),int(x[1])))

maxV = 0


def getKey(x):
    return x.r


item.sort(key=getKey, reverse=True)
	
def Bound(i, C):	# object i -> n-1, capacity = C
    global item, N
    
    sw = 0
    sv = 0
    j = i
    f = 1.0
    while j < N and f == 1.0:
        wj = min(C-sw, item[j].w)
        f = float(wj)/item[j].w
        sw += f*item[j].w
        sv += f*item[j].v
        j += 1
    return sv



def dfsv4(i, sumW, sumV):
    """prning bounding, branching"""
    global maxV, item, N, M
    if i == N:
        if sumW <= M:
            maxV = max(maxV, sumV)
    else:   
        temp1 = Bound(i+1, M-sumW) + sumV
        temp2 = Bound(i,M-sumW) + sumV
        is1 = False

        if temp1 > temp2:
            is1 = True

        if is1:
            if temp1 > maxV:
                dfsv4(i+1, sumW, sumV)
            if sumW + item[i].w <= M:
                if temp2 > maxV:
                    dfsv4(i+1, sumW+item[i].w, sumV+item[i].v)
        else:
            if sumW + item[i].w <= M:
                if temp2 > maxV:
                    dfsv4(i+1, sumW+item[i].w, sumV+item[i].v)
            if temp1 > maxV:
                dfsv4(i+1, sumW, sumV)


dfsv4(0,0,0)

print(maxV)
n,k = map(int,input().split())
A = [int(x) for x in input().split()]
A.sort()

answer = sum(A[-K:])
print(answer)

### FIXED CODE ###

n,k = map(int,input().split())
A = [int(x) for x in input().split()]
A.sort()

answer = sum(A[-k:])
print(answer)
n,k = map(int,input().split())
a = list(map(int, input().split()))
ns = [0] * (n+1)
tree = []

ns = [0] * n
ns[0] = 1
# max 2*10**5
# どこかでループしてる
nexti = 0
starti = 0
endi = 0
tree.append(nexti)

while  k > 0 :
    nexti = a[nexti] - 1
    if ns[nexti] == 1:
        starti = nexti
        break
    ns[nexti] = 1
    endi = nexti
    tree.append(nexti)

x = tree.index(starti) 
# y = tree[starti:]
y = len(tree[x:])

if k - x <= 0:
    print(tree[k-1])
else:
    k = k - x
    z = k % y
    if starti == 0:
        starti = -1
    temp = tree[starti+1:]

    print(temp[z]+1)

### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    num = 1
    l = []
    s = [1]*n

    while s[num-1]:
        l.append(num)
        s[num-1] = 0
        num = a[num-1]

    if l.index(num) <= k:
        l2 = l[l.index(num):]
        kk = (k-len(set(l)-set(l2)))%len(l2)
        print(l2[kk])
    else:
        print(l[k])

main()
while 1:
  H, W = map(int, raw_input().stlip())
  if H == 0 and W == 0:
    break
  for i in range(H):
    print "#" * W 

### FIXED CODE ###

while 1:
  h, w = map(int, raw_input().split())
  if h == 0 and w == 0:
    break
  for i in range(h):
    print "#" * w
  print""
import sys
import numpy as np
from heapq import heappop, heappush


def main():
    H, W = map(int, sys.stdin.readline().split())

    grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)], dtype='U')
    grid = np.pad(grid, 1, constant_values=('#'))

    can_go = False
    i = j = 1 # start
    c = 0     # real cost
    h = max(H - i, W - j) # goalまでの推定cost 
    s = c + h # score
    q = [] # open list
    heappush(q, (s, c, i, j))
    visited = set() # closed list
    # parent = [[None * (W + 1)] for _ in range(H+1)]

    while q:
        s, c, i, j = heappop(q)
        visited.add((i, j))
        if c == s: 
            can_go = True
            break
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            y = i + dy
            x = j + dx
            if grid[y][x] == '.' and not (y, x) in visited:
                visited.add((y, x))
                h = max(H - y, W - x)
                s = h + c + 1
                heappush(q, (s, c+1, y, x))
 
    if can_go:
        ans = (grid == '.').sum() - (c + 1)
    else:
        ans = -1
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import numpy as np
from heapq import heappop, heappush


def main():
    H, W = map(int, sys.stdin.readline().split())

    grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)], dtype='U')
    grid = np.pad(grid, 1, mode='constant')

    can_go = False
    i = j = 1 # start
    c = 0     # real cost
    h = max(H - i, W - j) # goalまでの推定cost 
    s = c + h # score
    q = [] # open list
    heappush(q, (s, c, i, j))
    visited = set() # closed list
    # parent = [[None * (W + 1)] for _ in range(H+1)]

    while q:
        s, c, i, j = heappop(q)
        visited.add((i, j))
        if c == s: 
            can_go = True
            break
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            y = i + dy
            x = j + dx
            if grid[y][x] == '.' and not (y, x) in visited:
                visited.add((y, x))
                h = max(H - y, W - x)
                s = h + c + 1
                heappush(q, (s, c+1, y, x))
 
    if can_go:
        ans = (grid == '.').sum() - (c + 1)
    else:
        ans = -1
    print(ans)


if __name__ == "__main__":
    main()
N = int(input())
num = list(map(str, input().split()))
num.sort(reverse=True)
print(sum(num[::2])-sum(num[1::2]))


### FIXED CODE ###

N = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)
print(sum(num[0::2])-sum(num[1::2]))
i=0
 while???True:
  x = raw_input()
  if x == 0:
   break
  i+=1
  print "Case %d: %d" % (i,x)
 

### FIXED CODE ###

sum = 0
while 1:
   x = int(raw_input())
   sum = sum + 1
   if x == 0:
      break
   print 'Case %s: %s' %(sum, x)
def func():

    n = int(input())
    data = []
    for i in range(n):
        data.append(list(map(int,input().split())))

    for cx in range(101):
        for cy in range(101):
            for line in data:
                x = line[0]
                y = line[1]
                h = line[2]
                disx = x-cx
                disy = y-cy
                h1 = h + abs(disx) + abs(disy)
                if not h1 in dict:
                    dict[h1] = 0
                else:
                    dict[h1] += 1
                if h == 0:
                    for i in range(h1):
                        # if i == 0:
                        #     continue
                        if not h1 in dict:
                            dict[h1] = 0
                        else:
                            dict[h1] += 1

                for key in dict.keys():
                    if dict[key] == n-1:
                        print(cx,end=" ")
                        print(cy,end=" ")
                        print(key)
                        return 0

func()



### FIXED CODE ###



def func():

    n = int(input())
    data = []
    for i in range(n):
        data.append(list(map(int,input().split())))

    for cx in range(101):
        for cy in range(101):
            for line in data:
                if line[2] != 0:
                    x = line[0]
                    y = line[1]
                    h = line[2]
                    H_max = h + abs(cx - x) + abs(cy - y)
                    break
            flag = True
            for i in range(n):
                    x = data[i][0]
                    y = data[i][1]
                    h = data[i][2]
                    if h != 0:
                        if not H_max == h + abs(cx-x) + abs(cy-y):
                            flag = False
                            break
                    else:
                        if not H_max <=  abs(cx-x) + abs(cy-y):
                            flag = False
                            break
            if flag:
                print(cx,cy,H_max)
                return 0

func()