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

import numpy as np
import math as m

def main(**kwargs):
    front = ""
    back = ""
    now = "f"

    for q in qs:
        if q[0] == "1":
            if now == "b":
                now = "f"
            else:
                now = "b"

    if now == "f":
        now = "f"

        for q in qs:
            if q[0] == "1":
                if now == "b":
                    now = "f"
                else:
                    now = "b"
            else:
                if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                    front += q[2]
                else:
                    back += q[2]

        res = front[::-1] + s + back
    else:
        now = "f"

        for q in qs:
            if q[0] == "1":
                if now == "b":
                    now = "f"
                else:
                    now = "b"
            else:
                if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                    front += q[2]
                else:
                    back += q[2]
        res = back[::-1] + s[::-1] + front
        
    return res

if __name__ == "__main__":
    cin = np.array(input().split(" "))
    s, *_ = cin
    cin = np.array(input().split(" ")).astype("int")
    n, *_ = cin

    qs = []

    for i in range(n):
        cin = np.array(input().split(" "))
        qs.append(list(cin))
    
    cout = main(s=s, n=n, qs=qs)
    print(cout)


### FIXED CODE ###

import numpy as np
import math as m
import collections

def main(**kwargs):
    front = collections.deque()
    back = collections.deque()
    now = "f"

    for q in qs:
        if q[0] == "1":
            if now == "b":
                now = "f"
            else:
                now = "b"

    if now == "f":
        now = "f"

        for q in qs:
            if q[0] == "1":
                if now == "b":
                    now = "f"
                else:
                    now = "b"
            else:
                if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                    front.appendleft(q[2])
                else:
                    back.append(q[2])

        res = "".join(front) + s + "".join(back)
    else:
        now = "f"

        for q in qs:
            if q[0] == "1":
                if now == "b":
                    now = "f"
                else:
                    now = "b"
            else:
                if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                    front.append(q[2])
                else:
                    back.appendleft(q[2])
        res = "".join(back) + s[::-1] + "".join(front)
        
    return res

if __name__ == "__main__":
    cin = np.array(input().split(" "))
    s, *_ = cin
    cin = np.array(input().split(" ")).astype("int")
    n, *_ = cin

    qs = []

    for i in range(n):
        cin = np.array(input().split(" "))
        qs.append(list(cin))
    
    cout = main(s=s, n=n, qs=qs)
    print(cout)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
class Node:
    def __init__(self):
        self.next=[]
    def get_data(self,new_next,weight=1):
        self.next.append(new_next)
def BFS(i,depth,K):  
    depth+=1
    tmp=i
    seki=1
    num=len(tmp)
    if depth==1:
        calc=K-1
        diff=0
        #for i in range(calc,max(1,calc-(len(tmp)-diff)),-1):
        
        for i in range(calc,calc-(num-diff),-1):
            seki*=i%1000000007
        
    else:
        calc=K-2
        diff=1
        for i in range(calc,calc-(num-diff),-1):
            seki*=i%1000000007
            
    for each in tmp:
        if not check_node[each]:
            check_node[each]=True
            seki*=BFS(node[each].next,depth,K)%1000000007
    return seki


N,K=list(map(int,input().split()))
node=[Node() for _ in range(N)]
check_node=[False for _ in range(N)]
check_node[0]=True
for i in range(N-1):
    p,n=list(map(int,input().split()))
    node[n-1].get_data(p-1)
    node[p-1].get_data(n-1)
start=0
d=0

com=K*BFS(node[0].next,d,K)
print(com%1000000007)

### FIXED CODE ###

import sys
import math
sys.setrecursionlimit(1000000)
mod=1000000007
class Node:
    def __init__(self):
        self.next=[]
    def get_data(self,new_next,weight=1):
        self.next.append(new_next)
def BFS(i,depth,K):  
    depth+=1
    tmp=i
    seki=1
    num=len(tmp)
    if depth==1:
        calc=K-1
        loop=range(calc,calc-num,-1)
        for i in loop:
            seki*=i%1000000007

        
    else:
        calc=K-2
        num-=1
        if calc>=num:
            seki=cache[num]
        else:
            print(0)
            exit()

            
            
    for each in tmp:
        if not check_node[each]:
            check_node[each]=True
            seki*=BFS(node[each].next,depth,K)%mod
    return seki


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

if K>2:
    cache=[0 for i in range(K-2)]
    cache[0]=1
    for i in range(1,K-2):
        cache[i]=cache[i-1]*(K-1-i)%mod
    cache.append(cache[-1])
else:
    cache=[1,1]
node=[Node() for _ in range(N)]
check_node=[False for _ in range(N)]
check_node[0]=True
for i in range(N-1):
    p,n=list(map(int,input().split()))
    node[n-1].get_data(p-1)
    node[p-1].get_data(n-1)
start=0
d=0

com=K*BFS(node[0].next,d,K)
print(int(com)%mod)
### BUGGY CODE ###

n = int(input())
table = [[]]
for i in range(n):
  a = list(map(int, input().split()))
  table.append(a)
cursor = [0]*(n+1)
is_matched = [False] * (n+1)
d = 0
match = 0
while match < n * (n-1) //2:
  now_match = match
  for i in range(1, n+1):
    for j in range(i+1, n+1):
      if cursor[i] < n-1 and table[i][cursor[i]] == j and not is_matched[i] and table[j][cursor[j]] == i and not is_matched[j]:
        match += 1
        cursor[i] += 1
        is_matched[i] = True
        cursor[j] += 1
        is_matched[j] = True
  if now_match == match:
    print(-1)
    exit()
  d += 1
  is_matched =  [False] * (n+1)
print(d)

### FIXED CODE ###

n = int(input())
table = [[] for _ in range(n+1)]
for i in range(1, n+1):
  a = list(map(int, input().split()))
  table[i] = a
cursor = [0]*(n+1)
is_matched = set()
d = 0
match = 0
while match < n * (n-1) //2:
  now_match = match
  for i in range(1, n):
    if cursor[i] < n-1 and i not in is_matched:
      j = table[i][cursor[i]]
      if i < j and j not in is_matched and table[j][cursor[j]] == i :
        match += 1
        cursor[i] += 1
        is_matched.add(i)
        cursor[j] += 1
        is_matched.add(j)
  if now_match == match:
    print(-1)
    exit()
  if d > 30000:
    print(499500)
    exit()  
  d += 1
  is_matched.clear()
print(d)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = map(int, input().split())
    P = list(map(int, input().split()))
    uf = UnionFind(N+1)
    for i in range(M):
        x, y = map(int, input().split())
        uf.union(x, y)
    ans = 0
    for r in uf.roots():
        ms = uf.members(r)
        p = set()
        for m in ms:
            p.add(P[m-1])
#        print(p, ms)
        ans += len(p & set(ms))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N, M = map(int, input().split())
    P = list(map(int, input().split()))
    uf = UnionFind(N)
    for i in range(M):
        x, y = map(int, input().split())
        uf.union(x-1, y-1)
    ans = 0
    for i in range(N):
        if uf.same(P[i]-1, i):
            ans += 1
    print(ans)


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

N = int(input())
A = list(map(int, input().split()))
num_list = [0] * 100
P = 10 ** 9 + 7
for i in A:
    for j in range(len(bin(i)) - 2):
        num_list[j] += (i >> j) & 1
ans = 0


def func(N, n):
    return (N - n) * n


for i in range(100):
    ans = (ans + func(N, num_list[i]) * 2 ** i) % P
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
num_list = [0] * 100
P = 10 ** 9 + 7
for i in A:
    tmp = i
    for j in range(len(bin(i)) - 2):
        num_list[j] += (tmp & 1)
        tmp = tmp >> 1
ans = 0


def func(N, n):
    return (N - n) * n


for i in range(100):
    ans = (ans + func(N, num_list[i]) * 2 ** i) % P
print(ans)
### BUGGY CODE ###

n=int(input())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a:
  lcm = lcm * i // fractions.gcd(lcm, i)
b=[]
for i in a:
  b.append(lcm//i)
ans=sum(b)%(10**9+7)
print(ans)

### FIXED CODE ###

n=int(input())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a:
  lcm = lcm * i // fractions.gcd(lcm, i)
b=[]
for i in a:
  b.append(lcm//i)
ans=sum(b)%(10**9+7)
print(ans)
### BUGGY CODE ###

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

# In[69]:


#import copy
import numpy as np

N, M = map(int, input().split())
As = np.sort(np.array(list(map(int, input().split()))))[::-1]
"""
3 3
2 13 8

4 4
1 9 3 5
"""


# In[70]:


As


# In[71]:


#As[0] = As[0] // 2
#arg = 
arg = 0
argrange = 0
As[arg] = As[arg] // 2
for i in range(1, M):
    argrange = max(arg + 1, argrange)
    arg = np.argmax(As[:argrange+1])
    #print(arg)
    As[arg] = As[arg] // 2
    #As[:i+1] = np.sort(As[:i+1])[::-1]
    #As[0] = As[0] // 2


# In[72]:


#print(As)
print(sum(As))


# In[ ]:






### FIXED CODE ###

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

# In[8]:


# import copy
#import numpy as np
import heapq

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

def int_minus(s):
    return -int(s)

As = list(map(int_minus, input().split()))
"""
3 3
2 13 8

4 4
1 9 3 5
"""


# In[10]:


heapq.heapify(As)


# In[17]:


for i in range(M):
    mx = heapq.heappop(As)
    heapq.heappush(As, -(-mx//2))


# In[19]:


#print(As)
print(-sum(As))


# In[ ]:
### BUGGY CODE ###

n = int(input())
List = list(map(int, input().split(" ")))
a = 1
for i in range(n):
    m = List.count(a)
    a += 1
    print(m)

### FIXED CODE ###

N = int(input())
List = list(map(int,input().split()))
List2 = [0]*N
for i in range(N-1):
    List2[List[i-1]-1] += 1 
for j in List2:
    print(j)
### BUGGY CODE ###

def lowerBound(arr, n):
    arr += [10e9+7]
    low, high = 0, len(arr)
    mid = (low+high)//2
    while high-low>1:
        if arr[mid]>=n: high = mid
        else: low = mid
        mid = (low+high)//2
    return high

def upperBound(arr, n):
    arr = [0] + arr
    low, high = 0, len(arr)
    mid = (low+high)//2
    while high-low>1:
        if arr[mid]>n: high = mid
        else: low = mid
        mid = (low+high)//2
    return low

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c, i)
    ans += cnt_a * cnt_b
print(ans)

### FIXED CODE ###

def lowerBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>=n: high = mid
        else: low = mid
    return high

def upperBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>n: high = mid
        else: low = mid
    return low+1

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c,i)
    ans += cnt_a * cnt_b
print(ans)
### BUGGY CODE ###

s = input()
x, y = map(int, input().split())
edge = [[], []]
# delete first edge
firstedge = 0
for c in s:
    if c == 'T': break
    else: firstedge += 1
x -= firstedge
dir = 0
cur = 0
for c in s[firstedge:]:
    if c == 'T':
        if cur > 0:
            edge[dir].append(cur)
            cur = 0
        dir = (dir + 1) % 2
    else:
        cur += 1
if cur > 0:
    edge[dir].append(cur)
xtar = sum(edge[0]) + x
ytar = sum(edge[1]) + y
if xtar < 0 or ytar < 0 or x > sum(edge[0]) or y > sum(edge[1]):
    print('No')
    exit()
# partition dp
dx = [0] * (xtar + 1)
dy = [0] * (ytar + 1)
dx[0], dy[0] = 1, 1
for e in edge[0]:
    for i in range(xtar+1 - 2*e):
        pre = dx.copy()
        if pre[i] == 1:
            dx[i+2*e] = 1
    if dx[xtar]: break
for e in edge[1]:
    for i in range(ytar+1 - 2*e):
        pre = dy.copy()
        if pre[i] == 1:
            dy[i+2*e] = 1
    if dy[ytar]: break
if dx[xtar] and dy[ytar]: print('Yes')
else: print('No')

### FIXED CODE ###

s = input()
x, y = map(int, input().split())
edge = [[], []]
# delete first edge
firstedge = 0
for c in s:
    if c == 'T': break
    else: firstedge += 1
x -= firstedge
dir = 0
cur = 0
for c in s[firstedge:]:
    if c == 'T':
        if cur > 0:
            edge[dir].append(cur)
            cur = 0
        dir = (dir + 1) % 2
    else:
        cur += 1
if cur > 0:
    edge[dir].append(cur)
xtar = sum(edge[0]) + x
ytar = sum(edge[1]) + y
if xtar < 0 or ytar < 0 or x > sum(edge[0]) or y > sum(edge[1]):
    print('No')
    exit()
# partition dp
dx = [0] * (xtar + 1)
dy = [0] * (ytar + 1)
dx[0], dy[0] = 1, 1
for e in edge[0]:
    preone = []
    for i in range(xtar+1 - 2*e):
        if dx[i] == 1:
            preone.append(i)
    for i in preone:
        dx[i+2*e] = 1
    if dx[xtar]: break
for e in edge[1]:
    preone = []
    for i in range(ytar+1 - 2*e):
        if dy[i] == 1:
            preone.append(i)
    for i in preone:
        dy[i+2*e] = 1
    if dy[ytar]: break
if dx[xtar] and dy[ytar]: print('Yes')
else: print('No')
### BUGGY CODE ###

import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    
    def lcs(x,y):
        lx,ly = len(x),len(y)
        dp = [[0 for _ in range(ly+1)] for _ in range(lx+1)]
        for i in range(lx):
            for j in range(ly):
                if x[i] == y[j]:
                    p = 1
                else:
                    p = 0
                dp[i+1][j+1] = max(dp[i][j]+p,dp[i][j+1],dp[i+1][j])
        return dp[-1][-1]
    
    print(max(lcs(s[:i],s[i:]) for i in range(N)))
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

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

# kが極端に少ないので、下位K個を管理してよさそうな気がする
# -> なんかダメ
# じゃ決め打ちして全探索することにしてみる どうせ長さは最大でKなので
# 時間的に間に合うか微妙な気がする
from string import ascii_lowercase
s = input()
k = int(input())
cur = 0


def f(v):
    global cur
    if len(v) <= k:
        if v in s:
            cur += 1
        if cur == k:
            print(v)
            exit()
        else:
            for c in ascii_lowercase:
                f(v + c)


for c in ascii_lowercase:
    f(c)

### FIXED CODE ###

# 最小かつ最長はzzzzzなので各文字+4まで調べてみるか（27^5-1で全探索もできると思うがやり方がわからん
s = input()
k = int(input())
d = set()
for i in range(len(s)):
    for j in range(1, 6):
        if i + j <= len(s):
            d.add(s[i : i + j])
print(sorted(list(d))[k-1])
### BUGGY CODE ###

#!/usr/bin/env python


def main():
    s = input()
    al, ar = 0, 0
    a = []
    for i in range(len(s) + 1):
        if i < len(s) and s[i] == '>':
            if ar == 0:
                for si in s[i:]:
                    if si == '>':
                        ar = ar + 1
                    else:
                        break
            else:
                ar = ar - 1
        else:
            ar = 0

        if i > 0 and s[i - 1] == '<':
            al = al + 1
        else:
            al = 0

        a.append(max(al, ar))

    print(sum(a))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python


def main():
    s = input()
    al, ar = ([0] * (len(s) + 1), [0] * (len(s) + 1))
    for i in range(0, len(s)):
        al[i + 1] = al[i] + 1 if s[i] == '<' else 0

    for i in range(len(s) - 1, -1, -1):
        ar[i] = ar[i + 1] + 1 if s[i] == '>' else 0

    sum_a = sum([max(aln, arn) for aln, arn in zip(al, ar)])
    print(sum_a)


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

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

d = {aa: 0 for aa in A}
c = sorted({a: A.count(a) for a in A if A.count(a) >= 2})
x = len(c)
if(x <= 1):
  ans = 0
elif(d.get(c[x-1]) >= 4):
  ans = c[x-1] * c[x-1]
else:
  ans = c[x-1] * c[x-2]
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
d = {}
for a in A:
  if(a in d):
    d[a] += 1
  else:
    d[a] = 1
x, y = 0, 0
for k, v in d.items():
  if(v >= 2 and k > y):
    if(k >= x):
      if(v >= 4):
        y = k
      else:
        y = x
      x = k
    else:
      y = k
print(x * y)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
print(A.count(1))
for i, num in enumerate(A):
    ORG = A[:]
    ORG.pop(i)
    me = i + 2
    print(ORG.count(me))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
x = [0] * N
for s in A:
    x[s-1] += 1
for s in x:
    print(s)
### BUGGY CODE ###

N = int(input())
P = [int(p) for p in input().split()]
out = 0

for i in range(N):
  for j in range(0, i):
    if P[i] > P[j]:
      out += 1
      break
print(N - out)

### FIXED CODE ###

N = int(input())
P = [int(p) for p in input().split()]
ans = 0
mi = P[0]
for i in range(N):
  mi = min(mi, P[i])
  if mi >= P[i]:
    ans += 1 
print(ans)
### BUGGY CODE ###

l,n=map(int,input().split())
c=n
tree=[int(input()) for i in range(n)]
reversed_tree=[l-i for i in reversed(tree)]
if n%2 == 0:
  ans= sum(tree)*2 + l*(n-1) +tree[n//2] - sum(tree[n//2:])*4
  ans2= sum(reversed_tree)*2 + l*(n-1) +reversed_tree[n//2] - sum(reversed_tree[n//2:])*4
  n-=1
  c-=1
  ans3= ans-tree.pop(0)*2-l+tree[n//2]*2
  ans= max(ans,ans3)
  ans4= ans2-reversed_tree.pop(0)*2-l+(reversed_tree[n//2])*2
  ans2= max(ans2,ans4)
else:
  ans= sum(tree)*2 + l*(n-1) - tree[n//2] - sum(tree[((n//2)+1):])*4
  ans3=ans
  ans2= sum(reversed_tree)*2 + l*(n-1) - reversed_tree[n//2] - sum(reversed_tree[((n//2)+1):])*4
  ans4=ans2
while n>1:
  n-=1
  ans_stack= ans3-tree.pop(0)*2-l+tree[(n-1)//2]+tree[(n+1)//2]
  ans= max(ans_stack,ans)
  ans3=ans_stack
  n-=1
  ans_stack= ans3-tree.pop(0)*2-l+tree[n//2]*2
  ans=max(ans_stack,ans)
  ans3=ans_stack
n=c
while n>1:
  n-=1
  ans_stack= ans4-reversed_tree.pop(0)*2-l+reversed_tree[(n-1)//2]+reversed_tree[(n+1)//2]
  ans2=max(ans_stack,ans2)
  ans4=ans_stack
  n-=1
  ans_stack= ans4-reversed_tree.pop(0)*2-l+reversed_tree[n//2]*2
  ans2=max(ans2,ans_stack)
  ans4=ans_stack
print(max(ans,ans2))


### FIXED CODE ###

import sys
from collections import deque
l,n=map(int,input().split())
c=n
tree1=[int(i) for i in sys.stdin]
reversed_tree1=[l-i for i in reversed(tree1)]
tree=deque(tree1)
reversed_tree=deque(reversed_tree1)
if n%2 == 0:
  ans= sum(tree1)*2 + l*(n-1) +tree1[n//2] - sum(tree1[n//2:])*4
  ans2= sum(reversed_tree1)*2 + l*(n-1) +reversed_tree1[n//2] - sum(reversed_tree1[n//2:])*4
  n-=1
  c-=1
  ans3= ans-tree.popleft()*2-l+tree[n//2]*2
  ans= max(ans,ans3)
  ans4= ans2-reversed_tree.popleft()*2-l+(reversed_tree[n//2])*2
  ans2= max(ans2,ans4)
else:
  ans= sum(tree1)*2 + l*(n-1) - tree1[n//2] - sum(tree1[((n//2)+1):])*4
  ans3=ans
  ans2= sum(reversed_tree1)*2 + l*(n-1) - reversed_tree1[n//2] - sum(reversed_tree1[((n//2)+1):])*4
  ans4=ans2
for i in range(n//2):
  n-=1
  ans_stack= ans3-tree.popleft()*2-l+tree[(n-1)//2]+tree[(n+1)//2]
  ans= max(ans_stack,ans)
  ans3=ans_stack
  n-=1
  ans_stack= ans3-tree.popleft()*2-l+tree[n//2]*2
  ans=max(ans_stack,ans)
  ans3=ans_stack
n=c
for i in range(n//2):
  n-=1
  ans_stack= ans4-reversed_tree.popleft()*2-l+reversed_tree[(n-1)//2]+reversed_tree[(n+1)//2]
  ans2=max(ans_stack,ans2)
  ans4=ans_stack
  n-=1
  ans_stack= ans4-reversed_tree.popleft()*2-l+reversed_tree[n//2]*2
  ans2=max(ans2,ans_stack)
  ans4=ans_stack
print(max(ans,ans2))
### BUGGY CODE ###

import heapq
[N,L] = [int(x) for x in input().split()]
A = []
for i,x in enumerate(input().split()):
    heapq.heappush(A,[int(x),int(i)])
heapq.heapify(A)
ANS = [10**9+1]*N
count = 0
for j in range(N):
    a = heapq.heappop(A)
    for i in range(L):
        try :
            if ANS[a[1]+i] == 10**9+1 :
                ANS[a[1]+i] = str(a[0])
                count += 1
        except IndexError : continue
    if count == N : break
print(" ".join(ANS[L-1:]))

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

N = int(input())
names = []
words = {}
for i in range(N):
    name = input()
    if name not in names:
        words[name] = 1
        names.append(name)
    elif name in names:
        words[name] += 1
        
max_name_list = []
for nm in words.items():
    if nm[1] == max(words.values()):
        max_name_list.append(nm[0])
max_name_list = sorted(max_name_list)
for i in range(len(max_name_list)):
    print(max_name_list[i])

### FIXED CODE ###

N = int(input())
words = {}
for i in range(N):
  name = input()
  if name not in words:
    words[name] = 1
  elif name in words:
    words[name] += 1
    
res_name = []
Max = max(words.values())
for i in words.keys():
  if words[i] == Max:
    res_name.append(i)
res_name = sorted(res_name)
for i in res_name:
  print(i)