Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]

    sset = set(sl)

    ans = 0
    for s in sset:
        scount = sl.count(s)
        ans += sum([i for i in range(scount)])

    print(ans)


Fixed submission:
import sys
import collections

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

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]
    c = collections.Counter(sl)

    dict = collections.defaultdict(int)
    for v in c.values():
        if v == 1:
            continue

        dict[v] += 1

    ans = 0
    for k, v in dict.items():
        ans += sum([i for i in range(k)]) * v

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]

    sset = set(sl)

    ans = 0
    for s in sset:
        scount = sl.count(s)
        ans += sum([i for i in range(scount)])

    print(ans)


Fixed submission:
import sys
import collections

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

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]
    c = collections.Counter(sl)

    dict = collections.defaultdict(int)
    for v in c.values():
        if v == 1:
            continue

        dict[v] += 1

    ans = 0
    for k, v in dict.items():
        ans += sum([i for i in range(k)]) * v

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]

    count = 0
    for i in range(n):
        for j in range(i+1, n):
            if sl[i] == sl[j]:
                count += 1

    print(count)


Fixed submission:
import sys
import collections

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

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]
    c = collections.Counter(sl)

    dict = collections.defaultdict(int)
    for v in c.values():
        if v == 1:
            continue

        dict[v] += 1

    ans = 0
    for k, v in dict.items():
        ans += sum([i for i in range(k)]) * v

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if __name__ == "__main__":
    n = int(input())
    al = [int(input()) for i in range(n)]

    for i in range(n):
        print(max(al[:i] + al[i+1:]))


Fixed submission:
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    al = [(i, int(input())) for i in range(n)]

    al.sort(key = itemgetter(1), reverse = True)

    for i in range(n):
        print(al[0][1] if i != al[0][0] else al[1][1])
Buggy python submission (verdict: Runtime Error):
import sys
import math

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

def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

if __name__ == "__main__":
    n, k = map(int, input().split())

    for i in range(1, k+1):
        print((combination(n-k+1, i) * combination(k-1, i-1)) % (10**9+7))


Fixed submission:
import sys
import math

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

def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

if __name__ == "__main__":
    n, k = map(int, input().split())

    for i in range(1, k+1):
        if n-k+1 >= i and k-1 >= i-1:
            print((combination(n-k+1, i) * combination(k-1, i-1)) % (10**9+7))
        else:
            print(0)

Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations

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

if __name__ == "__main__":
    n, k = map(int, input().split())

    for i in range(1, k+1):
        mul = 1
        div = 1

        for j in range(i):
            if j == i-1:
                mul *= ((n-k+1)-j)
                div *= (i-j)
            else:
                mul *= ((n-k+1)-j) * ((k-1)-j)
                div *= (i-j) * ((i-1)-j)

        print(int((mul / div) % (10**9+7)))


Fixed submission:
import sys
import math

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

def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

if __name__ == "__main__":
    n, k = map(int, input().split())

    for i in range(1, k+1):
        if n-k+1 >= i and k-1 >= i-1:
            print((combination(n-k+1, i) * combination(k-1, i-1)) % (10**9+7))
        else:
            print(0)

Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations

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

if __name__ == "__main__":
    n, k = map(int, input().split())

    for i in range(1, k+1):
        mul = 1
        div = 1

        for j in range(i):
            mul *= ((n-k+1)-j)
            div *= (i-j)

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

        print(int(mul / div % (10**9+7)))


Fixed submission:
import sys
import math

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

def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

if __name__ == "__main__":
    n, k = map(int, input().split())

    for i in range(1, k+1):
        if n-k+1 >= i and k-1 >= i-1:
            print((combination(n-k+1, i) * combination(k-1, i-1)) % (10**9+7))
        else:
            print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]

    is_possible = True
    for e in l:
        if sum([i[0] for i in l if i[1] <= e[1]]) > e[1]:
            is_possible = False
            break

    print("Yes" if is_possible else "No")


Fixed submission:
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    l.sort(key=itemgetter(1))

    is_possible = True
    sum = 0
    for e in l:
        sum += e[0]
        if sum > e[1]:
            is_possible = False
            break

    print("Yes" if is_possible else "No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    limits = set([e[1] for e in l])

    is_possible = True
    for e in l:
        if sum([i[0] for i in l if i[1] <= e[1]]) > e[1]:
            is_possible = False
            break

    print("Yes" if is_possible else "No")


Fixed submission:
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    l.sort(key=itemgetter(1))

    is_possible = True
    sum = 0
    for e in l:
        sum += e[0]
        if sum > e[1]:
            is_possible = False
            break

    print("Yes" if is_possible else "No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    limits = set([ e[1] for e in l])

    is_possible = True
    for e in limits:
        if sum([i[0] for i in l if i[1] <= e]) > e:
            is_possible = False
            break

    print("Yes" if is_possible else "No")


Fixed submission:
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    l.sort(key=itemgetter(1))

    is_possible = True
    sum = 0
    for e in l:
        sum += e[0]
        if sum > e[1]:
            is_possible = False
            break

    print("Yes" if is_possible else "No")
Buggy python submission (verdict: Runtime Error):
import sys

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

if __name__ == "__main__":
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    l.insert(0, 0)

    num = 0
    sum = 0
    while sum + l[num] <= x:
        sum += l[num]
        num += 1

    print(num)


Fixed submission:
import sys

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

if __name__ == "__main__":
    n, x = map(int, input().split())
    llist = list(map(int, input().split()))
    llist.insert(0, 0)

    res = 0
    sum = 0
    for l in llist:
        if (sum + l) <= x:
            res += 1
            sum += l
        else:
            break
    
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if __name__ == "__main__":
    a, b, k = map(int, input().split())

    l = [i for i in range(a, b+1)]
    ans = sorted(set(l[:k] + l[-k:]))

    [print(i) for i in ans]


Fixed submission:
import sys

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

if __name__ == "__main__":
    a, b, k = map(int, input().split())

    mid = (a + b) // 2

    if a + (k - 1) >= mid:
        [print(i) for i in range(a, b+1)]
    else:
        [print(i) for i in range(a, a+k)]
        [print(i) for i in range(b-(k-1), b+1)]
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
    si = sorted(input())
    s.append(si)
ans = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            ans += 1
print(ans)


Fixed submission:
from collections import Counter


N = int(input())
c = Counter()
for _ in range(N):
    si = "".join(sorted(input()))
    c[si] += 1

ans = sum([n*(n - 1) // 2 for n in c.values()])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M, P = map(int, input().split())

ABC = []
for _ in range(M):
    a, b, c = map(int, input().split())
    ABC.append((a - 1, b - 1, P - c))

# preprocess
to = [[] for _ in range(N)]
fr = [[] for _ in range(N)]
for a, b, c in ABC:
    to[a].append(b)
    fr[b].append(a)

visitable_s = [False] * N
q = deque()
q.append(0)
visitable_s[0] = True
while len(q):
    a = q.pop()
    for b in to[a]:
        if not visitable_s[b]:
            visitable_s[b] = True
            q.append(b)

visitable_g = [False] * N
q = deque()
q.append(N - 1)
visitable_g[N - 1] = True
while len(q):
    a = q.pop()
    for b in fr[a]:
        if not visitable_g[b]:
            visitable_g[b] = True
            q.append(b)

visitable = [visitable_s[i] and visitable_g[i] for i in range(N)]
inf = float("inf")
d = [inf] * N
d[0] = 0

# Bellman-Ford
for i in range(N):
    for a, b, c in ABC:
        if not visitable[a] or not visitable[b]:
            continue
        if d[b] <= d[a] + c:
            continue
        if i == N - 1:
            print(-1)
            exit()
        d[b] = d[a] + c
ans = d[N - 1]
print(max(0, -d[N - 1]))


Fixed submission:
N, M, P = map(int, input().split())

ABC = []
for _ in range(M):
    a, b, c = map(int, input().split())
    ABC.append((a - 1, b - 1, P - c))

inf = float("inf")
d = [inf] * N
d[0] = 0

# Bellman-Ford
for i in range(N):
    for a, b, c in ABC:
        if d[b] <= d[a] + c:
            continue
        d[b] = d[a] + c
ans = d[N - 1]
for i in range(N):
    for a, b, c in ABC:
        if d[b] <= d[a] + c:
            continue
        d[b] = d[a] + c
if ans != d[N - 1]:
    print(-1)
else:
    print(max(0, -d[N - 1]))
Buggy python submission (verdict: Runtime Error):
3 2 3


Fixed submission:
P, Q, R = map(int, input().split())
print(min(P + Q, Q + R, R + P))
Buggy python submission (verdict: Runtime Error):
8
27 23 76 2 3 5 62 52

Fixed submission:
N = int(input())
W = [int(s) for s in input().split()]
ans = float("inf")
for i in range(1, N):
    ans = min(ans, abs(sum(W[:i]) - sum(W[i:])))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 1000000007
L = input()
ans1 = 1
ans2 = 0
for i in range(len(L)):
    if L[i] == "0":
        continue
    ans2 += ans1 * 3 ** (len(L) - i - 1) % mod
    ans2 %= mod
    ans1 *= 2
    ans1 %= mod
print((ans1 + ans2) % mod)


Fixed submission:
mod = 1000000007

L = input()

threes = [1] * (len(L) + 1)
for i in range(1, len(L) + 1):
    threes[i] = threes[i-1] * 3 % mod

ans1 = 1
ans2 = 0
for i in range(len(L)):
    if L[i] == "0":
        continue
    ans2 += ans1 * threes[len(L) - i - 1] % mod
    ans2 %= mod
    ans1 *= 2
    ans1 %= mod
print((ans1 + ans2) % mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
c = [int(s) for s in input().split()]
c.sort(reverse=True)

anst = [0] * (N + 1)
anss = 0


def visit(a, prev):
    global anst, anss
    ans = 0
    for b in tree[a]:
        if b != prev:
            ci = visit(b, a)
            anss += ci
    ci = c.pop()
    anst[a] = ci
    return ci


visit(1, 1)
print(anss)
print(" ".join((str(i) for i in anst[1:])))


Fixed submission:
import sys
sys.setrecursionlimit(200010)

N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
c = [int(s) for s in input().split()]
c.sort(reverse=True)

anst = [0] * (N + 1)
anss = 0


def visit(a, prev):
    global anst, anss
    ans = 0
    for b in tree[a]:
        if b != prev:
            ci = visit(b, a)
            anss += ci
    ci = c.pop()
    anst[a] = ci
    return ci


visit(1, 1)
print(anss)
print(" ".join((str(i) for i in anst[1:])))
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        n = R * r + G * g
        if N - n >= 0 and (N - n) % B == 0:
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        n = R * r + G * g
        if N - n >= 0 and (N - n) % B == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
try:
    from math import gcd
except:
    from fractions import gcd
import operator
from collections import deque


class Segtree:
    """
    st = Segtree(4, f=operator.add, e=0)
    st[1:] = [4, 9, 16]
    st[0] = -99
    assert st[-1] == 16
    assert st[:] == [-99, 4, 9, 16]
    assert st.grasp(1, 3) == 13
    """

    def __init__(self, n, f=operator.add, e=0):
        """all(f(v, e) == f(e, v) == v for v in data)"""
        self.r = range(n)
        self.size = 2 ** ((n - 1).bit_length())
        self.tree = [e] * (2 * self.size)
        self.f = f
        self.iden = e

    def __len__(self):
        return len(self.r)

    def __list__(self):
        return self.tree[self.size-1:self.size-1+len(self.r)]

    def __repr__(self):
        return repr(list(self))

    def grasp(self, i=0, j=None):
        """reduce(f, data[i:j], e)"""
        if j is None:
            j = len(self)
        i = self.size - 1 + max(i, 0)
        j = self.size - 1 + min(j, len(self))
        ans = self.iden
        while j - i > 0:
            if i & 1 is 0:
                ans = self.f(self.tree[i], ans)
            if j & 1 is 0:
                ans = self.f(ans, self.tree[j-1])
            i = i >> 1
            j = (j - 1) >> 1
        return ans

    def __getitem__(self, i):
        r = self.r[i]
        if isinstance(r, int):
            return self.tree[self.size - 1 + r]
        else:
            return [self.tree[self.size - 1 + ri] for ri in r]

    def __setitem__(self, i, v):
        """Extra elements will be ignored when i is a slice."""
        r = self.r[i]
        if isinstance(r, int):
            r = [r]
            v = [v]
        q = deque()
        s = set()

        def addnext(j):
            k = (j - 1) // 2
            if k >= 0 and k not in s:
                q.append(k)
                s.add(k)

        for ri, vi in zip(r, v):
            j = self.size - 1 + ri
            self.tree[j] = vi
            addnext(j)
        while len(q):
            j = q.popleft()
            s.remove(j)
            vl = self.tree[2 * j + 1]
            vr = self.tree[2 * j + 2]
            self.tree[j] = self.f(vl, vr)
            addnext(j)


N = int(input())
A = [int(s) for s in input().split()]
st = Segtree(N, f=gcd, e=0)
st[:] = A
ans = max([gcd(st.grasp(0, i), st.grasp(i+1)) for i in range(N)])
print(ans)


Fixed submission:
try:
    from math import gcd
except:
    from fractions import gcd
from itertools import accumulate

N = int(input())
A = [int(s) for s in input().split()]
s = [0] + list(accumulate(A, gcd))
t = list(reversed(list(accumulate(reversed(A), gcd)))) + [0]

ans = max([gcd(s[i-1], t[i]) for i in range(1, N+1)])
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import inf
from collections import deque

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)


Fixed submission:
try:
    from math import inf
except:
    inf = float("inf")
from collections import deque

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, M = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
A.sort()
B.sort()
table = [[0] * M for _ in range(N)]
i = N
j = M
ans = 1
for n in range(N*M, 0, -1):
    if A[i-1] == n and B[j-1] == n:
        i -= 1
        j -= 1
        if table[i][j] > 0:
            print(0)
            sys.exit()
        table[i][j] = n
    elif A[i-1] == n:
        i -= 1
        ans *= M - j
    elif B[j-1] == n:
        j -= 1
        ans *= N - i
    else:
        ans *= (N - i) * (M - j) - (N*M - n)
print(ans % 1000000007)


Fixed submission:
import sys
mod = 1000000007
N, M = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
A.sort()
B.sort()
i = N
j = M
ans = 1
for n in range(N*M, 0, -1):
    if A[i-1] == n and B[j-1] == n:
        i -= 1
        j -= 1
    elif A[i-1] == n:
        i -= 1
        ans *= M - j
        ans %= mod
    elif B[j-1] == n:
        j -= 1
        ans *= N - i
        ans %= mod
    else:
        ans *= ((N - i) * (M - j) - (N*M - n)) % mod
        ans %= mod
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
L, N = map(int, input())
X = []
for _ in range(N):
    X.append(int(input()))
X.sort()

Y = [L - x for x in X]
ans = 2*sum(X[:(N-1)//2+1]) + 2*sum(Y[-1:(N-1)//2:-1]) - min(X[(N-1)//2], Y[N//2])

print(ans)


Fixed submission:
L, N = map(int, input().split())
X = [0]
for _ in range(N):
    X.append(int(input()))

s = [0] * (N + 1)
t = [0] * (N + 1)
for i in range(1, N + 1):
    s[i] = s[i-1] + X[i]
    t[i] = t[i-1] + (L - X[N - i + 1])
Y = [0] + [L - X[N - i] for i in range(N)]

# i >= 1


def get_d(s, x, i):
    if i == N:
        return x[N]
    a = i + (N - i) // 2
    return (
        2 * (s[a] - s[i-1] + L * (N - a) - s[N] + s[a]) -
        (x[a] if (N - i) % 2 == 0 else (L - x[a + 1]))
    )


ans = 0
for i in range(1, N + 1):
    ans = max(ans, get_d(s, X, i), get_d(t, Y, i))

print(ans)
Buggy python submission (verdict: Runtime Error):
# from math import gcd
from fraction import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)


Fixed submission:
# from math import gcd
from fractions import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)

Buggy python submission (verdict: Runtime Error):
from math import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)


Fixed submission:
# from math import gcd
from fractions import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)
Buggy python submission (verdict: Runtime Error):
import sys

def get_height(h, x, y, cx, cy):
	return h + abs(x - cx) + abs(y - cy)

n = int(input())
x = []
y = []
h = []
for _ in range(n):
	xi, yi, hi = map(int, input().split())
	if hi == 0:
		continue
	x.append(xi)
	y.append(yi)
	h.append(hi)

for cx in range(101):
	for cy in range(101):
		height = get_height(h[0], x[0], y[0], cx, cy)
        is_valid = True
		for i in range(1, len(x)):
			if height != get_height(h[i], x[i], y[i], cx, cy):
            	is_valid = False
				break
		if is_valid:
			print(cx, cy, height)
			sys.exit()

Fixed submission:
import sys

def get_height(h, x, y, cx, cy):
	for i in range(len(h)):
		if h[i] == 0:
			continue
		return h[i] + abs(x[i] - cx) + abs(y[i] - cy)

n = int(input())
x = []
y = []
h = []
for _ in range(n):
	xi, yi, hi = map(int, input().split())
	x.append(xi)
	y.append(yi)
	h.append(hi)

for cx in range(101):
	for cy in range(101):
		height = get_height(h, x, y, cx, cy)
		for i in range(n):
			if h[i] != max(0, height - abs(x[i] - cx) - abs(y[i] - cy)):
				break
		else:
			print(cx, cy, height)
			sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n, m = map(int, input().split())
maxdiv = None
for div in reversed(range(1, 1+m//n)):
	if m % div == 0:
		print(div)
		sys.exit()

Fixed submission:
import sys

n, m = map(int, input().split())
for div in reversed(range(1, 1+m//n)):
	if m % div == 0:
		print(div)
		sys.exit()