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

n=int (input())
a= list(map(int, input().strip().split()))
b=[0]*n
for i in range(n):
    for j in range(1,n+1):
        if a[i]==j:
            b[j-1]=i+1
print(*b)

### FIXED CODE ###

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

import sys


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


def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] += v

    #    dp = [[0] * 4 for j in range(C)]
    dp0 = [0] * C
    dp1 = [0] * C
    dp2 = [0] * C
    dp3 = [0] * C

    for i in range(R):
        for j in range(C):
            ct = field[i][j]
            premax = max(dp0[j], dp1[j], dp2[j], dp3[j])

            if ct == 0:
                if j > 0:
                    dp0[j] = max(dp0[j - 1], premax)
                    dp1[j] = dp1[j - 1]
                    dp2[j] = dp2[j - 1]
                    dp3[j] = dp3[j - 1]
                else:
                    dp0[j] = premax

                # for k in range(1, 4):
                #     if j > 0:
                #         dp[j][k] = dp[j - 1][k]
                #




            # else:
            #     if j > 0:
            #         dp[j][0] = max(dp[j - 1][0], premax)
            #         dp[j][1] = max(ct + max(dp[j - 1][0], premax), dp[j - 1][1])
            #     else:
            #         dp[j][0] = premax
            #         dp[j][1] = premax + ct
            #     for k in range(2, 4):
            #         if j > 0:
            #             dp[j][k] = max(dp[j - 1][k - 1] + ct, dp[j - 1][k])
            else:
                if j > 0:
                    dp0[j] = max(dp0[j - 1], premax)
                    dp1[j] = max(ct + max(dp0[j - 1], premax), dp1[j - 1])
                    dp2[j] = max(dp1[j - 1] + ct, dp2[j - 1])
                    dp3[j] = max(dp2[j - 1] + ct, dp3[j - 1])
                else:
                    dp0[j] =premax
                    dp1[j] = premax+ct

    #print(max(dp[C - 1]))
    print(max(dp0[C-1], dp1[C-1], dp2[C-1], dp3[C-1]))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


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


def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] += v

    dp = [[0] * 4 for j in range(C)]

    for i in range(R):
        for j in range(C):
            ct = field[i][j]
            premax = max(dp[j])

            if ct == 0:
                if j>0:
                    dp[j][0] = max(dp[j - 1][0], premax)
                else:
                    dp[j][0] = premax

                for k in range(1, 4):
                    if j > 0:
                        dp[j][k] = dp[j - 1][k]
            else:
                if j>0:
                    dp[j][0] = max(dp[j - 1][0], premax)
                    dp[j][1] = max(ct + max(dp[j - 1][0], premax), dp[j - 1][1])
                else:
                    dp[j][0] = premax
                    dp[j][1] = premax +ct
                for k in range(2, 4):
                    if j > 0:
                        dp[j][k] = max(dp[j - 1][k - 1] + ct, dp[j - 1][k])

    print(max(dp[C - 1]))


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

BIG_NUM = 10**18

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

l = [BIG_NUM]*(N+200)
l[0] = 0
for i in range(1, N):
    l[i] = min([
        l[i-j] + abs(H[i]-H[i-j]) for j in range(1, min(N, K, i)+1)
    ])

# print(l)
print(l[N-1])

### FIXED CODE ###

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

costs = [0]*(N+10)
for i in range(1, N):
    j = max(0, i-K)
    h_i = H[i]
    costs[i] = min(cost+abs(h_i-h) for cost, h in zip(costs[j:i], H[j:i]))

print(costs[N-1])
### BUGGY CODE ###

from collections import Counter
from collections import defaultdict

N=input()

fact= [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact.append(fact_tmp) 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n]/fact[r]/fact[n-r])

C=defaultdict(lambda: 0) 
for i in range(N):
	s=raw_input()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=ncr(i,2)

print ans


### FIXED CODE ###

import sys
from collections import Counter
from collections import defaultdict

N=input()

C=defaultdict(lambda: 0) 
for i in range(N):
	s=sys.stdin.readline().strip()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=i*(i-1)/2

print ans
### BUGGY CODE ###

n,x,y=map(int,input().split())
ans={i:0 for i in range(n)}
dp=[[0]*n for _ in range(n)]
for i in range(1,n+1):
  for j in range(i+1,n+1):
    if j<=x or y<=i:
      dp[i-1][j-1]=j-i  
    elif j<y:
      if i<=x:
        dp[i-1][j-1]=x-i+min(j-x,1+y-j)
      else:
        dp[i-1][j-1]=min(j-i,i-x+y-j+1)
    elif y<=j:
      if i<=x:
        dp[i-1][j-1]=x-i+1+j-y
      else:
        dp[i-1][j-1]=j-y+min(y-i,1+i-x)
    else:
      print("Error")
      print(i,j)
for i in range(0,n):
  for j in range(i,n):
    ans[dp[i][j]]+=1
for i in range(1,n):
  print(ans[i])

### FIXED CODE ###

n,x,y=map(int,input().split())
ans={i:0 for i in range(n)}
dp=[[0]*n for _ in range(n)]
for i in range(1,n+1):
  for j in range(i+1,n+1):
    if j<=x or y<=i:
      dp[i-1][j-1]=j-i  
    elif j<y:
      if i<=x:
        dp[i-1][j-1]=x-i+min(j-x,1+y-j)
      else:
        dp[i-1][j-1]=min(j-i,i-x+y-j+1)
    elif y<=j:
      if i<=x:
        dp[i-1][j-1]=x-i+1+j-y
      else:
        dp[i-1][j-1]=j-y+min(y-i,1+i-x)
    else:
      print("Error")
      print(i,j)
for i in range(0,n):
  for j in range(i,n):
    ans[dp[i][j]]+=1
for i in range(1,n):
  print(ans[i])
### BUGGY CODE ###

import numpy as np

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.zeros([H, W], dtype=np.int) - 1
    right = np.zeros([H, W], dtype=np.int) - 1
    up = np.zeros([H, W], dtype=np.int) - 1
    down = np.zeros([H, W], dtype=np.int) - 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
                
    print(np.max(left+right+up+down) + 1)

main()

### FIXED CODE ###

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':        
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()
### BUGGY CODE ###

N,K=map(int,input().split())
x=[int(i) for i in input().split()]

import bisect

zp=bisect.bisect_left(x,0)
cost=10**13

for i in range(max(0,zp-K),min(zp+1,N-K+1)):
    x2=x[i:i+K]
    c=min(abs(min(x2[0],0)),max(0,x2[-1]))*2 + max((-1)*x2[0],x2[-1])
    cost=min(cost,c)

print(cost)

### FIXED CODE ###

N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
    cost=min(cost,c)

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

N, K = map(int, input().split())
temp = N
mini = float("inf")
while True:
    mini = min(temp, mini)
    temp = abs(temp - K)
    if temp >= mini:
        break
print(mini)

### FIXED CODE ###

N, K = map(int, input().split())
t = N % K
print(min(K-t, t))
### BUGGY CODE ###

class SegmentTree:
  def __init__(self, size, default, op = min):
    self.size = 2**size.bit_length()
    self.dat = [default]*(self.size*2)
    self.op = op

  def update(self, i, x):
    i += self.size
    self.dat[i] = x
    while i > 0:
      i >>= 1
      self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])

  def add(self, i, x):
    i += self.size
    self.dat[i] = self.op(self.dat[i], x)
    while i > 0:
      i >>= 1
      self.dat[i] = self.op(self.dat[i], x)

  def get(self, a, b = None):
    if b is None:
      b = a + 1
    l, r = a + self.size, b + self.size
    res = None
    while l < r:
      if l & 1:
        if res is None:
          res = self.dat[l]
        else:
          res = self.op(res, self.dat[l])
        l += 1

      if r & 1:
        r -= 1
        if res is None:
          res = self.dat[r]
        else:
          res = self.op(res, self.dat[r])
      l >>= 1
      r >>= 1
    return res

N,M = map(int,input().split())
LRC = [list(map(int,input().split())) for _ in range(M)]
LRC.sort(key=lambda x:(x[0],x[1]))
#print(LRC)

INF = 10**18
dp = SegmentTree(N,INF,min)
dp.update(0,0)
#print(dp.get(0,1))

for l,r,c in LRC:
  for i in range(l,r):
    p = dp.get(l-1,r-1)+c
    dp.update(i,min(p,dp.get(i)))
print(dp.get(N-1) if dp.get(N-1) != INF else -1)


### FIXED CODE ###

class SegmentTree:
  def __init__(self, size, default, op = min):
    self.size = 2**size.bit_length()
    self.dat = [default]*(self.size*2)
    self.op = op

  def update(self, i, x):
    i += self.size
    self.dat[i] = x
    while i > 0:
      i >>= 1
      self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])

  def add(self, i, x):
    i += self.size
    self.dat[i] = self.op(self.dat[i], x)
    while i > 0:
      i >>= 1
      self.dat[i] = self.op(self.dat[i], x)

  def get(self, a, b = None):
    if b is None:
      b = a + 1
    l, r = a + self.size, b + self.size
    res = None
    while l < r:
      if l & 1:
        if res is None:
          res = self.dat[l]
        else:
          res = self.op(res, self.dat[l])
        l += 1

      if r & 1:
        r -= 1
        if res is None:
          res = self.dat[r]
        else:
          res = self.op(res, self.dat[r])
      l >>= 1
      r >>= 1
    return res

N,M = map(int,input().split())
LRC = [list(map(int,input().split())) for _ in range(M)]
LRC.sort(key=lambda x:(x[0],x[1]))
#print(LRC)

INF = 10**18
dp = SegmentTree(N,INF,min)
dp.update(0,0)
#print(dp.get(0,1))

for l,r,c in LRC:
  p = dp.get(l-1,r-1)+c
  # cf.https://ikatakos.com/pot/programming_algorithm/contest_history/atcoder/2019/1109_nikkei2019-2-qual
  #for i in range(l,r):
  #  if p < dp.get(i):
  #    dp.update(i,p)
  if p < dp.get(r-1):
    dp.update(r-1,p)
print(dp.get(N-1) if dp.get(N-1) != INF else -1)
### BUGGY CODE ###

from collections import deque
 
n, m = map(int, input().split(" "))
load = {}
for _ in range(m):
    a, b = map(int, input().split(" "))
    load[a] = load.get(a, set()) | set({b})
    load[b] = load.get(b, set()) | set({a})
 
queue = deque([1])
visited = {1: 1}
 
while len(queue) != 0:
    curr = queue.popleft()
    for _next in load[curr]:
        if visited.get(_next, -1) == -1:
            visited[_next] = curr
            queue.append(_next)
 
if len(visited) == n:
    print("Yes")
    for i in range(2, n+1):
        print(visited[i])
else:
    print("No")

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split(" "))
load = {i:[] for i in range(1, n+1)}
for _ in range(m):
    a, b = map(int, input().split(" "))
    load[a].append(b)
    load[b].append(a)

queue = deque([1])
visited = {1: 1}

while len(queue) != 0:
    curr = queue.popleft()
    for _next in load[curr]:
        if visited.get(_next, -1) == -1:
            visited[_next] = curr
            queue.append(_next)

if len(visited) == n:
    print("Yes")
    for i in range(2, n+1):
        print(visited[i])
else:
    print("No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    c = [0]*len(S)

    for i in range(len(S)):
        if S[i] == 'R':
            j = 1
            while S[i+j] == 'R':
                j += 1
            # i+j -> L
            if j % 2 == 0:
                c[i+j] += 1
            else:
                c[i+j-1] += 1
        if S[i] == 'L':
            j = -1
            while S[i+j] == 'L':
                j -= 1
            # i+j -> R
            if j % 2 == 0:
                c[i+j] += 1
            else:
                c[i+j+1] += 1

    for x in c:
        print(x, end=' ')


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def solve(S):
    def split(sub):
        result = []
        s = sub.partition('LR')
        while s[1] != '':
            new_s = s[0] + s[1][0]
            rem = s[1][1] + s[2]
            result.append(new_s)
            s = rem.partition('LR')
        return result + [s[0]]

    def count(sub):
        c = [0] * len(sub)
        l = sub.index('L')

        # R
        i = 1
        while l - i >= 0:
            c[l - (i % 2)] += 1
            i += 1

        # L
        i = 0
        while l + i < len(sub):
            c[l - (i % 2)] += 1
            i += 1

        return c

    ans = []
    for s in split(S):
        ans += count(s)
    return ans


def main():
    S = input().strip()
    ans = solve(S)

    for x in ans:
        print(x, end=' ')


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

import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[j]=max(a[j],c[xc[i]])
    a.sort()
print(sum(a))

### FIXED CODE ###

import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
co=0
f=0
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[co]=max(a[co],c[xc[i]])
        if a[co]>c[xc[i]]:
            f=1
            break                
        co+=1
        if co>=n:
            f=1 
            break
    if f==1:
        break
print(sum(a))
### BUGGY CODE ###

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

for i in range(Q):
    B, C = map(int, input().split())
    A = [C if i == B else i for i in A]
    print(sum(A))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
D = [0] * (10 ** 5 + 1)
for i in range(N):
    D[A[i]] += 1

Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    S += (C - B) * D[B]
    print(S)
    
    D[C] += D[B] 
    D[B] = 0
### BUGGY CODE ###

#ABC 55, B - training camp
n = int(input())
p = 1
for i in range(1, n+1):
    p *= i
print(p % (10**9 + 7))


### FIXED CODE ###

#ABC 55, B - training camp
n = int(input())
p = 1
for i in range(1, n+1):
    p *= i
    p = p % (10**9 + 7)
print(p)
### BUGGY CODE ###

n,p= map(int,input().split())
res=1
if n==1:
    res=p
else:
    for i in range(2,int(p**(1/n))+2):
        x=i**n
        if x>p:
            break
        if p%x==0:
            res=i
print(res)

### FIXED CODE ###

n,p= map(int,input().split())
for i in range(round(p**(1/n)),0,-1):
    if p%(i**n)==0:
        print(i)
        exit()
### BUGGY CODE ###

n, m = map(int, input().split())
ab=[]
for i in range(n):
    a, b = map(int, input().split())
    for j in range(b):
        ab.append(a)

ab.sort()
print(sum(ab[:m]))


### FIXED CODE ###

import bisect

n, m = map(int, input().split())

ab=[]
for i in range(n):
    ab.append(list(map(int, input().split())))

ab = sorted(ab, key=lambda x: x[0])

def func():
    c=0
    ans=0

    for target in ab:
        for i in range(target[1]):
            ans+=target[0]
            c+=1

            if c == m:
                return ans
            

print(func())
### BUGGY CODE ###

from bisect import bisect_right
A, B, Q = map(int, input().split())
BIG = 10**10 + 1
S = [-BIG] + [int(input()) for _ in range(A)] + [BIG*2]
T = [-BIG] + [int(input()) for _ in range(B)] + [BIG*2]
for _ in range(Q):
  x = int(input())
  shrine_b = bisect_right(S, x)
  dsl = x-S[shrine_b-1]
  dsr = S[shrine_b]-x
  temple_b = bisect_right(T, x)
  dtl = x-T[temple_b-1]
  dtr = T[temple_b]-x

  print(min(
    dsl if dsl > dtl else dtl,
    dsr if dsr > dtr else dtr,
    dsl * 2 + dtr,
    dsl + dtr * 2,
    dsr * 2 + dtl,
    dsr + dtl * 2
  ))

### FIXED CODE ###

from bisect import bisect_right
A, B, Q = map(int, input().split())
BIG = 10**10 + 1
S = [-BIG] + [int(input()) for _ in range(A)] + [BIG*2]
T = [-BIG] + [int(input()) for _ in range(B)] + [BIG*2]
for _ in range(Q):
  x = int(input())
  shrine_b = bisect_right(S, x)
  dsl = x-S[shrine_b-1]
  dsr = S[shrine_b]-x
  temple_b = bisect_right(T, x)
  dtl = x-T[temple_b-1]
  dtr = T[temple_b]-x

  print(min(
    dsl if dsl > dtl else dtl,
    dsr if dsr > dtr else dtr,
    dsl * 2 + dtr,
    dsl + dtr * 2,
    dsr * 2 + dtl,
    dsr + dtl * 2
  ))
### BUGGY CODE ###

from collections import deque

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

res = 0
for i in range(H):
    for j in range(W):
        stack = deque([])
        flag = [[False for _ in range(W)] for _ in range(H)]
        stack.append([i, j])
        flag[i][j] = True
        start = S[i][j]
        while len(stack) > 0:
            y, x = stack.popleft()
            for nx, ny in ([1, 0], [0, 1], [-1, 0], [0, -1]):
                if 0<= x + nx < W and 0 <= y + ny < H:
                    if S[y][x] != S[y+ny][x+nx] and flag[y+ny][x+nx] == False:
                        stack.append([y+ny, x+nx])
                        flag[y+ny][x+nx] = True
                        if S[y+ny][x+nx] != start:
                            res += 1
            
                
            
            
print(res//2)


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]
flag = [[-1 for _ in range(W)] for _ in range(H)]

now = 0
for i in range(H):
    for j in range(W):
        if flag[i][j] == -1:
            stack = deque([]) 
            stack.append([i, j])
            flag[i][j] = now
            while len(stack) > 0:
                y, x = stack.popleft()
                for nx, ny in ([1, 0], [0, 1], [-1, 0], [0, -1]):
                    if 0<= x + nx < W and 0 <= y + ny < H:
                        if S[y][x] != S[y+ny][x+nx] and flag[y+ny][x+nx] == -1:
                            stack.append([y+ny, x+nx])
                            flag[y+ny][x+nx] = now
            now += 1
    
Black = [0 for _ in range(now+1)]
White = [0 for _ in range(now+1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            Black[flag[i][j]] += 1
        else:
            White[flag[i][j]] += 1
   
res = 0
for i in range(now + 1):
    res += Black[i] * White[i]
    
print(res)
### BUGGY CODE ###

import sys
from collections import Counter
from bisect import insort_left

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = Counter(list(map(int, input().split())))
    
    A = sorted([[a, c] for a, c in A.items()])
    
    for i in range(M):
        B, C = map(int, input().split())
        
        c = idx = 0
        for j in range(len(A)):
            if A[j][0] > C: break
        
            x = min(B, A[j][1])
            c += x
            B -= x
            A[j][1] -= x
            
            if not A[j][1]: idx += 1
            if not B: break
        
        if c: 
            for k in range(idx): A.pop(0)
                
            insort_left(A, [C, c])
    
    print(sum([a[0] * a[1] for a in A]))
    
if __name__ == '__main__':
    main() 

### FIXED CODE ###

from collections import Counter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = set(A)
A = Counter(A)

for i in range(M):
    B, C = list(map(int, input().split()))
    A[C] += B
    a.add(C)
a = sorted(list(a), reverse=True)

ans = 0

for i in a:
    ans += i * min(A[i], N)
    N -= A[i]
    if N <= 0:
        break
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
event=[]
stop=set()
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append([s-x,1,x])
    event.append([t-x,-1,x])
event.sort()
d=[int(input()) for _ in range(q)]

k=0
for i in range(q):
    while k<2*n and event[k][0]<=d[i]:
        if event[k][1]==1: stop.add(event[k][2])
        else: stop.remove(event[k][2])
        k+=1
    print(min(stop) if stop!=set() else -1)

### FIXED CODE ###

def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

    n,q=map(int,input().split())

    event=[]
    for _ in range(n):
        s,t,x=map(int,input().split())
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(input()),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()
### BUGGY CODE ###

N = int(input())
S = [input() for _ in range(N)]

newS = sorted(list(set(S)))
frq = [0] * len(newS)

for i in range(N):
    for j in range(len(newS)):
        if S[i] == newS[j]:
            frq[j] += 1
            break
ma = max(frq)
for i in range(len(newS)):
    if frq[i] == ma:
        print(newS[i])

### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]

S = sorted(S)
newS = sorted(list(set(S)))
frq = [0] * len(newS)

si = index = 0
for i in range(N):
    if i == N-1:
        frq[index] = N - si
    elif S[i] != S[i+1]:
        frq[index] = i + 1 - si
        si = i + 1
        index += 1
    
ma = max(frq)
for i in range(len(newS)):
    if frq[i] == ma:
        print(newS[i])