Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n = int(input())
psn = []
alis = []
for i in range(n):
    lis = []
    a = int(input())
    for j in range(a):
        lis.append(list(map(int, input().split())))
    alis.append(a)
    psn.append(lis)
#print(psn)
#print(a)


ans = []
for i in range(2 ** n):
    flag = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            flag[j] = True
    #print(flag)
    hata = True
    for j in range(n):
        for k in range(len(psn[j])):
            if flag[j] == True:
                if flag[psn[j][k][0]-1] == True and psn[j][k][1] == 0:
                    hata = False
                if flag[psn[j][k][0]-1] == False and psn[j][k][1] == 1:
                    hata = False
            #print(flag[psn[j][k][0]-1])
    if hata == True:
        ans.append(flag.count(True))
    #print(hata)

print(max(ans))

### FIXED CODE ###

n = int(input())
psn = []
alis = []
for i in range(n):
    lis = []
    a = int(input())
    for j in range(a):
        lis.append(list(map(int, input().split())))
    alis.append(a)
    psn.append(lis)
#print(psn)
#print(a)


ans = []
for i in range(2 ** n):
    flag = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            flag[j] = True
    #print(flag)
    hata = True
    for j in range(n):
        for k in range(len(psn[j])):
            if flag[j] == True:
                if flag[psn[j][k][0]-1] == True and psn[j][k][1] == 0:
                    hata = False
                if flag[psn[j][k][0]-1] == False and psn[j][k][1] == 1:
                    hata = False
            #print(flag[psn[j][k][0]-1])
    if hata == True:
        ans.append(flag.count(True))
    #print(hata)

print(max(ans))
### BUGGY CODE ###

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

for i in range(n):
  print(l.count(i+1))

### FIXED CODE ###

import collections

n = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)

for i in range(n):
  print(c[i+1])
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))
ANS=A[0]
for i in range(1,N):
    ANS=ANS*A[i]
if ANS>10**18:
    print(-1)
else:
    print(ANS)

### FIXED CODE ###

import collections
import sys

N=int(input())
A=list(map(int, input().split()))
A_dict=collections.Counter(A)
ANS=1
if 0 in A_dict.keys():
    print("0")
    sys.exit()
    
for key, value in A_dict.items():
    ANS=ANS*(key**value)
    if ANS>10**18:
        print(-1)
        sys.exit()

print(ANS)
### BUGGY CODE ###

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

for i in range(N):
    print(A.count(i + 1))

### FIXED CODE ###

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

ans = [0] * N
for i in A:
    ans[i - 1] += 1

[print(i) for i in ans]
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip() + 'T'
    x,y = map(int, input().split())
    # 奇数はy方向, 偶数はx方向
    l = []
    susumu = 0
    for i in range(len(s)):
        if s[i] == 'T':
            l.append(susumu)
            susumu = 0
        else:
            susumu += 1
    b = len(l)
    dp = [[0]*16001 for _ in range(3)]
    dp[0][8000] = 1
    dp[1][8000] = 1
    for i in range(b):
        if i==0:
            dp[2][8000+l[i]] = 1
        elif i%2 == 0:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        elif i%2 == 1:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        dp = dp[1:] + [[0]*16000]
    if b%2 == 0:
        if dp[0][x+8000] == 1 and dp[1][y+8000] == 1:
            print('Yes')
        else:
            print('No')
    else:
        if dp[1][x+8000] == 1 and dp[0][y+8000] == 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip() + 'T'
    x,y = map(int, input().split())
    # 奇数はy方向, 偶数はx方向
    l = []
    susumu = 0
    for i in range(len(s)):
        if s[i] == 'T':
            l.append(susumu)
            susumu = 0
        else:
            susumu += 1
    b = len(l)
    dp = [[0]*16001 for _ in range(3)]
    dp[0][8000] = 1
    dp[1][8000] = 1
    for i in range(b):
        if i==0:
            dp[2][8000+l[i]] = 1
        elif i%2 == 0:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        elif i%2 == 1:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        dp = dp[1:] + [[0]*16000]
    if b%2 == 0:
        if dp[0][x+8000] == 1 and dp[1][y+8000] == 1:
            print('Yes')
        else:
            print('No')
    else:
        if dp[1][x+8000] == 1 and dp[0][y+8000] == 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
n = int(input())
li = list(map(int, input().split()))
ans_li = deque()
for i in range(1, n+1):
    ans_li.append(li.index(i)+1)
print(*ans_li)

### FIXED CODE ###

n = int(input())
li = list(map(int, input().split()))
ans_li = [0] * n
for i in range(n):
    ans_li[li[i]-1] = i+1
print(*ans_li)
### BUGGY CODE ###

n, m = map(int, input().split())
# A = set()
# for i in range(m):
#     a = int(input())
#     A.add(a)
a = []
for i in range(m):
    a.append(int(input()))
dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

"""
100 5
1
23
45
67
89
"""


### FIXED CODE ###

n, m = map(int, input().split())
A = set()
for i in range(m):
    a = int(input())
    A.add(a)
dp = [0] * (n + 1)
for i in range(n + 1):
    if i in A:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

"""
100 5
1
23
45
67
89
"""
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

s = []
for i in range(h):
   s.append(input().rstrip('\n'))

INF = 10 ** 10
d = [INF] * (h*w)

A = 10**18
B = 10**9

nex = []
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i, j) in [(-1,0),(1,0),(0,-1),(0,1),(0,0)]:
            continue
        else:
            nex.append((i,j))

d[(ch-1) * w + (cw-1)] = 0

T = ((-1,0), (1,0), (0,1), (0,-1))

q = [(ch-1)*A + (cw-1)*B + 0]
use = [0] * (h * w)

for x in q:
    curh = (x // A)
    x -= curh * A
    curw = (x // B)
    cnt = x - curw * B
    tmp = curh * w + curw
    if d[tmp] < cnt or use[tmp]: continue
    d[tmp] = cnt
    use[tmp] = 1

    for dh, dw in T:
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.' and d[nh * w + nw] > cnt:
            d[nh * w + nw] = cnt
            use[nh * w + nw] = 0
            q.append(nh*A + nw*B + cnt)
    for dh, dw in nex:
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.' and d[nh * w + nw] > cnt:
            d[nh * w + nw] = cnt + 1
            use[nh * w + nw] = 0
            q.append(nh*A + nw*B + cnt+1)

# for item in d:
#     print(item)
gh -= 1
gw -= 1

if d[gh*w + gw] == INF:
    print(-1)
else:
    print(d[gh*w + gw])


### FIXED CODE ###

import heapq
class Dijkstra:
    INF = 10**18
    threshold = 10**9

    def __init__(self, N):
        self.MAX_V = N + 1
        self.dist = [self.INF] * self.MAX_V
        self.G = [[] for _ in range(self.MAX_V)]

    def insert(self, X, Y, cost): self.G[X].append(cost * self.threshold + Y)

    def dijkstra(self, st):
        q = []
        heapq.heappush(q, st)
        self.dist[st] = 0

        while len(q):
            p = heapq.heappop(q)
            cost = p // self.threshold
            node = p - cost * self.threshold
            if cost > self.dist[node]: continue
            for to in self.G[node]:
                to_cost = to // self.threshold
                to_node = to - to_cost * self.threshold
                to_cost += self.dist[node]
                if self.dist[to_node] > to_cost:
                    self.dist[to_node] = to_cost
                    heapq.heappush(q, to_cost * self.threshold + to_node)

h, w = map(int, input().split())
sh, sw = map(int, input().split())
eh, ew = map(int, input().split())

sh -= 1
sw -= 1
eh -= 1
ew -= 1

S = [input() for _ in range(h)]

di = Dijkstra(h*w)
for x in range(h):
    for y in range(w):
        if S[x][y] == '#': continue
        for i in range(-2, 3):
            for j in range(-2, 3):
                X = x + i
                Y = y + j
                if X < 0 or Y < 0 or X >= h or Y >= w or S[X][Y] == '#': continue
                D = abs(i) + abs(j)

                if D == 1: di.insert(x * w + y, X * w + Y, 0)
                if D >= 2: di.insert(x * w + y, X * w + Y, 1)

di.dijkstra(sh * w + sw)
ans = di.dist[eh * w + ew]
if ans == 10**18: print(-1)
else: print(ans)
### BUGGY CODE ###

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

# 昇順のカードとする
g_cards = list(map(int, input().split()))

# 操作
for i in range(M):
	# sizeと同じ枚数の値が増えたと考える
	size, val = map(int, input().split())
	for i in range(size):
		g_cards.append(val)

# ソート
cards = sorted(g_cards, reverse=True)

sum_val = sum(cards[:N])

print(sum_val)

### FIXED CODE ###

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

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

# key-valueデータで管理
dict_cards = []
for card in g_cards:
	dict_cards.append([card, 1])

# 操作
for i in range(M):
	# sizeと同じ枚数のカードが増えたと考える
	size, val = map(int, input().split())
	dict_cards.append([val, size])

# 降順にする
s_dict_cards = sorted(dict_cards, key=lambda x: -x[0])

s_cards = []
for data in s_dict_cards:
	s_cards += [data[0]] * data[1]
	if(len(s_cards) >= N):
		break
# 出力
sum_val = sum(s_cards[:N])
print(sum_val)
### BUGGY CODE ###

s = input()
cnt = 0
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        a = int(s[i:j+1])
        if a % 2019 == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

P = 2019
S=input()
N = len(S)
ans=0

rem = [0]*P
mod = 0
ten = 1
rem[mod]=1
for i in range(N):
    mod=(mod+int(S[N-i-1])*ten)%P
    ten=ten*10%P
    rem[mod]+=1
for j in rem:
    ans+=(j*(j-1))//2
print(ans)
### BUGGY CODE ###

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

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = lenx/N
baisuu_t = lenx/M
def check():
    for i in range(0,lenx):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)

### FIXED CODE ###

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

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = int(lenx/N)
baisuu_t = int(lenx/M)
def check():
    for i in range(0,lenx,baisuu_s):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)
### BUGGY CODE ###

import math
def solution(a):
    for i in xrange(1, len(a)):
        ab = abs(sum(a[:i]) - sum(a[i:]))
        if i == 1:
            Min = ab 
            continue
        if ab < Min:
            Min = ab
    print Min
N = int(raw_input())
a = map( int, raw_input().split())
solution(a)

### FIXED CODE ###

def solution(a):
    A = a[0]
    B = sum(a) - a[0]
    Min = abs(A - B)
    for i in xrange(1, len(a)-1):
        A += a[i]
        B -= a[i]
        if Min > abs(A- B):
            Min = abs(A - B)
    print Min
import math
N = int(raw_input())
a = map( int, raw_input().split())
solution(a)
### BUGGY CODE ###

a, b, x = map(int, input().split())
count = 0
for i in range(a,b+1):
    if i % x == 0:
        count += 1
print(count)

### FIXED CODE ###

a, b, x = map(int, input().split())
print(b//x - (a-1)//x)
### BUGGY CODE ###

S = list(map(int, input()))
ans = 0
l = len(S)
i = 0
while len(S)-1 > i:
    if S[i] != S[i+1]:
        S.pop(i)
        S.pop(i)
        ans += 2
        i = -1
    i += 1


print(ans)

### FIXED CODE ###

S = list(map(int, input()))
ans = 0
l = len(S)
i = 0
while len(S)-1 > i:
    if S[i] != S[i+1]:
        S.pop(i)
        S.pop(i)
        ans += 2
        if i == 0:
            i -= 1
        else:
            i -= 2
    i += 1


print(ans)
### BUGGY CODE ###

n,k,*A=map(int,open(0).read().split());e=enumerate
for _ in '_'*min(k,99):
  S=[0]*(n+1)
  B=[0]*(n+1)
  for i,a in e(A):S[max(0,i-a)]+=1;S[min(n,i+a+1)]-=1
  for i,s in e(S[:-1]):B[i+1]=B[i]+s
  A=B[1:]
print(*A)

### FIXED CODE ###

n,k,*A=map(int,open(0).read().split());e=enumerate
for _ in '_'*min(k,99):
  S=[0]*(n+1)
  B=[0]*(n+1)
  for i,a in e(A):S[max(0,i-a)]+=1;S[min(n,i+a+1)]-=1
  for i,s in e(S[:-1]):B[i+1]=B[i]+s
  A=B[1:]
print(*A)
### BUGGY CODE ###

'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    x = [int(i) for i in ipt().split()]
    d = [x[i+1]-x[i] for i in range(n-1)]
    k = [1]
    for i in range(1,n):
        k.append(k[-1]*i%mod)

    #n!の逆元を求める
    g2 = [1,1]
    inverse = [0,1] #逆元テーブル計算用テーブル
    for i in range(2,n+1):
        inverse.append((-inverse[mod%i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)

    ans = 0
    na = 0
    for i in range(1,n):
        na = na*i+k[i-1]
        ans += na*d[i-1]*k[-1]*g2[i]
        ans %= mod

    print(ans)
    return None

if __name__ == '__main__':
    main()


### FIXED CODE ###

'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    x = [int(i) for i in ipt().split()]
    d = [x[i+1]-x[i] for i in range(n-1)]
    k = [1]
    for i in range(1,n):
        k.append(k[-1]*i%mod)

    #n!の逆元を求める
    g2 = [1,1]
    inverse = [0,1] #逆元テーブル計算用テーブル
    for i in range(2,n+1):
        inverse.append((-inverse[mod%i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)

    ans = 0
    na = 0
    for i in range(1,n):
        na = na*i+k[i-1]
        na %= mod
        ans += na*d[i-1]*k[-1]*g2[i]
        ans %= mod

    print(ans)
    return None

if __name__ == '__main__':
    main()
### BUGGY CODE ###

H, W, A, B = map(int, input().split())
matr = [[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
  for w in range(W):
    if w < A and h < B:
      matr[h][w] = 1
    if w >= A and h >= B:
      matr[h][w] = 1
      
      
flgw = True    
for h in range(H):
  wsum = sum(matr[h])
  if wsum == A or wsum == (W - A):
    pass
  else:
    flgw = False
    
import numpy as np 
matr = np.array(matr)
math = np.sum(matr, axis = 0)
flgh = True    
for w in math:
  if w == B or w == (H - B):
    pass
  else:
    flgh = False
    
if flgh and flgw:
  for h in range(H):
    for w in range(W):
      print(matr[h][w], end = '')
    print() 
else:
  print('No')

### FIXED CODE ###

H, W, A, B = map(int, input().split())
matr = [[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
  for w in range(W):
    if w >= A and h >= B:
      matr[h][w] = 1
    if w < A and h < B:
      matr[h][w] = 1
    

for h in range(H):
  for w in range(W):
    print(matr[h][w], end = '')
  print()
### BUGGY CODE ###

S=input()
Q=int(input())
for i in range(Q):
    q=input()
    if q[0]=='2':
        if q[2]=='1':
            S=q[4]+S
        else:
            S=S+q[4]
    else:
        S=S[::-1]
print(S)

### FIXED CODE ###

from collections import deque
S=deque(input())
Q=int(input())
ans=0
for i in range(Q):
    q=input()
    if q[0]=='2':
        if ans%2==0:
            if q[2]=='1':
                S.appendleft(q[4])
            else:
                S.append(q[4])
        else:
            if q[2]=='1':
                S.append(q[4])
            else:
                S.appendleft(q[4])
    else:
        ans+=1
S="".join(S)
print(S if ans%2==0 else S[::-1])
### BUGGY CODE ###

n,p = map(int,input().split())
s = input()

if p == 2 or p == 5:
    ans = 0
    for i in range(n-1,-1,-1):
        if int(s[i]) % p == 0:
            ans += i+1
    print(ans)
    exit()

l = [0]

s1 = s[::-1]
l.append(int(s1[0])%p)
for i in range(1,n):
    check = int(s1[i])*10**i%p
    l.append((l[-1]+check)%p)
ans = 0

for i in range(p):
    k = l.count(i)*(l.count(i)-1)//2
    ans += k
print(ans)



### FIXED CODE ###

def main():
    n,p = map(int,input().split())
    s = input()

    if p == 2 or p == 5:
        ans = 0
        for i in range(n-1,-1,-1):
            if int(s[i]) % p == 0:
                ans += i+1
        print(ans)
        exit()

    l = [0]*p
    l[0] += 1
    s1 = s[::-1]
    ten = 1
    mod = 0
    for i in range(n):
        mod += int(s1[i])*ten%p
        mod %= p
        ten = ten*10%p
        l[mod] += 1
    ans = 0

    for i in l:
        ans += (i-1)*i//2
    print(ans)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [0]*N
for i in range(N):
    S[L[i]-1]+=1


for i in range(N):
    tmp=S
    tmp[L[i]-1]-=1
    goukei=0
    for j in range(N):
        if tmp[j]>=2:
            goukei+=(tmp[j]*(tmp[j]-1))//2
    tmp[L[i]-1]+=1
    print(goukei)


### FIXED CODE ###

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

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [0]*N
for i in range(N):
    S[L[i]-1]+=1

init=0
for j in range(N):
    tmp=S
    if tmp[j]>=2:
        init+=(tmp[j]*(tmp[j]-1))//2




for i in range(N):
    ans=init
    R=S[L[i]-1]
    if R>=2:
        print(ans-(R-1))
    else:
        print(ans)
### BUGGY CODE ###

import numpy as np
n,m,k = (int(x) for x in input().split())
a =np.array([int(x) for x in input().split()])
b =np.array([int(x) for x in input().split()])

count = 0
for i in range(n+1):
    for j in range(m+1):
        if i+j>count:
            if np.sum(a[:i])+np.sum(b[:j]) <= k:
                count = i+j

print(count)

### FIXED CODE ###

n,m,k = (int(x) for x in input().split())
y = 0
a = [0]
for x in input().split():
    y += int(x)
    a.append(y)
y = 0
b = [0]
for x in input().split():
    y += int(x)
    b.append(y)
    
ans = 0
j = m
for i in range(n+1):
    if a[i]>k:
        break
    while j >= 0:
        if a[i]+b[j]<=k:
            ans = max(ans,i+j)
            break
        j -= 1
print(ans)
### BUGGY CODE ###

n = int(input())
T = 1
A = 1
for _ in range(n):
    i = 1
    t, a = map(int, input().split())
    while i * t < T or i * a < A:
        i += 1
    T = i * t
    A = i * a
print(T + A)

### FIXED CODE ###

from copy import deepcopy as copy
n = int(input())
T = [1]
A = [1]
for i in range(n):
    t, a = map(int, input().split())
    tc = copy(t)
    ac = copy(a)
    if T[-1] > t or A[-1] > a:
        multi = max(T[-1] // t, A[-1] // a) + 1
        t *= multi
        a *= multi
        while t - tc >= T[-1] and a - ac >= A[-1]:
            t -= tc
            a -= ac
    T.append(t)
    A.append(a)
print(T[-1] + A[-1])
### BUGGY CODE ###

n = int(input())
dic = {}
for _ in range(n):
  s = input()
  if s in dic:
    dic[s] += 1
  else:
    dic[s] = 1
max_k_list = [kv[0] for kv in dic.items() if kv[1] == max(dic.values())]
max_k_list = sorted(max_k_list)
for i in max_k_list:
  print(i)

### FIXED CODE ###

N = int(input(''))
dict = {}
for i in range(N):
    S = input('')
    if S in dict:
        dict[S] += 1
    else:
        dict[S] = 1
M = max(dict.values())
out = [j for j in dict.keys() if dict[j] == M]
out.sort()
for k in out:
    print(k)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
s = list()
s.append(0)
for i in range(N):
  s.append(a[i] + s[i])
b = sorted(s)
c = len(b)
count = 0
for j in range(c):
  d = b.count(b[j])
  count += (d * (d-1))/2/d
print(int(count))

### FIXED CODE ###

from collections import Counter
N = int(input())
a = list(map(int, input().split()))
count = 0
s = list()
s.append(0)
for i in range(N):
  s.append(a[i] + s[i])
for j in  Counter(s).values():
  count += (j * (j-1))/2
print(int(count))
### BUGGY CODE ###

N = int(input())
L = [n for n in map(int,input().split())]
res = 0
k = 0
for i in range(0,N):
  for j in range(0,i):
    if L[i] > L[j]:
      k = 1
  if k!=1:
    res += 1
  k = 0
print(res)

### FIXED CODE ###

N = int(input())
L = [_ for _ in map(int,input().split())]
res = 0
for x in L:
  if x <= N:
    res += 1
    N = x #最小上書き。次にresが増えるのは後々の要素で最小より小さいのが出てきたとき。
print(res)
#みんなもtabulationミスってREには気をつけようね
### BUGGY CODE ###

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

ans = float("inf")

for i in range(1,n):
    ans = min(ans, abs(sum(a[:i])-sum(a[i:])))

print(ans)

### FIXED CODE ###

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

ans = float("inf")
suml = sum(a)
snuke = 0

for i in range(n-1):
    snuke += a[i]
    ans = min(ans, abs(suml-snuke*2))

print(ans)
### BUGGY CODE ###

N = int(input()) 
A = [int(i) for i in input().split()]
A.sort()

def f(x):
    B = [((x<=a)<<1)-1 for a in A]      
    C = [0]  
    [C.append(C[-1]+b) for b in B]          
    r = 0
    s = 0
    for i in range(N):
        for j in range(i+1,N+1):
            s += 1
            if C[j]-C[i] > 0: 
                r += 1
    return(r>s//2)        

l = 0
r = N-1
while l != r:
    if f((l+r)//2):               
        l = (l+r)//2 + 1
    else:
        r = (l+r)//2
print(A[r])


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
AS = sorted(list(set(A)))

def f(x):
    B = [((x<=a)<<1)-1 for a in A]
    C = [N]
    [C.append(C[-1]+b) for b in B]

    r = 0
    Bit = [0] * (2*N+1)

    for i,c in enumerate(C):
        t=c-1
        while(t>0):
            r += Bit[t]
            t -= t&-t
        t=c-1
        while(t<=2*N+1):
            Bit[t] += 1
            t += t&-t
    return(r>=N*(N+1)//4)

l = 0
r = len(AS)-1
while l != r:
    if f(AS[(l+r+1)//2]):
        l = (l+r+1)//2
    else:
        r = (((l+r+1)//2)-1)
print(AS[r])