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

from collections import deque
q = deque([])

def get_root(i):
    while True:
        if parent[i] == -1:
            return i
        i = parent[i]

def bfs(i):
    global l
    c = 0
    q.append(i)
    while True:
        if len(q) == 0:
            break
        p = q.popleft()
        l.append(p)
        c += 1
        if not children[p] == -1:
            for j in children[p]:
                q.append(j)
    return c

n, m = map(int, input().split())
p = list(map(int, input().split()))
parent = [-1] * n
children = [-1] * n
d = [0] * n
root = []
rank = []
num = ["a"] * n
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if num[x] == "a":
        num[x] = [y]
    else:
        num[x].append(y)
    if num[y] == "a":
        num[y] = [x]
    else:
        num[y].append(x)
    if d[x] == d[y] == 0:
        root.append(x)
        rank.append(1)
        children[x] = [y]
        parent[y] = x
        d[x] = 1
        d[y] = 1
    elif d[x] == 1 and d[y] == 0:
        r = get_root(x)
        children[r].append(y)
        parent[y] = r
        d[y] = 1
    elif d[x] == 0 and d[y] == 1:
        r = get_root(y)
        children[r].append(x)
        parent[x] = r
        d[x] = 1
    else:
        s = get_root(x)
        t = get_root(y)
        if not s == t:
            i = rank[root.index(s)]
            j = rank[root.index(t)]
            if i >= j:
                parent[t] = s
                children[s].append(t)
                if i == j:
                    rank[root.index(s)] += 1
            else:
                parent[s] = t
                children[t].append(s)

ans = 0
for i in range(n):
    if parent[i] == -1 and children[i] != -1:
        l = []
        bfs(i)
        for j in l:
            if p[j] - 1 in l:
                ans += 1
    elif parent[i] == -1:
        if p[i] - 1 == i:
            ans += 1
print(ans)

### FIXED CODE ###

def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m = map(int, input().split())
p = list(map(int, input().split()))
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)
ans = 0
for i in range(n):
    if get_root(i) == get_root(p[i] - 1):
        ans += 1
print(ans)
### BUGGY CODE ###

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

DP = [[0] * (N+1) for _ in range(N+1)]

for w in range(1, N+1):
    for i in range(N):
        j = i + w
        if j > N:
            continue
        if (w+n) % 2 == 1:
            DP[i][j] = min(DP[i+1][j] - A[i], DP[i][j-1] - A[j-1])
        else:
            DP[i][j] = max(DP[i+1][j] + A[i], DP[i][j-1] + A[j-1])

print(DP[0][N])


### FIXED CODE ###

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

DP = [[0] * (N+1) for _ in range(N+1)]

for w in range(1, N+1):
    for i in range(N):
        j = i + w
        if j > N:
            continue
        if (w+n) % 2 == 1:
            DP[i][j] = min(DP[i+1][j] - A[i], DP[i][j-1] - A[j-1])
        else:
            DP[i][j] = max(DP[i+1][j] + A[i], DP[i][j-1] + A[j-1])

print(DP[0][N])
### BUGGY CODE ###

import numpy as np
n,q= map(int,input().split())
s = list(input())
td = [input().split() for _ in range(q)]
data = {i :[] for i in list(set(s))}
for j,i in enumerate(s):
  data[i].append(j+1)

ans = np.array([0]+[1]*n+[0])

for i in td:
  if i[0] in s:
    temp = ans[data[i[0]]].copy()
    ans[data[i[0]]]=0
    if i[1]=='L':
      ans[np.array(data[i[0]])-1]+=temp
    else:
      ans[np.array(data[i[0]])+1]+=temp
  ans[[0,-1]]=0
  
print(ans[1:-1].sum())


### FIXED CODE ###

n,q= map(int,input().split())
s = [0]+list(input())+[0]
td = [input().split() for _ in range(q)]
l,r = 0,n+1
for i,j in td[::-1]:
  if s[l+1]==i and j=='L':
    l+=1
  elif s[l]==i and j=='R':
    l-=1
  if s[r-1]==i and j=='R':
    r-=1
  elif s[r]==i and j=='L':
    r+=1
print(max(0,r-l-1))
### BUGGY CODE ###

from collections import deque
N,M = map(int,input().split())
UV = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
S,T = map(lambda x:int(x)-1,input().split())

es = [[set() for j in range(N)] for i in range(3)]
for u,v in UV:
    es[0][u].add(v)

for i in range(2):
    for j in range(N):
        for k in es[i][j]:
            es[i+1][j] |= es[0][k]

INF = float('inf')
dist = [INF]*N
dist[S] = 0
q = deque([S])
while q:
    v = q.popleft()
    for to in es[2][v]:
        if dist[to] != INF: continue
        dist[to] = dist[v]+1
        if to == T:
            print(dist[to])
            exit()
        q.append(to)

print(-1)

### FIXED CODE ###

from collections import deque
import sys
inputs = sys.stdin.readline
N,M = map(int,input().split())
UV = [tuple(map(lambda x:int(x)-1,inputs().split())) for i in range(M)]
S,T = map(lambda x:int(x)-1,input().split())

es = [[] for i in range(3*N)]
for u,v in UV:
    es[u].append(v+N)
    es[u+N].append(v+2*N)
    es[u+2*N].append(v)

q = deque([S])
INF = float('inf')
dist = [INF] * (3*N)
dist[S] = 0

while q:
    v = q.popleft()
    for to in es[v]:
        if dist[to] != INF: continue
        dist[to] = dist[v] + 1
        if to==T:
            print(dist[to] // 3)
            exit()
        q.append(to)
print(-1)
### BUGGY CODE ###

N, M, QN = [int(x) for x in input().split()]

L = [None] * M
R = [None] * M

MAT0 = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(M):
    l, r = [int(x) for x in input().split()]
    L[i] = l
    R[i] = r
    MAT0[l][r] += 1

MAT = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(0, N + 1):
        MAT[i][j] = MAT[i][j - 1] + MAT0[i][j]

for i in range(QN):
    p, q = [int(x) for x in input().split()]
    ret = 0
    for j in range(p, q + 1):
        ret = ret + MAT[j][q] - MAT[j][p - 1]
    print(ret)


### FIXED CODE ###

N, M, QN = [int(x) for x in input().split()]

MAT0 = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(M):
    l, r = [int(x) for x in input().split()]
    MAT0[l][r] += 1

MAT = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        MAT[i][j] = MAT[i][j - 1] + MAT0[i][j]

MM = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        MM[i][j] = MM[i - 1][j] + MAT[i][j]

for i in range(QN):
    p, q = [int(x) for x in input().split()]
    ret = 0
    ret = ret + MM[q][q] - MM[q][p - 1] - MM[p - 1][q] + MM[p - 1][p - 1]
    print(ret)
### BUGGY CODE ###


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

PP=P
for i in range(N):
    PP[i]=P[i]*0.5+0.5



ans = float(0)
final = 0
repeat = N-K+1
for j in range(repeat):
    ans = 0
    for i in range(K):
        ans = ans+PP[i+j]
        if final <= ans:
            final = ans
        
print(final)

### FIXED CODE ###

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

wa = float(0)
for i in range(K):
    wa = wa + P[i]

ans = wa 
  
repeat = N-K
for i in range(repeat):
    wa = wa + P[i+K]-P[i]
    if ans <= wa :
        ans = wa
      
print(ans/2+(K*0.5))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
from collections import Counter as co
D=co(A)

cnt=0
for i in range(N):
  if D[A[-1-i]]>0:
    D[A[-1-i]]-=1
    for j in range(1,50):
      d=2**j
      if A[-1-i]<d:
        e=d-A[-1-i]
        break
    if D[e]>0:
      cnt+=1
      D[e]-=1
print(cnt)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
from collections import Counter as co
D=co(A)

cnt=0
for i in range(N):
  if D[A[-1-i]]>0:
    D[A[-1-i]]-=1
    d=A[-1-i]
    f=len(bin(d))-2
    e=2**f-d
    if D[e]>0:
      cnt+=1
      D[e]-=1
print(cnt)
### BUGGY CODE ###

import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    s = list(input())
    q = int(input())
    for i in range(q):
        tfc = list(input().split())
        if tfc[0]=='1':
            s.reverse()
        else:
            t,f,c = tfc
            if f=='1':
                s.insert(0,c)
            else:
                s.append(c)
    print(''.join(s))
    return

if __name__=='__main__':
    main()


### FIXED CODE ###

import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
import collections
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    s = collections.deque(list(input()))
    q = int(input())
    count = 0
    for i in range(q):
        tfc = list(input().split())
        if tfc[0]=='1':
            count = abs(count - 1)
        else:
            t,f,c = tfc
            if count:
                if f=='1':
                    s.append(c)
                else:
                    s.appendleft(c)
            else:
                if f=='1':
                    s.appendleft(c)
                else:
                    s.append(c)
    if count:
        t = []
        for i in range(len(s)):
            t.append(s.pop())
        print(''.join(t))
    else:
        print(''.join(s))
    return

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

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from functools import lru_cache

N,M = II()
A = III()
num = [0]*10
num[1],num[2],num[3],num[4],num[5] = 2,5,5,4,5
num[6],num[7],num[8],num[9] = 6,3,7,6

@lru_cache(maxsize=None)
def rec(n):
    val = []
    for i in range(M):
        if n-num[A[i]] < 0:
            continue
        elif n-num[A[i]] == 0:
            val.append(A[i])
        else:
            if rec(n-num[A[i]])>0:
                val.append(int(str(A[i]) + str(rec(n-num[A[i]]))))
    if val:
        return max(val)
    else:
        return -1

print(rec(N))

### FIXED CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from functools import lru_cache

N,M = II()
A = III()
num = [0]*10
num[1],num[2],num[3],num[4],num[5] = 2,5,5,4,5
num[6],num[7],num[8],num[9] = 6,3,7,6

@lru_cache(maxsize=10**5)
def rec(n):
    val = []
    for i in range(M):
        if n-num[A[i]] < 0:
            continue
        elif n-num[A[i]] == 0:
            val.append(A[i])
        else:
            if rec(n-num[A[i]])>0:
                val.append(10*rec(n-num[A[i]])+A[i])
    if val:
        return max(val)
    else:
        return -1

print(rec(N))
### BUGGY CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


def list_gcd(a):
    a_gcd = a[0]
    for i in range(n-1):
        a_gcd = gcd(a_gcd, a[i+1])
    return a_gcd


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

for i in range((n+1)//2):
    b = a[:]
    b[i] = b[i-1]
    ans = max(ans, list_gcd(b))

print(ans)

### FIXED CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n = int(input())
a = list(map(int, input().split()))
a = [0]+a[:]+[0]

l = [0]*len(a)
r = [0]*len(a)

for i in range(len(a)-1):
    m = len(a)-1
    l[i+1] = gcd(l[i], a[i+1])
    r[m-i-1] = gcd(r[m-i], a[m-i-1])

ans = [0]*n

for i in range(n):
    ans[i] = gcd(l[i], r[i+2])

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

N = int(input())
A = list(map(int, input().split(' ')))
rect_long = 0
rect_small = 0
while A != []:
    long_max = max(A)
    if A.count(long_max) >= 2:
        rect_long += long_max
        A.remove(long_max)
        A.remove(long_max)
        break
    else:
        A.remove(long_max)

while A != []:
    small_max = max(A)
    if A.count(small_max) >= 2:
        rect_small += small_max
        break
    A.remove(small_max)

print(rect_long * rect_small)

### FIXED CODE ###

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

a = sorted(a, reverse=True)

count = 0
edge = []

i = 0
for _ in range(n-1):
    if a[i] == a[i+1]:
        count = count + 1
        edge.append(a[i])
        i = i + 1
        if count == 2:
            break
    i = i + 1

s = edge[0]*edge[1] if count == 2 else 0
print(s)
### BUGGY CODE ###

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort()
#dp = [[0 for _ in range(X+1)] for _ in range(N+1)]
#dp = [[0] * (X+1) for _ in range(N+1)]

#dp[0] = [x for x in range(X+1)]
from collections import defaultdict
dp = [defaultdict(int) for _ in range(N+1)]
dp[0] = [x for x in range(X+1)]

for i, n  in enumerate(numbers):
    for x in range(X+1):
        dp[i+1][x] += dp[i][x % n]
        #dp[i+1][x] = dp[i+1][x] % MOD
        
        dp[i+1][x] += dp[i][x] * i #% MOD
        #dp[i+1][x] = dp[i+1][x] % MOD

print(dp[N][X] % MOD)


### FIXED CODE ###

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort(reverse=True)


dp = {X: 1}

for i, n in enumerate(numbers):
    tmp_dp = {}
    for k, v in dp.items():
        if k < n:
            tmp_dp[k] = (tmp_dp.get(k,0)+v*(N-i))
        else:
            tmp_dp[k]=(tmp_dp.get(k,0)+v*(N-i-1)) 
            tmp_dp[k%n]=(tmp_dp.get(k%n,0)+v) 
    dp = tmp_dp.copy()
        
ans = 0
for k, v in dp.items():
    ans += k *  v

print(ans % MOD)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        # for b in range(a+1, len(L)-1):
            # ct+= bisect.bisect_left(L[b+1:],a_+L[b])
            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        for b in range(a+1, len(L)-1):
            b_in = bisect.bisect_left(L,a_+L[b]) - b -1
            if b_in > 0:
                ct+=b_in

            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        # ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

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

n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    max_num = 0
    g_max = num//gsb0[0] if (gsb0[0] < gsb1[0]) else 0
    for i in range(g_max + 1):
        remain = num - i*gsb0[0]
        s_max = remain//gsb0[1] if (gsb0[1] < gsb1[1]) else 0
        for j in range( s_max + 1 ):
            k = (remain - j*gsb0[1])//gsb0[2] if (gsb0[2] < gsb1[2]) else 0

            tmp = (num - i*gsb0[0] - j*gsb0[1] - k*gsb0[2]) + i*gsb1[0] + j*gsb1[1] + k*gsb1[2]
            max_num = max(max_num, tmp)

    return(max_num)

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

### FIXED CODE ###

n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [num] * (num+1) for _ in range(3+1)]
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v-w)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(4100000)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7
n, k, *ab = map(int, read().split())
m = iter(ab)
AB = zip(m, m)
graph = [[] for _ in range(n + 1)]
cnt = [0] * (n + 1)
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
    cnt[a] += 1
    cnt[b] += 1
ans = 1

mod = 10 ** 9 + 7
kaidan = [1] * (10 ** 5 + 1)
gyaku = [1] * (10 ** 5 + 1)

for i in range(1, 10 ** 5 + 1):
    kaidan[i] = i * kaidan[i - 1] % mod
    gyaku[i] = pow(kaidan[i], mod - 2, mod)


def perm(k, i):
    if i > k:
        return 0
    return kaidan[k] * gyaku[k - i]


def dfs(v, p):
    global ans
    if p == -1:
        ans *= k * perm(k - 1, cnt[v])
        ans %= mod
    else:
        ans *= perm(k - 2, cnt[v] - 1)
        ans %= mod
    for u in graph[v]:
        if u == p:
            continue
        dfs(u, v)


dfs(1, -1)
print(ans)


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, readline().split())


graph = [[] for _ in range(n + 1)]
cnt = [0] * (n + 1)
for _ in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    cnt[a] += 1
    cnt[b] += 1
ans = 1

mod = 10 ** 9 + 7
kaidan = [1] * (10 ** 5 + 1)
gyaku = [1] * (10 ** 5 + 1)

for i in range(1, 10 ** 5 + 1):
    kaidan[i] = i * kaidan[i - 1] % mod
    gyaku[i] = pow(kaidan[i], mod - 2, mod)


def perm(k, i):
    if i > k:
        return 0
    return kaidan[k] * gyaku[k - i]


# dfs

stack = [1]
used = [False] * (n + 1)
while stack:
    v = stack.pop()
    used[v] = True
    if v == 1:
        ans *= k * perm(k - 1, cnt[v])
        ans %= mod
    else:
        ans *= perm(k - 2, cnt[v] - 1)
        ans %= mod
    for u in graph[v]:
        if used[u] == True:
            continue
        stack.append(u)

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

n,k=map(int,input().split())
a=[]
if k==1:
    print(0)
else:
    while True:
        n=abs(n-k)
        a.append(n)
        if a[0]==abs(n-k):
            break
        elif abs(n-k)==0:
            a.append(0)
            break
    print(min(a))

### FIXED CODE ###

n,k=map(int,input().split())
if k==1:
    print(0)
else:
    print(min(n%k,abs(n%k-k)))
### BUGGY CODE ###


from collections import defaultdict
import sys

sys.setrecursionlimit(10**6)


N = int(input())
g = [set() for _ in range(N+1)]

for x, y in [map(int, input().split()) for _ in range(N-1)]:
    g[x].add(y)
    g[y].add(x)

M = 10**9 + 7


def dfs(u, p):
    w = 1
    b = 1
    for v in g[u]:
        if p == v:
            continue
        wn, bn = dfs(v, u)
        w *= wn + bn
        b *= wn
        w %= M
        b %= M
    return w, b
print(sum(dfs(1, -1))%M)


### FIXED CODE ###


from collections import defaultdict
import sys

sys.setrecursionlimit(10**6)


N = int(input())
g = [set() for _ in range(N+1)]

for x, y in [map(int, input().split()) for _ in range(N-1)]:
    g[x].add(y)
    g[y].add(x)

M = 10**9 + 7


def dfs(u, p):
    w = 1
    b = 1
    for v in g[u]:
        if p == v:
            continue
        wn, bn = dfs(v, u)
        w *= wn + bn
        b *= wn
        w %= M
        b %= M
    return w, b
print(sum(dfs(1, -1))%M)
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(i+1):
        if p[i] <= p[j]:
            if i == j:
                cnt += 1
        else:
            break
print(cnt)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for _ in p:  #p[i]よりも小さいものが出てきたらだめ
    if _ <= n:
        cnt += 1
        n = _
print(cnt)
### BUGGY CODE ###

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

count = 0
if 1 in x:
    try:
        for i in range(n):
            while x[i]!=(i+1):
                del x[i]
                count += 1            
        print(count)
    except:
        print(count)
else:
    print(-1)

### FIXED CODE ###

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

count = 0
if 1 in x:
    try:
        j = 0
        for i in range(n):
            while x[j]!=(i+1):
                j = j+1
                count += 1    
            j +=1        
        print(count)
    except:
        print(count)
else:
    print(-1)
### BUGGY CODE ###

import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
z = 2
count = 0
if is_prime(n): exit(print(1))
while True:
    if n%z==0:
        n /= z
        count += 1
    while True:
        z += 1
        t = math.sqrt(z)
        t = prime_factorize(z)
        if is_prime(z) or sum(t)==t[0]*len(t): break
    if n < z: break
print(count)

### FIXED CODE ###

import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr

n = int(input())
pl = factorization(n)
if len(pl) == 0: exit(print(0))
count = 0
for a,b in pl:
    if a==1 and b==1: exit(print(0))
    t=1
    while True:
        if b < t: break
        count += 1
        b-=t
        t+=1
print(count)
### BUGGY CODE ###

import collections


N = int(input())

S = [input() for i in range(N)]

result = collections.Counter(S)

result_max = sorted([i for i in result.keys() if result[i] == max(result.values())])

for r in result_max:
    print(r)

### FIXED CODE ###

import collections


N = int(input())

S = [input() for i in range(N)]

count = collections.Counter(S)


mx = max(count.values())

result = [key for key, val in count.items() if val == mx]
print("\n".join(sorted(result)))