Harryxun/stf_run huggingface dataset:
def main28():
    import sys
    N, M = (int(x) for x in input().split())

    if N >= M:
        S = input()
        T = input()
    else:
        T = input()
        S = input()

    def lcm(n, m):
        gcd = 0
        for i in range(1, min(n, m)):
            if n % i == 0 and m % i == 0:
                gcd = i

        return int(n * m / gcd)

    LCM = lcm(N, M)
    a = int(LCM / max(N, M))
    b = int(LCM / min(N, M))

    for i in range(b):
        small_index = i * b
        if small_index % a == 0 and S[int(small_index / a)] != T[i]:
            print("-1")
            sys.exit()
    print(LCM)

main28()

### FIXED CODE ###

def main28():
    import sys
    N, M = (int(x) for x in input().split())

    if N >= M:
        S = input()
        T = input()
    else:
        T = input()
        S = input()

    def lcm(n, m):
        gcd = 0
        for i in range(1, min(n, m) + 1):
            if n % i == 0 and m % i == 0:
                gcd = i

        return int(n * m / gcd)

    LCM = lcm(N, M)

    a = int(LCM / max(N, M))
    b = int(LCM / min(N, M))

    for i in range(min(N, M)):
        small_index = i * b
        if int(small_index % a) == 0:
            if S[int(small_index / a)] != T[i]:
                print("-1")
                sys.exit()
    print(LCM)

main28()
n,k=map(int,input().split())
while n>=0:
  n=ans(n-k)
  if n-k<=0:
    print(n)

### FIXED CODE ###

n,k=map(int,input().split())
print(min(n%k,abs(n%k-k)))
N,X = map(int, input().split())
L = list(map(int, input().split()))
i = 2
D = 0
count = 0

while D < X+1:
  D += L[i-1]
  i += 1
  count += 1

print(count)
  

### FIXED CODE ###

N,X = map(int, input().split())
L = list(map(int, input().split()))
count = 1
D = 0

for i in range(N):
  D += L[i]
  if D <= X:
    count += 1
  else:
    break

print(count)
N = int(input())
if(N == 1):
  return(1)
elif(N %2 == 0):
  return(0.5)
elif(N %2 == 1):
  return((N+1)/(2*N))

### FIXED CODE ###

N = int(input())
if(N == 1):
  print(1)
elif(N %2 == 0):
  print(0.5)
elif(N %2 == 1):
  print((N+1)/(2*N))
a = str(input())
print(a.count(1))

### FIXED CODE ###

a = str(input())
print(a.count('1'))
n=int(input())
l=list(map(int,inout().split()))
l.sort()
new=(l[0]+[1])/2
if n>=3:
  for i in range(2,n):
    new=(new+l[i])/2
  print(new)
else:
  print((l[0]+l[1])/2)
    

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l.sort()
new=(l[0]+l[1])/2
if n>=3:
  for i in range(2,n):
    new=(new+l[i])/2
  print(new)
else:
  print((l[0]+l[1])/2)
import math
A,B,H,M = map(int,input().split())
A2 = A**2
B2 = B**2
a = 30*H + 0.5*M
b = M*6
F  = 0

ab = min(abs(a-b),abs(360-a-b))
ab1 = math.cos(math.radians(ab))
print(ab)
ab_angle = -2*A*B*ab1
ans = (A2 + B2 +ab_angle)**0.5
if ab  == 0:
    print(abs(A-B))
elif ab == 180:
    printF(A+B)
else:
    print(ans)

### FIXED CODE ###

import math
A,B,H,M = map(int,input().split())
a = 30*H + 0.5*M
b = M*6
if abs(a-b) < 180:
    ab = abs(a-b)
else:
    ab = 360 - abs(a-b)
ab1 = round(math.cos(math.radians(ab)),20)
ans = round(math.sqrt(A**2 + B**2 - 2 * A* B*ab1),20)
print(round(ans,20))
import sys
sys.setrecursionlimit(100000)
x=int(input())
def factorial(n):
  a=1
  if n==1:
    return a
  else:
    a= n*factorial(n-1)
    return a
print(factorial(x)%(10**9+7))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
x=int(input())
def factorial(n):
  a=1
  if n==1:
    return a
  else:
    a= n*factorial(n-1)
    return a%(10**9+7)
print(factorial(x))
N = int(input())
ans = ""
while N > 26:
    N, mod = divmod(N, 26)
    if mod == 0: mod = 26 
    ans += chr(96+mod)
    if N < 27:break
ans += chr(96+mod) 
print(ans[::-1])

### FIXED CODE ###

N = int(input())
ans = ""
while N > 0:
    N -= 1
    ans += chr(97 + N%26)
    N //= 26
print(ans[::-1])
def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0

### FIXED CODE ###

import heapq

def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0
n=int(input())
a=sorted([int(i) for i in input().split()])
gcd1=[0]*n
gcd2=[0]*n
for i in range(n):
    if i!=0:
        gcd1[i]=gcd(a[0],a[i])
    if i!=1:
        gcd2[i]=gcd(a[1],a[i])
print(max(max(gcd1),max(gcd2)))

### FIXED CODE ###

def gcd(num1,num2):
    if num2==0:
        return num1
    return gcd(num2,num1%num2)
from collections import deque
n=int(input())
a=[int(i) for i in input().split()]
left_gcd=a[0]
right_gcd=a[-1]
left=deque([])
right=deque([])
for i in a:
    left_gcd=gcd(left_gcd,i)
    left.append(left_gcd)
for i in a[::-1]:
    right_gcd=gcd(right_gcd,i)
    right.append(right_gcd)
right=deque(reversed(right))
Max=max(right[1],left[-2])
for i in range(1,n-1):
    Max=max(Max,gcd(left[i-1],right[i+1]))
print(Max)
N=int(input())
A=list(map(int,input().split()))
count=0
for num in range(N)
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
    else:
        count=count
print (count)    

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
count=0
for num in range(N-1):
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
        A[num+1]=A[num]
    else:
        continue        
print(count)
# -*- coding: utf-8 -*-
import sys


def input():
    return sys.stdin.readline().strip()


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

dp = [[0 for _ in range(3)] for _ in range(N + 1)]

or i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + DATA[i][k])

res = 0

for v in range(3):
    res = max(res, dp[N][v])

print(res)


### FIXED CODE ###

import sys

input = sys.stdin.readline

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

dp = [[0 for i in range(3)] for j in range(vacation+1)]
def chmax(a, b):
    if a > b:
        return a
    else:
        return b

for i in range(vacation):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = chmax(dp[i+1][k], dp[i][j] + lst_happiness[i][k])
ans = 0
for i in range(3):
    ans = chmax(ans, dp[vacation][i])
print(ans)
n, m = map(int, input().split())
d = [int(input()) for _ in range(n)]
c = [int(input()) for _ in range(m)]
h = [[10e10 for _ in range(m)] for _ in range(n)]
q = [[0, 0, 0]]
while True:
    nq = []
    for i in q:
        dn = i[2] + d[i[0]] * c[i[1]] 
        if dn < min(h[i[0]][:i[1] + 1]):
            if i[0] < n - 1:
                nq.append([i[0] + 1, i[1] + 1, dn])
            h[i[0]][i[1]] = dn
        if n - i[0] < m - i[1] and i[1] < m - 1:
            nq.append([i[0], i[1] + 1, i[2]])
    if nq == []:
        break
    q = nq
print(min(h[-1]))


### FIXED CODE ###

n, m = map(int, input().split())
d = [int(input()) for _ in range(n)]
c = [int(input()) for _ in range(m)]
h = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
    for j in range(i, m):
        if i == j:
            h[i][j] = h[i -1][j - 1] + d[i] * c[j]
        else:
            h[i][j] = min(h[i][j - 1], h[i - 1][j - 1] + d[i] * c[j])
            
print(h[n - 1][m - 1])
def main():
    input_data = [int(input()) for i in range(5)]
    k = int(input())

    input_data.sort()
    input_data..reverse()

    temp = input_data[0] - input_data[4]
    if temp > k :
        print(":(")
    else:
        print('Yay!')

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    input_data = [int(input()) for i in range(5)]
    k = int(input())

    input_data.sort()
    input_data.reverse()

    temp = input_data[0] - input_data[4]
    if temp > k :
        print(":(")
    else:
        print('Yay!')

if __name__ == '__main__':
    main()
s = input()
L = []

for i in range(len(s)):
  if s[i] == '0':
    L.append('0')
  elif s[i] == '1':
    L.append('1')
  elif s[i] == 'B':
    del L[-1]

print(''.join(L))

### FIXED CODE ###

s = input()
L = []

for i in range(len(s)):
  if s[i] == '0':
    L.append('0')
  elif s[i] == '1':
    L.append('1')
  elif s[i] == 'B' and len(L) > 0:
    del L[-1]

print(''.join(L))
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s) - min(s)

ans = []

for i in range(10 ** digit + 1,10 ** (digit + 1)):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j]-1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

print(min(ans))

### FIXED CODE ###

n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            if int(str(i)[s[j] - 1]) != c[j]:
                    flg = False
        if flg:
            print(i)
            break
if not flg:
    print(-1)
N = int(input())
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
dic = {chr(i+ord("a")):[] for i in range(26)}
for i, s in enumerate(S):
    dic[s].append(i)
for q in Query:
    t,a,b = q.split()
    if(t == "1"):
        a_index = int(a)-1
        dic[S[a_index]].remove(a_index)
        dic[b].append(a_index)
    if(t == "2"):
        a_index = int(a)-1
        b_index = int(b)-1
        cnt = 0
        for i in range(26):
            for d in dic[chr(i+ord("a"))]:
                if(a_index<=d<=b_index):
                    cnt += 1
                    break
        print(cnt)

### FIXED CODE ###

from bisect import insort_left, bisect_left
N = int(input())
S = list(input())
Q = int(input())
Query = [input() for _ in range(Q)]
dic = {chr(i+ord("a")):[] for i in range(26)}
for i, s in enumerate(S):
    dic[s].append(i)
for q in Query:
    t,a,b = q.split()
    a = int(a)-1
    if(t == "1"):
        if(S[a]==b):
            continue
        tmp_index = bisect_left(dic[S[a]],a)
        dic[S[a]].pop(tmp_index)
        insort_left(dic[b],a)
        S[a] = b
    elif(t == "2"):
        b = int(b)-1
        cnt = 0
        for li in dic.values():
            if li and a<=li[-1] and li[bisect_left(li, a)] <= b:
                cnt += 1
        print(cnt)
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
s_A = sum(A)

if N >= s_A:
    print(N - s_A)
elif N < s_A:
    print(-1)



### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in a:
    n-=i
    if n<0: #宿題の総日数が夏休みの日数を上回った場合
        print(-1)
        exit()
print(n)
N=input()
M=len(str(N))
K=int(N[0])
ans=0
for i in range (M):
	ans+=N[i]

print(max(9*(M-1)+(K-1)),ans)

### FIXED CODE ###

N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
sum=0
for i in range(len(N)):
	sum+=int(N[i])
K=0
if L>0:
	D=M
else:
	D=M+1
for i in range(D):
	j=str(i)
	if len(j)==1:
		K=max(K,(int(j)))
	else:
		K=max(K,(int(j[0])+int(j[1])))
print(max(sum,K+L))
H,W,M = map(int,input().split())

horizontal = [[i,0] for i in range(H)]
vertical = [[i,0] for i in range(W)]
table = {}

for i in range(M):
    h,w = map(int,input().split())
    h -= 1
    w -= 1
    table[(h,w)] = True
    vertical[w][1] += 1
    horizontal[h][1] += 1

vertical.sort(key=lambda x:-x[1])
horizontal.sort(key=lambda x:-x[1])

h_max = horizontal[0][1]
v_max = vertical[0][1]
    
for i in range(H):
    if horizontal[i][1]<h_max:
        break
for j in range(W):
    if vertical[j][1]<v_max:
        break

flag = False
for h in horizontal[:i]:
    for v in vertical[:j]:
        if table.get((h[0],v[0]))==None:
            flag = True
            break
    if flag:
        break

if flag:
    print(h_max+v_max)
else:
    print(h_max+v_max-1)

### FIXED CODE ###

n,x,t = map(int,input().split())

c = n//x
if n%x == 0:
    print(c*t)
else:
    print((c+1)*t)
N = int(input())
nums = list(map(int,input().split()))
judge = "Yes"

if N  == 1:
  print("Yes")

else:
  for i in range(N-1):
    dev = nums[i+1] - nums[i]
    if dev < 0:
      if dev != -1:
        judge = "No"
        break
      else:
        if i < N-1:
          if (nums[i+2] - nums[i+1] < 0):
            judge = "No"
            break
          else:
            continue
        else:
          continue
          
  if judge == "Yes":
    print("Yes")
  else:
    print("No")

  
        



### FIXED CODE ###

N = int(input())
nums = list(map(int,input().split()))
nums = nums[::-1]
judge = "Yes"

for i in range(N-1):
  dev = nums[i+1] - nums[i]
  if dev > 1:
    judge =  "No"
    break
  elif dev == 1:
    nums[i+1] = nums[i+1] - 1
  else:
    continue
    
print(judge)
A = int(input())
B = int(input())

print((A-1)*(B-1))

### FIXED CODE ###


A,B =  [int(x) for x in input().split()]


print((A-1)*(B-1))
k=int(input())
dp=[[0]*10 for _ in range(5)]
dp[0]=[1]*10
for i in range(4):
    dp[i+1][0]=dp[i][0]+dp[i][1]
    for j in range(1,9):
        dp[i+1][j]=dp[i][j-1]+dp[i][j]+dp[i][j+1]
    dp[i+1][9]=dp[i][8]+dp[i][9]

a=0
h=0
s=0
for i in range(5):
    for j in range(1,10):
        a+=dp[i][j]
        if a>=k:
            a-=dp[i][j]
            s=k-a
            h=j
            d=i
            break
        else:
            continue
    if h!=0:
        break
ans=str(h)
q=0
w=0
for p in range(d):
    for j in range(max(0,h-1),min(h+2,10)):
        q+=dp[p][j]
        if q>=s:
            q-=dp[p][j]
            s=s-a
            ans+=str(j)

            q=0
        elif q==s:
            ans+=str(j)
            w=1
            break
            
        if s==0:
            w=1
            break
    if w==1:
        break
print(int(ans))

### FIXED CODE ###

k=int(input())
lun=[1,2,3,4,5,6,7,8,9]
for i in range(10**5+1):
    if len(lun)>=k:
        break
    di=lun[i]%10
    for j in range(max(0,di-1),min(9,di+1)+1):
        lun.append(lun[i]*10+j)
print(lun[k-1])
import sys
N = int(input())
C = [0]
#c = [int(sys.stdin.readline()) for i in range(N)]
n = N
for i in range(1, n + 1):
    c = int(sys.stdin.readline())
    if c == C[-1]:
        N -= 1
    else:
        C.append(c)
#C = C+c
dp = [0] * (N + 2)
color = [[]for i in range((2*(10**4)+2))]
dp[0] = 1
dp[1] = 1
color[C[1]].append(1)
for i in range(2, N+1):
    dp[i] = dp[i - 1] + sum([dp[col - 1] for col in color[C[i]]])
    color[C[i]].append(i)
    dp[i] %= (10 ** 9 + 7)
# print(dp)
print(dp[N])


### FIXED CODE ###

import sys
N = int(input())
C = [0]
n = N
for i in range(1, n + 1):
    c = int(sys.stdin.readline())
    if c == C[-1]:
        N -= 1
    else:
        C.append(c)
dp = [0] * (N + 2)
dp[0] = 1
dp[1] = 1
cumsum = [0] * (2 * (10 ** 5) + 2)
cumsum[C[1]] = 1
for i in range(2, N+1):
    dp[i] = dp[i - 1] + cumsum[C[i]]
    cumsum[C[i]] += dp[i-1]
    dp[i] %= (10 ** 9 + 7)
print(dp[N])
N, K = map(int, (input().split()))
    h = list(map(int, input().split()))

    dp = [float("inf")] * len(h)
    dp[0] = 0

    for i in range(len(h)):
        for j in range(1, min(i + 1, K + 1)):
            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])

    print(dp[N - 1])

### FIXED CODE ###

N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])
n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
    e.append((a - 1, b - 1))
c = list(map(int, input().split()))
c.sort(reverse=True)

def point(x, prev, turn=0):
    if turn > n:
        return
    dp[x] = c[n - dp.count(0)]
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

ans = 0
for i in range(n):
    dp = [0] * n
    point(i, -1)

    m = 0
    for a, b in e:
        m += min(dp[a], dp[b])
    if m > ans:
        ans = m
        d = dp

print(ans)
print(" ".join(map(str, d)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
c = list(map(int, input().split()))
c.sort(reverse=True)

num = 0
def point(x, prev, turn=0):
    global num
    if turn > n:
        return
    dp[x] = c[num]
    num += 1
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

for i in range(n):
    if len(edge[i]) > 1:
        continue
    else:
        dp = [0] * n
        point(i, -1)
        break

ans = sum(c) - max(c)

print(ans)
print(" ".join(map(str, dp)))
i = 0
x = input()
while x != "0":
  print('Case ' i ': ' x)
  x = input()
  i+=1


### FIXED CODE ###

i,x = 1,input()
while x != "0":
  print('Case '+str(i)+': '+x)
  i,x = i+1,input()
import numpy as np


N, M = map(int, input().split())
A, B = list(), list()
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A = np.array(A)
B = np.array(B)

n_bins = 0
cost = 0
indices = np.argsort(A)
for idx in indices:
    print(idx, B[idx], A[idx] * B[idx])
    # enough bins @idx
    if n_bins + B[idx] > M:
        cost += A[idx] * (M - n_bins)
        break
    # buy all bins
    else:
        n_bins += B[idx]
        cost += A[idx] * B[idx]
print(cost)

### FIXED CODE ###

import numpy as np


H, W = map(int, input().split())
h, w = map(int, input().split())
board = np.ones((H, W), dtype=int)
board[0:h] = 0
board[:, 0:w] = 0
print(board.sum())
import collections

n = int(input())

co = collectiosn.Counter([int(input()) for i in range(n)])

c =0

for i in co.values():
    if i % 2 != 0:
        c  +=1
print(c)

### FIXED CODE ###

import collections

n = int(input())

co = collections.Counter([int(input()) for i in range(n)])

c =0

for i in co.values():
    if i % 2 != 0:
        c  +=1
print(c)
n = int(input())
fizzbuzz = [i for i in range(n+1) if i%5!=0 and i%3!=0]
print(sum(fizzbuss))

### FIXED CODE ###

n = int(input())
fizzbuzz = [i for i in range(n+1) if i%5!=0 and i%3!=0]
print(sum(fizzbuzz))
R = int(input())
 
if R < 1200:
  r = 'ABC'
elif R < 2800:
  r = 'ARC':
else:
  r ='AGC'
print(r)

### FIXED CODE ###

R = int(input())
 
if R < 1200:
  r = 'ABC'
elif R < 2800:
  r = 'ARC'
else:
  r ='AGC'
 
print(r)
import collections
n, m  = [int(i) for i in input().split(' ')] 
edges = collections.defaultdict(list)
for i in range(m):
    s,d = [int(i) for i in input().split(' ')] 
    edges[s-1].append(d-1) 
dp = [-1]*n
maxPath = 0 
def dfs(node): 
    global maxPath
    global dp
    if dp[node]>=0:
        return dp[node]+1  
    ans = 0 
    for i in edges[node]: 
        ans = max(ans,dfs(i))
    dp[node] = ans
    maxPath = max(maxPath, ans) 
    return ans+1 
for i in range(n):
    dfs(i)
print(maxPath)


### FIXED CODE ###

import collections
import sys
from functools import lru_cache
sys.setrecursionlimit(int(10**9))
n, m  = [int(i) for i in input().strip().split(' ')] 
edges = collections.defaultdict(list)
for i in range(m):
    s,d = [int(i) for i in input().strip().split(' ')]
    edges[s-1].append(d-1) 
# dp = [-1]*n
maxPath = 0 
@lru_cache(None)
def dfs(node): 
    ans = 0 
    for i in edges[node]:
        ans = max(ans,dfs(i)+1)
    return ans

for i in range(n):
    maxPath = max(dfs(i), maxPath) 
print(maxPath)
def search_center(xyh_list):
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    highest = xyh_list[0]
    for cx in range(101):
        for cy in range(101):
            h = highest[2] + abs(highest[0] - cx) + abs(highest[1] - cy)
            matched = True
            for xyh in xyh_list[1:]:
                if xyh[2] == 0:
                    if h - abs(highest[0] - cx) - abs(highest[1] - cy) > 0:
                        matched = False
                        break
                else:
                    hh = xyh[2] + abs(xyh[0] - cx) + abs(xyh[1] - cy)
                    if h != hh:
                        matched = False
                        break
            if matched:
                return cx, cy, h
    return None


def main():
    N = int(input())
    xyh_list = [list(map(int, input().split(' '))) for _ in range(N)]
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    cx, cy, ph = search_center(xyh_list)
    print('{} {} {}'.format(cx, cy, ph))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def search_center(xyh_list):
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    highest = xyh_list[0]
    for cx in range(101):
        for cy in range(101):
            h = highest[2] + abs(highest[0] - cx) + abs(highest[1] - cy)
            matched = True
            for xyh in xyh_list[1:]:
                if xyh[2] == 0:
                    if h - abs(xyh[0] - cx) - abs(xyh[1] - cy) > 0:
                        matched = False
                        break
                else:
                    hh = xyh[2] + abs(xyh[0] - cx) + abs(xyh[1] - cy)
                    if h != hh:
                        matched = False
                        break
            if matched:
                return cx, cy, h
    return None


def main():
    N = int(input())
    xyh_list = [list(map(int, input().split(' '))) for _ in range(N)]
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    cx, cy, ph = search_center(xyh_list)
    print('{} {} {}'.format(cx, cy, ph))


if __name__ == '__main__':
    main()
s=list(input())
ans=""
for i in range(len(s)):
  if s[i-1]==B:
    ans=ans[:-1]
  else:
    ans+=s[i-1]

### FIXED CODE ###

s=input()
ans=""
for i in range(len(s)):
  if s[i]=="B":
    ans=ans[:-1]
  else:
    ans+=s[i]
print(ans)
N=int(input())
l_list = list(int(input()) for _ in range(N))
max_l=max(l_list)
if sum(l_list)-max_l>max_l:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=int(input())
table=list(map(int,input().split()))
if max(table)*2<sum(table[:]):
  print("Yes")
else :
  print("No")
import math

N,P=map(int,input().split())
a=math.sqrt(P)
if N > 3 :
    b=math.sqrt(a)
    a=b

res=1
for i in range(1,int(a)+1):
    if P % i**N: continue
    res = i

print(res)

### FIXED CODE ###

print(input().count("2"))
import math

Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)

c_min = int(a/c) if a % c == 0 else int(a/c) + 1
c_max = int(b/c)
delta_c = c_max - c_min + 1

d_min = int(a/d) if a % c == 0 else int(a/d) + 1
d_max = int(b/d)
delta_d = d_max - d_min + 1

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

cd = lcm(c, d)
cd_min = int(a/cd) if a % c == 0 else int(a/cd) + 1
cd_max = int(b/cd)
delta_cd = cd_max -cd_min + 1

num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

### FIXED CODE ###

from fractions import gcd
Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)
delta_c = b//c - (a-1)//c
delta_d = b//d - (a-1)//d
def lcm(x, y):
    return (x * y) // gcd(x, y)
cd = lcm(c, d)
delta_cd = b//cd - (a-1)//cd
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')
s=input()
if(len(s)>=4)
if(s[:4]=="YAKI"): print("YES")
else : print("NO")

### FIXED CODE ###

s=input()
if(len(s)>=4) :
	if(s[:4]=="YAKI"): 
		print("Yes")
	else : print("No")
else : print("No")