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

S = input()
Q = int(input())
rev = False
for i in range(Q):
    query = input()
    if query == "1":
        T = 1
        rev = not(rev)
    else:
        T,F,C = query.split()
        if rev:
            if F == "1":
                S = S + C
            else:
                S = C + S
        else:
            if F == "1":
                S = C + S
            else:
                S = S + C
if rev:
    print("".join(list(reversed(S))))
else:
    print(S)


### FIXED CODE ###

from collections import deque
S = deque(list(input()))
Q = int(input())
rev = False
for i in range(Q):
    query = input()
    if query == "1":
        rev = not(rev)
    else:
        T,F,C = query.split()
        if rev:
            if F == "1":
                S.append(C)
            else:
                S.appendleft(C)
        else:
            if F == "1":
                S.appendleft(C)
            else:
                S.append(C)
if rev:
    print("".join(list(reversed(S))))
else:
    print("".join(S))
### BUGGY CODE ###

n,Y=map(int, input().split())
a=-1; b=-1; c=-1
for x in range(n+1):
    for y in range(n+1):
        for z in range(n+1):
            if x+y+z==n and 10000*x+5000*y+1000*z==Y:
                a,b,c=[x,y,z]
print(a,b,c)

### FIXED CODE ###

def solve():
    a=-1;b=-1;c=-1
    n,Y=map(int, input().split())
    for x in range(n+1):
        for y in range(n+1):
            if 10000*x+5000*y+1000*(n-x-y)==Y and 0<=n-x-y<=n:
                a,b,c= [x,y,n-x-y]
    return a,b,c

a,b,c=solve()
print(a,b,c)
### BUGGY CODE ###

n=int(input())
p=list( float(s) for s in input().split() )
res=[1-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    res[len(res)-1]=(1-p[i])*res[len(res)-1]
    for j in range(len(res)-2, -1, -1):
        res[j+1]+=(res[j]*p[i])
        res[j]=(res[j]*(1-p[i]))        
print( (1-sum(res[:1+n//2])) )

### FIXED CODE ###

n=int(input())
p=list( float(s) for s in input().split() )
 
res=[1-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    for j in range(len(res)-1, 0, -1):
        res[j]=(res[j]*(1-p[i]) + (res[j-1]*p[i]) )
    res[0]=res[0]*(1-p[i])
print( (1-sum(res[:1+n//2])) )
### BUGGY CODE ###

n, m = map(int, input().split())
if m % n == 0:
    print(m // n)
    exit()
ret = 1
for i in range(1,1+m//n):
    if m % i == 0:
        ret = i
print(ret)

### FIXED CODE ###

n, m = map(int, input().split())
divisors = []
for i in range(1,m+1):
    if i * i > m:
        break
    if i * i == m:
        divisors.append(i)
        break
    if m % i == 0:
        divisors.append(i)
        divisors.append(m // i)
ans = filter(lambda d: d <= m//n, divisors)
print(max(ans))
### BUGGY CODE ###

import numpy as np
from numba import njit

@njit
def main(n,ma,mb,abc):
    inf=10**5
    cost=inf*np.ones((401,401))
    maxa=np.sum(abc,axis=0)[0]
    maxb=np.sum(abc,axis=0)[1]

    left=6*n//8
    right=n
    cnt=right-left

    for i in range(2**cnt):
        ta=0
        tb=0
        tc=0
        for j in range(cnt):
            if (i>>j)&1==1:
                a,b,c=abc[left+j]
                ta+=a
                tb+=b
                tc+=c
        
        cost[ta,tb]=min(cost[ta,tb],tc)
    
    ans=inf

    for i in range(1,401):
        targeta=ma*i
        targetb=mb*i
        if targeta>maxa or targetb>maxb:
            break

        for j in range(2**left):
            ta=0
            tb=0
            tc=0
            for k in range(left):
                if (j>>k)&1==1:
                    a,b,c=abc[k]
                    ta+=a
                    tb+=b
                    tc+=c
        
            ua=targeta-ta
            ub=targetb-tb

            if 0<=ua<=400 and 0<=ub<=400 and cost[ua,ub]!=inf:
                ans=min(ans,tc+cost[ua,ub])
    
    if ans==inf:
        return -1
    else:
        return int(ans)

n,ma,mb=map(int,input().split())
abc=np.array([list(map(int,input().split())) for _ in range(n)])
print(main(n,ma,mb,abc))

### FIXED CODE ###

n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(n)]

wmax=400
inf=10**10
dp=[[[inf]*(wmax+1) for _ in range(wmax+1)] for _ in range(n+1)]
dp[0][0][0]=0

for i in range(n):
    a,b,c=abc[i]
    for j in range(wmax+1):
        for k in range(wmax+1):
            dp[i+1][j][k]=dp[i][j][k]

            if j>=a and k>=b:
                dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j-a][k-b]+c)

ans=inf

for j in range(1,wmax+1):
    for k in range(1,wmax+1):
        if dp[n][j][k]>=inf:
            continue

        if ma*k==mb*j:
            ans=min(ans,dp[n][j][k])

if ans==inf:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

cnt = 0
for i in range(len(S)-3):
	for j in range(i+3, len(S)+1):
		if int(S[i:j])%2019 == 0:
			cnt += 1

print(cnt)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

S = input()
n = len(S)
s = [0]
for i, x in enumerate(S):
	s.append(int(S[i])*pow(10, n-i-1, 2019)%2019)

tmp = 0
t = []
for x in s:
	tmp = (tmp+x)%2019
	t.append(tmp)

ans = 0
for v in Counter(t).values():
	ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

import sys

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

s_len = len(s)
t_len = len(t)
dp = [[[0, ''] for x in range(t_len)] for y in range(s_len)]

for i in range(t_len):
    if s[0] == t[i]:
        dp[0][i][1] = s[0]
        dp[0][i][0] = 1
    else:
        dp[0][i][1] = dp[0][i-1][1] if i != 0 else ''
        dp[0][i][0] = dp[0][i-1][0] if i != 0 else 0


for i in range(s_len):
    if s[i] == t[0]:
        dp[i][0][1] = t[0]
        dp[i][0][0] = 1
    else:
        dp[i][0][1] = dp[i-1][0][1] if i != 0 else ''
        dp[i][0][0] = dp[i-1][0][0] if i != 0 else 0

for i in range(1, s_len):
    for j in range(1, t_len):
        if t[j] == s[i]:
            dp[i][j][1] = dp[i-1][j-1][1] + t[j]
            dp[i][j][0] = dp[i-1][j-1][0] + 1
        else:
            dp[i][j][1] = dp[i-1][j][1] if dp[i-1][j][0] > dp[i][j-1][0] else dp[i][j-1][1]
            dp[i][j][0] = dp[i-1][j][0] if dp[i-1][j][0] > dp[i][j-1][0] else dp[i][j-1][0]

print(dp[s_len-1][t_len-1][1])


### FIXED CODE ###

import sys

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

s_len = len(s)
t_len = len(t)
dp = [[0 for x in range(t_len + 1)] for y in range(s_len + 1)]


for i in range(1, s_len+1):
    for j in range(1, t_len+1):
        if t[j-1] == s[i-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = ''
i = s_len
j = t_len

while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans += s[i - 1]
        i -= 1
        j -= 1

print(ans[::-1])
### BUGGY CODE ###

N=int(input())
A=list(map(str,(input().split())))
Q=int(input())
B=[]
C=[]
for _ in range(Q):
  L, R = map(str,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  A_string = ",".join(A)
  A_new = A_string.replace(B[i],C[i])
  A =  A_new.split(",")
  int_A = [int(n) for n in A]
  print(sum(int_A))

### FIXED CODE ###

import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)
### BUGGY CODE ###

N,K = map(int, input().split())
A=list(map(int, input().split()))  
num=0
for j in range(0,K):
    num += sum(range(1,A[j]+1))/A[j]  
#num = sum(A[0:K])
#ind = 0
#max_num =0
ans = num
for i in range(N-K):
    num -= sum(range(1,A[i]+1))/A[i] 
    num += sum(range(1,A[i+K]+1))/A[i+K] 
    ans = max(num,ans)


print(ans)

### FIXED CODE ###

N,K = map(int, input().split())
A=list(map(int, input().split()))  
 
num = sum(A[0:K])
ind = 0
max_num =0
for i in range(N-K):
    num -= A[i]
    num += A[i+K]
    if num> max_num:
        ind = i+1
        max_num = num
 
ans = 0
for i in range(ind,ind+K):
    ans += (1+A[i])/2
    
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
kouho=[]
def saikorokitaiti(A):
    return ((P[A]*(1+P[A])/2)/P[A])
hako=[]
for i in range(N-K+1):
    for j in range(K):
        hako.append(saikorokitaiti(i+j))
        if j==K-1:
            kouho.append(sum(hako))
            hako=[]

print(max(kouho))

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,K=map(int,input().split())
P=list(map(int,input().split()))
kouho=0
def saikorokitaiti(A):
    return ((P[A]*(1+P[A])/2)/P[A])
kari=[]
hako=[]
kitaiti=0
if K==1:
    print(saikorokitaiti(P.index(max(P))))
    exit()
for i in range(K):
    hako.append(saikorokitaiti(i))
    kitaiti+=saikorokitaiti(i)
    kouho=kitaiti
b=0
for j in range(N-K+1):
    if j==0:
        continue
    elif j+K-1<N:
        hako.append(saikorokitaiti(j+K-1))
        kitaiti+=saikorokitaiti(j+K-1)
        kitaiti-=hako[b]
        b+=1
        kouho=max(kouho,kitaiti)
#print(kouho)
print(kouho)
### BUGGY CODE ###

s = input()

if len(s)<3:
    print(0)
    exit()

i = 0
while True:
    if s[i:i+2]=='BC':
        s=s[:i]+'D'+s[i+2:]
    i+=1
    if i>=len(s):
        break


s1 = s.split('B')
s2 = []
for i in range(len(s1)):
    s2+= s1[i].split('C')


ans = 0

for i in range(len(s2)):
    d = s2[i].count('D')
    for j in range(len(s2[i])):
        if s2[i][j]=='A':
            ans += d
        else:
            d-=1

print(ans)

### FIXED CODE ###

s = input()

if len(s)<3:
    print(0)
    exit()

i = 0
while True:
    if s[i:i+2]=='BC':
        s=s[:i]+'D'+s[i+2:]
    i+=1
    if i>=len(s):
        break


s1 = s.split('B')
s2 = []
for i in range(len(s1)):
    s2+= s1[i].split('C')


ans = 0

for i in range(len(s2)):
    d = s2[i].count('D')
    for j in range(len(s2[i])):
        if s2[i][j]=='A':
            ans += d
        else:
            d-=1
            if d == 0:
                break

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

n = int(input())
a = list(map(int, input().split()))
m = 0
s = []
for i in range(len(a)):
    m += a[i]
    s.append(abs(sum(a) - m * 2))
print(min(s))


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
m = 0
s = []
suma = sum(a)
for i in range(len(a)):
    m += a[i]
    s.append(abs(suma - m * 2))
print(min(s))
### BUGGY CODE ###

I=lambda:map(int,input().split());*_,k=I();s='sorted(i+j for i in I()for j in %s)[:-k-1:-1]';*a,=I();b=eval(s%'a');print(*eval(s%'b'))

### FIXED CODE ###

I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x, y = map(int, input().split())

    if x == y:
        print(-1)
        exit()

    for res in range(x, 10 ** 18, x):
        if res % y:
            print(res)
            break


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x, y = map(int, input().split())

    if x % y == 0:
        print(-1)
        exit()

    for res in range(x, 10 ** 18, x):
        if res % y:
            print(res)
            break


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

n = int(input())
a = tuple(int(x) for x in input().split())

def fac(n, x):
 fact = 1
 for f in range(n, x+1):
  fact *= f
 return fact

def comb(n, r):
 num = fac(1, r)
 dom = fac(n-r+1, n)
 return dom // num

maxi = {}
for i in a:
 for j in a:
  if i <= j: continue
  maxi[i, j] = comb(i, j)

ans = tuple(maxi.keys())[0]
for k, v in maxi.items():
 ans = k if maxi[ans] < v else ans
print(*ans)


### FIXED CODE ###

N = int(input())
a = sorted(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)
### BUGGY CODE ###

n = int(input())
a = [0] * (n+1)
for i in range(n):
    a[i+1] = list(map(int, input().split()))
todo = [0] * (n+1)
days = 0
while True:
    update = []
    for i in range(1, n+1):
        if todo[i] < n - 1 and i not in update:
            p = a[i][todo[i]]
            if a[p][todo[p]] == i:
                update.append(i)
    for j in update:
        todo[j] += 1
    days += 1
    #print(todo)
    if todo[1:] == [n - 1] * n:
        break
    elif update == []:
        days = -1
        break
print(days)

### FIXED CODE ###

n = int(input())
a = []
for _ in range(n+1):
    a.append([-1])
for i in range(n):
    inp = list(map(int, input().split()))
    for j in range(n-2, -1, -1):
        a[i+1].append(inp[j])
matched = [i for i in range(1, n+1)]
finish = 0
days = 0
while True:
    used = set()
    while matched != []:
        i = matched.pop()
        p = a[i][-1]
        if p != -1 and a[p][-1] == i and (i not in used) and (p not in used) :
            a[i].pop()
            a[p].pop()
            used.add(i)
            used.add(p)
            if a[i][-1] == -1:
                finish += 1
            if a[p][-1] == -1:
                finish += 1
    days += 1
    matched = list(used)
    if len(used) == 0:
        days = -1
        break
    elif finish == n:
        break
print(days)
### BUGGY CODE ###

import math
import functools

k = int(input())
k = k+1
ans = 0
for i in range(1,k):
	for j in range(1,k):
		for kk in range(1,k):
			ans += functools.reduce(math.gcd, [i,j,kk])
print(ans)

### FIXED CODE ###

import math

def solve(n):
    n = n+1
    ans = 0
    for i in range(1,n):
        for j in range(1,n):
            tmp = math.gcd(i, j)
            for k in range(1,n):
                ans += math.gcd(tmp, k)
    return ans

def main():
    k = int(input())
    print(solve(k))

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

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

adic=dict()

for ai in a:
    if ai in adic:
        adic[ai]+=1
    else:
        adic[ai]=1
        
#for i in range(1,max(a)+1):
for i in range(1,10**5+1):
    if not i in adic:
        adic[i]=0
        
        
q=int(input())
b=[0]*(q+1)
c=[0]*(q+1)
for i in range(q):
    bi,ci=map(int,input().split())
    b[i]=bi
    c[i]=ci
    
#print(adic)    
for i in range(q):
    adic[c[i]]=adic[c[i]]+adic[b[i]]
    adic[b[i]]=0
#    print(i,adic)
    asum=0
    for i,ad in adic.items():
#    for i in range(1,10**5+1):
#        asum+=a[i]*adic[a[i]]
#        asum+=i*adic[i]
        asum+=i*ad
    print(asum)

### FIXED CODE ###

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

adic=dict()

for ai in a:
    if ai in adic:
        adic[ai]+=1
    else:
        adic[ai]=1
        
q=int(input())
b=[0]*(q)
c=[0]*(q)
bc=[[0]*2 for i in range(q)]
for i in range(q):
    bc[i]=map(int,input().split())
    
asum=0
for i,ad in adic.items():
    asum+=i*ad
    
#print(adic)    
for bi,ci in bc:
    if bi in adic and ci in adic:
        asum-=bi*adic[bi]
        adic[ci]=adic[ci]+adic[bi]
        asum+=ci*adic[bi]
        del adic[bi]
    elif bi in adic and (not ci in adic):
        asum-=bi*adic[bi]
        adic[ci]=adic[bi]
        asum+=ci*adic[bi]
        del adic[bi]
#    print(i,adic)
    print(asum)
### BUGGY CODE ###

# countBcd[i] : 最大公約数がiとなる数列の個数
# 全てiの倍数である数列の数はint(K/i) ** N ただし、全てi*2,i*3・・・の場合を除く

N, K = [int(x) for x in input().split()]
countBcd = [0]*(K+1)
mod=10**9+7
sumTotal=0
for i in range(K,0,-1):
    countBcd[i] = int(K/i) ** N

    for j in range(i*2,K+1,i):
        countBcd[i] += mod - countBcd[j]
        countBcd[i] %= mod

    sumTotal += i*countBcd[i]
    sumTotal %= mod

print(sumTotal)


### FIXED CODE ###

# countBcd[i] : 最大公約数がiとなる数列の個数
# 全てiの倍数である数列の数はint(K/i) ** N ただし、全てi*2,i*3・・・の場合を除く

N, K = [int(x) for x in input().split()]
countBcd = [0]*(K+1)
mod=10**9+7
sumTotal=0
for i in range(K,0,-1):
    countBcd[i] = pow(K//i,N,mod)

    for j in range(i*2,K+1,i):
        countBcd[i] -= countBcd[j]

    sumTotal += i*countBcd[i]%mod

print(sumTotal%mod)
### BUGGY CODE ###

from collections import defaultdict
from collections import deque
n,q = map(int,input().split())
d = defaultdict(list)
dp = defaultdict(int)
ep = [0] * n
for i in range(n-1):
    ta,tb = map(int,input().split())
    d[ta-1].append(tb-1)
    d[tb-1].append(ta-1)
for i in range(q):
    ta,tb = map(int,input().split())
    dp[ta-1] +=tb
ep[0]+=1
l = deque()
l.append(0)
while l:
    t = l.pop()
    for i in d[t]:
        if ep[i] == 0:
            dp[i] += dp[t]
            ep[i]+=1
            l.append(i)
ans = []
for i in dp:
    ans.append(dp[i])
print(*ans)

### FIXED CODE ###

from collections import defaultdict
from collections import deque
n,q = map(int,input().split())
d = defaultdict(list)
dp = [0] * n
ep = [0] * n
for i in range(n-1):
    ta,tb = map(int,input().split())
    d[ta-1].append(tb-1)
    d[tb-1].append(ta-1)
for i in range(q):
    ta,tb = map(int,input().split())
    dp[ta-1] +=tb
ep[0]+=1
l = deque()
l.append(0)
used = [False] * n
while l:
    t = l.pop()
    used[t] = True
    for i in d[t]:
        if not used[i]:
            dp[i] += dp[t]
            l.append(i)
print(*dp)
### BUGGY CODE ###

n, m = map(int, input().split())
gate = []
for i in range(m):
    l, r = map(int, input().split())
    gate.append({j for j in range(l, r + 1)})
ID = gate[0]
for i in range(1, m):
    ID = ID & gate[i]
print(len(ID))

### FIXED CODE ###

n, m = map(int, input().split())
gate = []
l, r = map(int, input().split())
for i in range(1, m):
    m, s = map(int, input().split())
    if l < m:
        l = m
    if s < r:
        r = s
print(len([i for i in range(l, r + 1)]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


def warshall_floyd(g):
    d = defaultdict(dict)
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    for i in V:
        for j in V:
            if i in g and j in g[i]:
                d[i][j] = g[i][j]
            else:
                d[i][j] = INF
    for k in g:
        for i in g:
            for j in g:
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    g[i][j] = 0

    return d


@mt
def slv(N, A):
    ca = Counter(A)

    @lru_cache(maxsize=None)
    def f(c1, c2, c3):
        if min(c1, c2, c3) < 0:
            return 0
        if c1 == c2 == c3 == 0:
            return 0

        c0 = N - (c1 + c2 + c3)
        p0 = c0 / N
        p1 = c1 / N
        p2 = c2 / N
        p3 = c3 / N
        ip0 = 1 - p0
        ret = 1 / ip0
        ret += f(c1-1, c2, c3) * p1 / ip0
        ret += f(c1+1, c2-1, c3) * p2 / ip0
        ret += f(c1, c2+1, c3-1) * p3 / ip0
        return ret
    return f(ca[1], ca[2], ca[3])



def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.buffer.readline


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def f(c1, c2, c3):
    if memo[c1][c2][c3] != -1:
        return memo[c1][c2][c3]
    c0 = N - (c1 + c2 + c3)
    p0 = c0 / N
    ip0 = 1 - p0
    ret = 1 / ip0
    if c1 > 0:
        p1 = c1 / N
        ret += f(c1-1, c2, c3) * p1 / ip0
    if c2 > 0:
        p2 = c2 / N
        ret += f(c1+1, c2-1, c3) * p2 / ip0
    if c3 > 0:
        p3 = c3 / N
        ret += f(c1, c2+1, c3-1) * p3 / ip0
    memo[c1][c2][c3] = ret
    return ret


N = read_int()
A = read_int_n()
memo = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
memo[0][0][0] = 0
print(f(A.count(1), A.count(2), A.count(3)))
### BUGGY CODE ###

def main():
    N = int(input())
    P = list(map(int,input().split()))
    cnt = 1
    for i in range(1, N):
        # Pi
        # P[0:i]
        Q = P[0:i]
        if P[i] > min(P[0:i]):
            cnt = cnt
        else:
            cnt += 1

        #Q = [ _ for _ in P[0:i] if P[i] <= _ ]  # TLE
        #for _ in P[0:i+1]:
        #    print(_)
        #if len(Q) == i:
        #    cnt += 1
    print(cnt)

main()

### FIXED CODE ###

def main():
    N = int(input())
    P = list(map(int,input().split()))
    cnt = 0
    Q = max(P)
    for i in range(N):
        if Q >= P[i]:
            cnt += 1
            Q = P[i]
    print(cnt)

main()