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

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left

OFS = ord('a')
_, S, _, *Q = open(0).read().split()
S = [ord(s)-OFS for s in S]
Q = tuple(zip(*[iter(Q)]*3))

D = [[] for _ in [0]*26]

for i, s in enumerate(S):
    D[s].append(i)

for q, *x in Q:
    if q == '1':
        i, c = int(x[0])-1, ord(x[1])-OFS
        s, S[i] = S[i], c

        D[s].pop(bisect_left(D[s], i))
        insort_left(D[c], i)

    else:
        l, r = int(x[0])-1, int(x[1])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i == len(L):
                continue
            if L[i] <= r:
                cnt += 1

        print(cnt)


### FIXED CODE ###

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
OFS = ord('a')
_ = input()
S = list(input()[:-1])

D = [[] for _ in [0]*26]
for i, s in enumerate(S):
    D[ord(s)-OFS].append(i)

for _ in [0]*int(input()):
    Q = input()[:-1].split()
    if Q[0] == '1':
        i, c = int(Q[1])-1, Q[2]

        if S[i] != c:
            s = ord(S[i])-OFS
            D[s].pop(bisect_left(D[s], i))
            insort_left(D[ord(c)-OFS], i)
            S[i] = c

    else:
        l, r = int(Q[1])-1, int(Q[2])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i < len(L) and L[i] <= r:
                cnt += 1

        print(cnt)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for i in range(Q):
    B.append(list(map(int,input().split())))
sum=int(0)
AA=[int(0)]
for i in range(100000):
    AA.append(int(0))
for i in range(100001):
    AA[i]=A.count(int(i))
#for i in range(5):
#    print(AA[i])
sum=int(0)
for i in range(N):
    sum += A[i]
for i in range(Q):
    sum = sum + B[i][1]*AA[(B[i][0])]-B[i][0]*AA[(B[i][0])]
    AA[(B[i][1])] = AA[(B[i][1])]+AA[(B[i][0])]
    AA[(B[i][0])] = 0
    print(sum)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for i in range(Q):
    B.append(list(map(int,input().split())))
sum=int(0)
AA=[int(0)]
for i in range(100000):
    AA.append(int(0))
for i in A:
    AA[i]+=1 #A.count(int(i))
#for i in range(5):
#    print(AA[i])
sum=int(0)
for i in range(N):
    sum += A[i]
for i in range(Q):
#    AA[(B[i][0])]=A.count(int((B[i][0])))
#    A.replace(B[i][0],B[i][1])
#    AA[(B[i][1])]=A.count(int((B[i][1])))
    sum = sum + B[i][1]*AA[(B[i][0])]-B[i][0]*AA[(B[i][0])]
    AA[(B[i][1])] = AA[(B[i][1])]+AA[(B[i][0])]
    AA[(B[i][0])] = 0
    print(sum)
### BUGGY CODE ###

import sys


H, W, M = map(int, input().split())
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
for s in sys.stdin.readlines():
    h, w = map(lambda x: int(x) - 1, s.split())
    X[h].add(w)
    Y[w].add(h)
cntX = []
cntY = []
for x in X:
    cntX.append((len(x), x))
for w, y in enumerate(Y):
    cntY.append((len(y), w))

cntX.sort(reverse=True)
cntY.sort(reverse=True)
maxX = cntX[0][0]
maxY = cntY[0][0]
ans = 0
for cnt, x in cntX:
    if cnt < maxX:
        break
    for tmp, w in cntY:
        if tmp < maxY:
            break
        tmp += cnt - (w in x)
        if ans < tmp:
            ans = tmp
    if cnt == maxX + maxY:
        break
print(ans)


### FIXED CODE ###

import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)
### BUGGY CODE ###

n=int(input())
S=input()

ans=0
for i in range(1000):
    j="0"*(3-len(str(i)))+str(i)
    flag1=False
    flag2=False
    flag3=False
    for i in range(n):
        if not flag1 and S[i]==j[0]:
            flag1=True
            continue
        if flag1 and not flag2:
            if S[i]==j[1]:
                flag2=True
                continue
        if flag2 and not flag3:
            if S[i]==j[2]:
                flag3=True
                break
    if flag3:
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
S=input()
ans=0
sublist=[]
for i in range(100):
    used=0
    j="0"*(2-len(str(i)))+str(i)
    flag1=False
    flag2=False
    for i in range(n):
        if not flag1 and S[i]==j[0]:
            flag1=True
            continue
        if flag1 and not flag2:
            if S[i]==j[1]:
                flag2=True
                used=i+1
    if flag2:
        sublist.append((j,used))
anslist=[]
for some in sublist:
    a1=some[0]
    index=some[1]
    lis=[0 for i in range(10)]
    for j in range(index,n):
        anslist.append(a1+S[j])
anslist=set(anslist)
print(len(anslist))
### BUGGY CODE ###

s  = input()
q = int(input())

for _ in range(q):
    lis = list(input().split())
    if lis[0] == "1":
        s = s[::-1]
    else:
        if lis[1] == '1':
            s = lis[2] + s
        else:
            s = s + lis[2]

print(s)

### FIXED CODE ###

from collections import deque

s  = input()
q = int(input())

#flag=0 でleft, flag=1でrightが先頭
flag = 0
cnt = 0
d  = deque(s)

for _ in range(q):
    lis = list(input().split())
    if lis[0] == "1":
        if flag:
            flag = 0
        else:
            flag = 1
        cnt += 1
    else:
        if lis[1] == '1':
            if flag:
                d.append(lis[2])
            else:
                d.appendleft(lis[2])
        else:
            if flag:
                d.appendleft(lis[2])
            else:
                d.append(lis[2])


d = list(d)
if cnt % 2 != 0:
    d = d[::-1]


print(''.join(d))
### BUGGY CODE ###

from collections import deque
s=input()
q=int(input())
t=[input() for i in range(q)]
l=deque(list(s))
for i in range(q):
  if int(t[i][0])==1:
    l.reverse()
  else:
    if int(t[i][2])==1:
      l.appendleft(t[i][4]) 
    else:
      l.append(t[i][4])
print(''.join(l))

### FIXED CODE ###

from collections import deque
s=input()
q=int(input())
t=[input() for i in range(q)]
l=deque(list(s))
m=0
for i in range(q):
  if int(t[i][0])==1:
    m+=1
  else:
    if m%2==0:
      if int(t[i][2])==1:
        l.appendleft(t[i][4]) 
      else:
        l.append(t[i][4])
    else:
      if int(t[i][2])==2:
        l.appendleft(t[i][4]) 
      else:
        l.append(t[i][4])
if m%2==1:
  l.reverse()
print(''.join(l))
### BUGGY CODE ###

s = input()

ans = 0
while True:
    for i in range(len(s)-1):
        if s[i:i+2] == "01" or s[i:i+2] == "10":
            s = s[:i] + s[i+2:]
            ans += 2

    if s.count("1") == 0 or s.count("0") == 0:
        break

print(ans)


### FIXED CODE ###

s = input()

print(min(s.count("0"), s.count("1"))*2)
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    div_i = 0
    tmp_multi = 1
    prev_tmp_multi = 1
    for i in range(N):
        if i <= K - 1:
            tmp_multi *= A[i]
            prev_tmp_multi *= A[i]
        else:
            tmp_multi *= A[i]
            tmp_multi /= A[div_i]
            if tmp_multi > prev_tmp_multi:
                print("Yes")
            else:
                print("No")
            prev_tmp_multi = tmp_multi
            div_i += 1


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    div_i = 0
    for i in range(N):
        if i <= K - 1:
            pass
        else:
            if A[i] > A[div_i]:
                print("Yes")
            else:
                print("No")
            div_i += 1


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


n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
result = sum(a)
b_ = []
for i in range(m):
    b, c = map(int, input().split(' '))
    tmp = [c] * b
    b_ += tmp
b_.sort(reverse=True)
a.sort()
if len(b_) > n:
    b_ = b_[:n]
for i,(j,k) in enumerate(zip(a, b_)):
    if j < k:
        a[i] = k
    else:
        break
print(sum(a))


### FIXED CODE ###


n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
result = sum(a)
b_ = []
for i in range(m):
    b, c = map(int, input().split(' '))
    b_ += [(b,c)]
for i in range(n):
    b_ += [(1, a[i])]

from operator import itemgetter
b_.sort(key=itemgetter(1), reverse=True)

count = n
res = 0
for j, k in b_:
    if count > j:
        res += k * j
        count -= j
    elif count <= j:
        res += k * count
        break
print(res)
### BUGGY CODE ###

N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N


for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

result = []
while q != []:
    qn = q.pop(0)
    result.append(qn)
    for v in outs[qn]:
        ins[v] -= 1
        if ins[v] == 0:
            q.append(v)


last = [0] * N
# last[i] = iが最後だったときに最長のパス
for sq in result:
    now = last[sq] + 1
    for v in outs[sq]:
        last[v] = max(last[v], now)

print(max(last))

### FIXED CODE ###

N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N

for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

last = [0] * N
while q != []:
    qn = q.pop()
    for v in outs[qn]:
        ins[v] -= 1
        last[v] = max(last[v], last[qn] + 1)
        if ins[v] == 0:
            q.append(v)

print(max(last))
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
x = list(map(int,input().split()))
x.sort(reverse=True)
y = list(map(int,input().split()))
y.sort(reverse=True)
z = list(map(int,input().split()))
z.sort(reverse=True)
xy = []
for xx in x:
  for yy in y:
    xy.append(xx+yy)
xy.sort(reverse=True)
xy = xy[:k]
xyz = []
for yx in xy:
  for zz in z:
    xyz.append(yx+zz)
xyz.sort(reverse=True)
for i in range(k):
  print(xyz[i])

### FIXED CODE ###

#15:38
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
a = a[:k]
b = list(map(int,input().split()))
b.sort(reverse = True)
b = b[:k]
c = list(map(int,input().split()))
c.sort(reverse = True)
c = c[:k]
ab = []
for l in a:
  for m in b:
    ab.append(l+m)
ab.sort(reverse = True)
ab = ab[:k]
abc = []
for n in ab:
  for o in c:
    abc.append(n+o)
abc.sort(reverse = True)
abc = abc[:k]
for p in abc:
  print(p)
### BUGGY CODE ###

from sys import stdin
from collections import deque

input = stdin.readline


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

    nexts = [[] for i in range(n)]
    
    for i in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues

    red_deque = deque([0])

    arrows = [0] * n

    while 1 in blues:
        rd = red_deque[0]
        red_deque.popleft()

        for nxt in nexts[rd]:
            if blues[nxt] == 1:
                blues[nxt] = 0
                if rd not in red_deque:
                    red_deque.append(nxt)
                arrows[nxt] = rd

    print("Yes")
    for arrow in arrows[1:]:
        print(arrow + 1)
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

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


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

    nexts = [[] for i in range(n)]
    
    for _ in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [-1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues
    checked = [0] * n

    red_deque = deque([0])

    while len(red_deque) > 0:
        rd = red_deque[0]
        red_deque.popleft()
        if checked[rd] == 0:
            checked[rd] = 1
            for nxt in nexts[rd]:
                if blues[nxt] == -1:
                    blues[nxt] = rd
                    red_deque.append(nxt)

    print("Yes")
    for blue in blues[1:]:
        print(blue + 1)
    

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

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[] for j in range(n + 1)]
    for i in range(m):
        l, r = map(int, input().split())
        bisect.insort_left(nl[l], r)
    table = [array.array("i", [0] * (n + 1)) for j in range(n + 1)]
    r = array.array("i", range(1, n + 1))
    for i in r:
        for j in r:
            table[i][j] = bisect.bisect_right(nl[i], j)

    s = array.array("i", [0] * q)
    for i in range(q):
        l, r = map(int, input().split())
        for j in range(l, r + 1):
            s[i] += table[j][r] - table[j][l - 1]
    print("\n".join([str(e) for e in s]))


if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

a=[]
n=int(input())
nn=n
while(nn>0):
    b=int(input())
    a.append(b)
    nn-=1

a.reverse()
sa=a[0]-a[1]
for i in range(1,n):
    sb=a[i-1]-min(a[i:])
    if(sb>sa):
        sa=sb

print(sa)

### FIXED CODE ###

a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append(b)
    i+=1
score=-1000000000
mini = a[0]
for i in a[1:]:
    if(i-mini>score):
        score = i-mini
    if(mini>i):
        mini=i
    

print(score)
### BUGGY CODE ###

# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
    if k == n-1:
        print(1)
    else:
        print(0)
    exit()
MOD = 998244353

ans = tmp = (m * (m-1) ** (n-1))
ans %= MOD

for i in range(k):
    tmp *= (n-1-i)
    tmp //= (m-1) * (i+1)
    ans += tmp
    ans %= MOD

print(ans)

### FIXED CODE ###

# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
    if k == n-1:
        print(1)
    else:
        print(0)
    exit()
MOD = 998244353

ans = tmp = (m * (m-1) ** (n-1)) % MOD

for i in range(k):
    tmp *= (n-1-i)
    tmp %= MOD
    tmp *= pow((m-1) * (i+1), -1, MOD)
    ans += tmp
    ans %= MOD

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

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        s_cost[i] = min(s_cost[i], a[(i-k)%N])
    # s_cost = [min(s_cost[x],a[y]) for (x,y) in zip( list(range(N)), list(range(N-k,N))+list(range(N-k)) )]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)


### FIXED CODE ###

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)
### BUGGY CODE ###

import sys
import math
import heapq
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

H,W=LI()
MP=[input() for _ in range(H)]
CORD=[(i,j) for i in range(H) for j in range(W)]

max_dist = 0
visited=set()
for i in range(len(CORD)):
    for j in range(i+1, len(CORD)):
        st, en = CORD[i], CORD[j]
        if MP[st[0]][st[1]] == "." and MP[en[0]][en[1]] == ".":
            QUE=deque()
            visited.add(st)
            QUE.append((st[0], st[1], 0))
            res = 0
            while QUE:
                ii, jj, dist = QUE.popleft()
                if (ii, jj) == en:
                    res = dist
                    visited.clear()
                    break
                for iii, jjj in [(ii-1,jj),(ii+1,jj),(ii,jj-1),(ii,jj+1)]:
                    if iii >= 0 and jjj >= 0 and iii < H and jjj < W and MP[iii][jjj] != '#' and not (iii, jjj) in visited:
                        QUE.append((iii, jjj, dist+1))
                        visited.add((iii, jjj))

            max_dist = max(res, max_dist)

print(max_dist)


### FIXED CODE ###

import sys
import math
import heapq
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

H,W=LI()
MP=[input() for _ in range(H)]
CORD=[(i,j) for i in range(H) for j in range(W)]

max_dist = 0
for i in range(len(CORD)):
    st = CORD[i]
    if MP[st[0]][st[1]] == ".":
        QUE=deque()
        visited = [[0]*W for i in range(H)]
        visited[st[0]][st[1]] = 1
        QUE.append((st[0], st[1], 0))
        res = 0
        while QUE:
            ii, jj, dist = QUE.popleft()
            max_dist = max(max_dist, dist)
            for iii, jjj in [(ii-1,jj),(ii+1,jj),(ii,jj-1),(ii,jj+1)]:
                if iii >= 0 and jjj >= 0 and iii < H and jjj < W and MP[iii][jjj] != '#' and not visited[iii][jjj]:
                    QUE.append((iii, jjj, dist+1))
                    visited[iii][jjj] = 1


print(max_dist)
### BUGGY CODE ###

from collections import deque

H, W = [int(i) for i in input().split()]
S = [list(input()) for _ in range(H)]

white = sum(s.count(".") for s in S)

Q = deque([(0, 0, 1)])
while Q:
    h, w, count = Q.popleft()
    if (h, w) == (H - 1, W - 1):
        print(white - count)
        quit()

    S[h][w] = "_"

    for nh, nw in [(h, w + 1), (h, w - 1), (h + 1, w), (h - 1, w)]:
        if not (0 <= nh < H and 0 <= nw < W):
            continue
        if S[nh][nw] == ".":
            Q.append((nh, nw, count + 1))
print(-1)



### FIXED CODE ###

from collections import deque

H, W = [int(i) for i in input().split()]
S = [list(input()) for _ in range(H)]

white = sum(s.count(".") for s in S)

S[0][0] = "_"
Q = deque([(0, 0, 1)])
while Q:
    h, w, count = Q.popleft()
    if (h, w) == (H - 1, W - 1):
        print(white - count)
        quit()

    for nh, nw in [(h, w + 1), (h, w - 1), (h + 1, w), (h - 1, w)]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == ".":
            S[nh][nw] = "_"
            Q.append((nh, nw, count + 1))
print(-1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

import collections

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
cond_keys = []
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in cond_keys:
    conditions[inputs[0]].append(inputs[1])
  else:
    cond_keys.append(inputs[0])
    conditions[inputs[0]] = collections.deque([inputs[1]])

for day in conditions.keys():
  conditions[day] = sorted(conditions[day], reverse=True)

ans = 0
candidates = []
cand_len = 0
for reversed_day in range(1, m + 1):
  if reversed_day in cond_keys:
    candidates.append(conditions[reversed_day])
    cand_len += 1

  if cand_len == 0:
    continue

  cnt, maxval, maxkey = 0, 0, 0
  for cands in candidates:
    if cands[0] > maxval:
      maxval = cands[0]
      maxkey = cnt
    cnt += 1
  ans += candidates[maxkey].pop(0)
  if len(candidates[maxkey]) == 0:
    del candidates[maxkey]
    cand_len -= 1
print(ans)


### FIXED CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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

n,k=map(int,input().split())
while abs(n-k) < n:
  n = abs(n-k)
print(n)

### FIXED CODE ###

n,k=map(int,input().split())
l=n//k
m=min(abs(l*k-n),abs((l+1)*k-n))
while n > m:
  n=m
print(n)
### BUGGY CODE ###

from sys import stdin

K = int(stdin.readline().rstrip())
a_n = 7
i = 1
while True:      
  if a_n % K == 0:
    break
  else:
    i += 1
    a_n = a_n * 10 + 7
    
print(i)

### FIXED CODE ###

from sys import stdin
K = int(stdin.readline().rstrip())
def main(K):
  a=0
  for i in range(1,K+1):
    a = ((10%K) * a + 7)%K
    if a == 0:
      return i
  return -1
print(main(K))
### BUGGY CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
cnt = 1
for i in range(k):
  cnt *= a[i]
pre = cnt
for i in range(n-k):
  cnt /= a[i]
  cnt *= a[i+k]
  if cnt>pre:
    print('Yes')
  else:
    print('No')
  pre = cnt

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
cnt = 1
for i in range(k):
  cnt += a[i]
pre = cnt
for i in range(n-k):
  cnt -= a[i]
  cnt += a[i+k]
  if cnt>pre:
    print('Yes')
  else:
    print('No')
  pre = cnt
### BUGGY CODE ###


num = input()
l = []
for i in range(0,int(num)):
    l.append(input())

cnt = []
l_t = list(set(l))
keys = []
max_v = 0
for item in l_t:
    if max_v < l.count(item):
        max_v = l.count(item)
        keys = []
        keys.append(item)
    elif max_v == l.count(item):
        keys.append(item)

for i in sorted(keys):
    print(i)
    
    keys.append(item)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = Counter(input() for _ in range(N))
m = max(S.values())
for v in sorted(k for k, v in S.items() if v == m):
	print(v)