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

a,b,c=map(int, input().split())
count=0

while(True):
    if c>0:
        if b>0:
            c-=1
            b-=1
            count+=2
        else:
            if a>0:
                c-=1
                a-=1
                count+=1
            else:
                c-=1
                count+=1
                break
    else:
        count+=b
        break
print(count)

### FIXED CODE ###

a,b,c=map(int, input().split())
count=0

if c>=b:
    count+=2*b
    c=c-b
    if c>a:
        count+=a
        c=c-a
        if c>0:
            count+=1
    else:
        count+=c
else:
    count+=c+b

print(count)
### BUGGY CODE ###

from sys import stdin

n, d, a = (int(v) for v in stdin.readline().split())
monsters = [(int(v) for v in stdin.readline().split()) for i in range(n)]

monsters = [[x, (h // a + 1) if h % a > 0 else (h // a)] for x, h in monsters]
monsters = sorted(monsters)
bomb_size = 2 * d + 1
num_bombs = 0

ptr = 0
while ptr < len(monsters):
    while ptr < len(monsters) and monsters[ptr][1] <= 0:
        ptr += 1
    if ptr < len(monsters):
        position = monsters[ptr][0]
        bombs_now = monsters[ptr][1]
        i = ptr
        while i < len(monsters) and monsters[i][0] - position < bomb_size:
            monsters[i][1] -= bombs_now
            i += 1
        num_bombs += bombs_now

print(num_bombs)


### FIXED CODE ###

from sys import stdin
from collections import deque

n, d, a = (int(v) for v in stdin.readline().split())
monsters = [(int(v) for v in line.split()) for line in stdin.readlines()]

monsters = [[x, (h // a + 1) if h % a > 0 else (h // a)] for x, h in monsters]
monsters = sorted(monsters)
bomb_size = 2 * d + 1
num_bombs = 0

current_bombs = 0
bomb_endpoints = deque()
bomb_endnumbers = deque()

for i in range(len(monsters)):
    while len(bomb_endpoints) > 0 and bomb_endpoints[0] <= monsters[i][0]:
        current_bombs -= bomb_endnumbers[0]
        bomb_endpoints.popleft()
        bomb_endnumbers.popleft()
    monsters[i][1] -= current_bombs
    if monsters[i][1] > 0:        
        bombs_now = monsters[i][1]
        monsters[i][1] = 0
        num_bombs += bombs_now
        current_bombs += bombs_now
        bomb_endpoints.append(monsters[i][0] + bomb_size)
        bomb_endnumbers.append(bombs_now)

print(num_bombs)
### BUGGY CODE ###

# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


def replacement(orig, b, c):
    if orig == b:
        return c
    else:
        return orig


for bc in BC:
    b, c = bc
    A = [replacement(a, b, c) for a in A]
    print(sum(A))


### FIXED CODE ###

# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


array = [0]*(10**5+1)
total = sum(A)

for a in A:
    array[a] += 1

for bc in BC:
    b, c = bc
    total += c*array[b]-b*array[b]
    array[c] += array[b]
    array[b] = 0
    print(total)
### BUGGY CODE ###

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
T = lr()
A = lr()
MOD = 10 ** 9 + 7

T_spe = [T[0]] + [0] * (N-1)
A_spe = [0] * (N-1) + [A[-1]]

for i in range(1, N):
    if T[i] > T[i-1]:
        T_spe[i] = T[i]

for i in range(N-2, -1, -1):
    if A[i] > A[i+1]:
        A_spe[i] = A[i]

answer = 1
for i in range(N):
    if T_spe[i] > A[i] or A_spe[i] > T[i]:
        print(0)
        exit()
    if T_spe[i] == 0 and A_spe[i] == 0:
        answer *= min(T[i], A[i])

print(answer%MOD)
# 34


### FIXED CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
T = np.array(lr()).astype('int64')
A = np.array(lr()).astype('int64')
MOD = 10 ** 9 + 7

T_low = T.copy()
T_low[1:][T[1:] <= T[:-1]] = 1
A_low = A.copy()
A_low[:-1][A[:-1] <= A[1:]] = 1

lower = np.maximum(T_low, A_low)
upper = np.minimum(T, A)
domain = np.maximum(0, upper - lower + 1) #変域が0の時は記録が間違い
L = len(domain); LSQ = int(L**.5 + 1)
domain = np.resize(domain, LSQ**2) #行列の形に無理やりする下準備（1次元）
domain[L:] = 1 #後半は全部1
domain = domain.reshape((LSQ, LSQ))
for n in range(1, LSQ):
    domain[:, n] *= domain[:, n-1]; domain[:, n] %= MOD
for n in range(1, LSQ):
    domain[n] *= domain[n-1, -1]; domain[n] %= MOD
answer = domain[-1, -1]
print(answer)
### BUGGY CODE ###



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

result=0
LR=[]
for i in range(M):
        LR.append(input().split())



for i in range(N+1):#0からNまで
    counter=0
    for j in LR:#['1','1']
        #print(j)

        L=int(j[0])
        R=int(j[1])

        if L<=i and i<=R:
            counter+=1
    if counter==M:
        result+=1
print(result)


### FIXED CODE ###


N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)
### BUGGY CODE ###

import math
from collections import defaultdict

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


def left_right(x, d):
    left = x - d - 0.5
    right = x + d + 0.5
    return left, right


printed_lst = []
for x in range(K):
    dic = defaultdict(int)
    for i in range(N):
        l, r = left_right(i + 1, al[i])
        left = math.ceil(l)
        if left <= 0:
            left = 1
        right = math.floor(r)
        for n in range(left, right + 1):
            dic[n] += 1
    al = list(dic.values())[:N]
    #print(al)
    if al in printed_lst:
        print(' '.join([str(i) for i in al]))
        #print('end')
        exit()
    else:
        printed_lst.append(al)


print(' '.join([str(i) for i in al]))


### FIXED CODE ###

import math
from itertools import accumulate

N, K = map(int, input().split())
al = list(map(int, input().split()))
syusoku = [N] * N

for _ in range(K):
    s = [0] * N
    for i in range(N):
        left = i - al[i]
        right = i + al[i]
        if left < 0:
            left = 0
        s[left] += 1
        if right + 1 <= N - 1:
            s[right + 1] -= 1
        # print(left,right)
    al = list(accumulate(s))
    # print(al)
    if al == syusoku:
        print(*al)
        #print('end')
        exit()

print(*al)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7


def extgcd(a,b):
    a0,b0=a,b
    x0,y0=1,0
    x1,y1=0,1

    while b0!=0:
        q = a0 // b0
        r = a0 % b0

        a0,b0=b0,r
        x0,x1=x1,x0-q*x1
        y0,y1=y1,y0-q*y1

    return a0,x0,y0

def mo(x,mod):
    return (mod+x%mod)%mod

def inv(a,mod):
    g,x,y=extgcd(a,mod)
    ans=mo(x,mod)
    return ans

def combi_mod(n,k):
    invlist = [1]
    for i in range(1, k + 1):
        temp = inv(i, mod)
        invlist.append(temp)
    k1 = 1
    k3 = 1

    for i in range(n, 0, -1):

        if i > n - k:
            k1 *= i
        if i < k + 1:
            k3 *= invlist[i]
    ans = k1 * k3
    ans = ans % mod
    return ans

A.sort()

ans=0

for i in range(K-1,N):
    temp=A[i]*combi_mod(i,K-1)
    ans+=temp
    ans=ans%mod

for i in range(N-K+1):
    temp=A[i]*combi_mod(N-i-1,K-1)
    ans-=temp
    ans=ans%mod

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

fac=[]
finv=[]
inv=[]
def combi_init():
    fac.append(1)
    fac.append(1)
    finv.append(1)
    finv.append(1)
    inv.append(1)
    inv.append(1)

    for i in range(2,N+1):
        fac.append(fac[i-1]*i%mod)
        inv.append(mod-mod//i*inv[mod%i]%mod)
        finv.append(finv[i-1]*inv[i]%mod)

def combi_mod(n,k):

    ret=fac[n]*finv[n-k]*finv[k]%mod
    return ret

A.sort()

ans=0
combi_init()
for i in range(N-1,K-2,-1):
    ans+=(A[i]-A[(N-1)-i])*combi_mod(i,K-1)


ans%=mod

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

N,M=map(int,input().split())
d={}
PY=[]
for _ in range(M):
    p,y=map(int,input().split())
    PY.append((p,y))
    d[p]=d.get(p, [])+[y]

dx={}
for k, v in d.items():
    sv=sorted(v)
    for i in range(len(sv)):
        dx[(k,sv[i])]=i+1
        
for p,y in PY:
    print(str(p).zfill(6)+str(dx[(p,y)]).zfill(6))

### FIXED CODE ###

N,M=map(int,input().split())
d={}
PY=[]
import bisect
for _ in range(M):
    p,y=map(int,input().split())
    PY.append((p,y))
    t=d.get(p, [0])
    i=bisect.bisect_left(t,y)
    t.insert(i,y)
    d[p]=t
    
dx={}
for k, v in d.items():
    for i in range(len(v)):
        dx[(k,v[i])]=i
        
for p,y in PY:
    print(str(p).zfill(6)+str(dx[(p,y)]).zfill(6))
### BUGGY CODE ###

from collections import deque

H,W=map(int,input().split())
d={}
for i in range(H):    
    for j,c in enumerate(input()):
        d[(i,j)]=0 if c=='#' else -1
q=deque()
for s in d:
    if not d[s]:
        q.append(s)
while q:
    u=q.popleft()
    ui,uj=u
    for v in [(ui-1,uj),(ui+1,uj),(ui,uj-1),(ui,uj+1)]:
        vi,vj=v
        if 0<=vi<=H-1 and 0<=vj<=W-1 and d[v]==-1:
            d[v]=d[u]+1
            q.append(v)
print(max(d.values()))

### FIXED CODE ###

from collections import deque

class Grid():
    def __init__(self,i,j,isblack):
        self.i=i
        self.j=j
        self.isblack=isblack
        self.distance=0

H,W=map(int,input().split())

g=[]
for i in range(H):
    Ai=input()
    gi=[]    
    for j in range(W):
        gi.append(Grid(i,j,Ai[j]=='#'))
    g.append(gi)

d=deque()

# 黒マスのreachedをTrueにし，dequeに入れる
for row in g:
    for grid in row:
        if grid.isblack:
            d.append(grid)

while d:
    tg=d.popleft()
    i=tg.i
    j=tg.j
    if i>0 and not g[i-1][j].isblack:
        g[i-1][j].isblack=True
        g[i-1][j].distance=tg.distance+1
        d.append(g[i-1][j])
    if i<H-1 and not g[i+1][j].isblack:
        g[i+1][j].isblack=True
        g[i+1][j].distance=tg.distance+1
        d.append(g[i+1][j])
    if j>0 and not g[i][j-1].isblack:
        g[i][j-1].isblack=True
        g[i][j-1].distance=tg.distance+1
        d.append(g[i][j-1])
    if j<W-1 and not g[i][j+1].isblack:
        g[i][j+1].isblack=True
        g[i][j+1].distance=tg.distance+1
        d.append(g[i][j+1])

'''
for row in g:
    for grid in row:
#        print(grid.distance,end=' ')
#    print()
'''

print(max([max([grid.distance for grid in row]) for row in g]))
### BUGGY CODE ###

from collections import deque
import sys

sys.setrecursionlimit(10**9)

h, w = map(int,input().split())
ch, cw = map(int,input().split())
dh, dw = map(int,input().split())

G = []
for i in range(h):
    G.append(list(input()))

queue = deque([(ch-1, cw-1)])
S = [[float("inf")]*w for _ in range(h)]
S[ch-1][cw-1] = 0

while queue:
    y, x = queue.popleft()
    dx_dy = [(1,0),(0,1),(-1,0),(0,-1)]
    for j, i in dx_dy:
        if 0 <= x+i < w and 0 <= y+j < h:
            if S[y+j][x+i] > S[y][x] and G[y+j][x+i] == ".":
                S[y+j][x+i] = S[y][x]
                queue.appendleft((y+j, x+i))
    magic = ((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2))
    for j, i in magic:
            if 0 <= x+i < w and 0 <= y+j < h:
                if S[y+j][x+i] > S[y][x] and G[y+j][x+i] == ".":
                    S[y+j][x+i] = S[y][x] + 1
                    queue.append((y+j, x+i))


if S[dh-1][dw-1] == float("inf"):
    print(-1)
else:
    print(S[dh-1][dw-1])


### FIXED CODE ###

from collections import deque


h, w = map(int,input().split())
ch, cw = map(lambda x: int(x) - 1, input().split())
dh, dw = map(lambda x: int(x) - 1, input().split())

G = []
for i in range(h):
    G.append(list(input()))

queue = deque([(ch, cw)])
S = [[float("inf")]*w for _ in range(h)]
S[ch][cw] = 0

while queue:
    y, x = queue.popleft()
    dx_dy = ((1,0),(0,1),(-1,0),(0,-1))
    ans = S[y][x]

    if (y, x) == (dh, dw):
            S[y][x] = ans
            break

    for j, i in dx_dy:
        if 0 <= x+i < w and 0 <= y+j < h and S[y+j][x+i] > ans and G[y+j][x+i] == ".":
            queue.appendleft((y+j, x+i))
            S[y+j][x+i] = ans
            

    ans += 1
    for i in range(-2, 3):
        for j in range(-2, 3):
            if 0 <= x+i < w and 0 <= y+j < h and S[y+j][x+i] > ans and G[y+j][x+i] == ".":
                S[y+j][x+i] = ans
                queue.append((y+j, x+i))


if S[dh][dw] == float("inf"):
    print(-1)
else:
    print(S[dh][dw])
### BUGGY CODE ###

[n, m] = [int(num) for num in input().split()];
a = [];
b = [];
for i in range(m):
	[t1, t2] = [int(num) for num in input().split()];
	a.append(t1);
	b.append(t2);
	
start = [];
end = [];
for i in range(m):
	if a[i] == 1:
		start.append(b[i]);
	if b[i] == n:
		end.append(a[i]);

flag = False;		
for i in range(1, n + 1):
	if (i in start) & (i in end):
		flag = True;
		
if (flag):
	print('POSSIBLE');
else:
	print('IMPOSSIBLE');

### FIXED CODE ###

[n, m] = [int(num) for num in input().split()];
a = [];
b = [];

for i in range(m):
	[t1, t2] = [int(num) for num in input().split()];
	a.append(t1);
	b.append(t2);

start = [];
end = [];
for i in range(n):
	start.append(False);
	end.append(False);
	
for i in range(m):
	if a[i] == 1:
		start[b[i]] = True;
	elif b[i] == n:
		end[a[i]] = True;
		
flag = False;
for i in range(n):
	if start[i] & end[i]:
		flag = True;
		
if flag:
	print('POSSIBLE');
else:
	print('IMPOSSIBLE');
### BUGGY CODE ###

n,q = map(int,input().split())
s = str(input())
for i in range(q):
    a,b = map(int,input().split())
    S = s[a-1:b]
    print(S.count("AC"))

### FIXED CODE ###

from itertools import *
n,q = map(int,input().split())
s = str(input())
k = [ 1 if s[i-1] == "A" and s[i] == "C" else 0  for i in range(n)]
cumsum = list(accumulate(k))
#print(k)
#print(cumsum)
for i in range(q):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    #print(k[a:b+1])
    ans = cumsum[b] - cumsum[a]
    """
    if k[a] == 1:
        ans -= 1
    """
    print(ans)
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
B = LI()
ANS = []
def dfs(C, D):
    global ANS
    if len(D) == 0:
        ANS = reversed(C)
    for i, d in enumerate(D):
        if i+1 == d:
            if i == len(D)-1:
                dfs(C+[d], D[:i])
            else:
                dfs(C+[d], D[:i]+D[i+1:])
dfs([], B)
if not ANS:
    print(-1)
    exit()
for ans in ANS:
    print(ans)


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())

# ----------------------------------------------------------- #

n = I()
B = LI()

ANS = []
for _ in range(n):
    for i in reversed(range(len(B))):
        if i+1 == B[i]:
            ANS.append(B.pop(i))
            break
    else:
        print(-1)
        exit()

ANS.reverse()
for ans in ANS:
    print(ans)
### BUGGY CODE ###

n,d,a=map(int,input().split())
s=sorted([list(map(int,input().split()))+[1]for i in range(n)])
c=0
for i in range(n):
    if s[i][2]:
        s[i][2]=0
        t=((s[i][1]-1)//a+1)
        c+=t
        for j in range(i+1,n):
            if s[j][0]<=s[i][0]+2*d:
                s[j][1]-=t*a
                if s[j][1]<=0:
                    s[j][2]=1
print(c)

### FIXED CODE ###

from bisect import bisect_left as bl
n,d,a=map(int,input().split())
s=sorted([list(map(int,input().split()))for i in range(n)])
c=0
p=[0]
q=[0]
for i in range(n):
    g=bl(q,s[i][0])
    s[i][1]-=a*(p[-1]-p[g-1])
    if s[i][1]>0:
        t=((s[i][1]-1)//a+1)
        c+=t
        p.append(p[-1]+t)
        q.append(s[i][0]+2*d)
print(c)
### BUGGY CODE ###

s = list(input())
n = int(input())
q = [list(map(str, input().split())) for _ in range(n)]

c = 0
for i in range(n):
    if q[i][0] == "1":
        c += 1
    if q[i][0] == "2":
        if q[i][1] == "1" and c % 2 == 0 or q[i][1] == "2" and c % 2 == 1:
            s.insert(0, q[i][2])
        elif q[i][1] == "2" and c % 2 == 0 or q[i][1] == "1" and c % 2 == 1 :
            s.append(q[i][2])

if c % 2 == 1:
    s = s[::-1] 

print("".join(s))


### FIXED CODE ###

from collections import deque

d = deque(input())
q = int(input())

reverse = False

for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if query[1] == '1':
            if reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if reverse:
    d = list(reversed(d))


print("".join(map(str, d)))
### BUGGY CODE ###

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())
	A[i] -= 1
	B[i] -= 1
inf = 123456789123456789123456789
dist = [ -inf ] * N
dist[0] = 0
bounded = True
for i in range(2 * N):
	for j in range(M):
		if dist[B[j]] < dist[A[j]] + C[j]:
			dist[B[j]] = dist[A[j]] + C[j]
			if B[j] == N - 1 and i >= N:
				bounded = False
if not bounded:
	print("inf")
else:
	print(dist[N - 1])

### FIXED CODE ###

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())
	A[i] -= 1
	B[i] -= 1
inf = 123456789123456789123456789
dist = [ -inf ] * N
dist[0] = 0
bounded = True
for i in range(max(2 * N - 3, 4)):
	for j in range(M):
		if dist[B[j]] < dist[A[j]] + C[j]:
			dist[B[j]] = dist[A[j]] + C[j]
			if B[j] == N - 1 and i >= N:
				bounded = False
if not bounded:
	print("inf")
else:
	print(dist[N - 1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  a.pop(0)
  a.pop(-1)
  ans+=a.pop(-1)
print(ans)

### FIXED CODE ###

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

#!/usr/bin/env python3

(R, C, K), *D = [[*map(int,o.split())] for o in open(0)]
D = {(r - 1, c - 1) : v for r, c, v in D}

dp = [[[-1] * 4 for _ in [0] * C] for _ in [0] * R]

dp[0][0][0] = 0
for r in range(R):
    for c in range(C):
        v = D.get((r, c), None)
        for i in range(4):
            if dp[r][c][i] > -1:
                if r < R - 1:
                    dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][i])
                if c < C - 1:
                    dp[r][c + 1][i] = max(dp[r][c + 1][i], dp[r][c][i])
                if i < 3 and v:
                    if r < R - 1:
                        dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][i] + v)
                    if c < C - 1:
                        dp[r][c + 1][i + 1] = max(dp[r][c + 1][i + 1], dp[r][c][i] + v)
#for l in dp:print(l)
for i in range(3):
    dp[R - 1][C - 1][i] += D.get((R - 1, C - 1), 0)
print(max(dp[R - 1][C - 1]))

### FIXED CODE ###

import sys

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(C)] for r in range(R)] for i in range(4)]
    DP[0][0][0] = 0
    for r in range(R):
        for c in range(C):
            for i in range(4):
                if DP[i][r][c] > -1:
                    if r + 1 < R: 
                        DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c])
                    if c + 1 < C: 
                        DP[i][r][c+1] = max(DP[i][r][c+1], DP[i][r][c])
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c] + item[r][c])
                        if c + 1 < C: DP[i+1][r][c+1] = max(DP[i+1][r][c+1], DP[i][r][c] + item[r][c])

    ans = DP[3][R-1][C-1]
    for i in range(3): ans = max(ans, DP[i][R-1][C-1] + item[R-1][C-1])
    print(ans)
    return 0

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

h, w = map(int, input().split())

a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]

c = [[abs(a[i][j] - b[i][j]) for j in range(w)] for i in range(h)]


def div(s):
    s.sort(reversed=True)
    a = []
    b = []
    total_a = 0
    total_b = 0
    for v in a:
        if total_a < total_b:
            total_a += v
            a.append(v)
        else:
            total_b += v
            b.append(v)
    return (a, b)


sets = [[set() for j in range(w)] for i in range(h)]
sets[0][0].add(c[0][0])
for i in range(1, h):
    for e in sets[i-1][0]:
        sets[i][0].add(e + c[i][0])
        sets[i][0].add(abs(e - c[i][0]))
for i in range(1, w):
    new_set = set()
    for e in sets[0][i-1]:
        sets[0][i].add(e+c[0][i])
        sets[0][i].add(abs(e-c[0][i]))

for i in range(1, h):
    for j in range(1, w):
        for e in sets[i-1][j]:
            sets[i][j].add(e+c[i][j])
            sets[i][j].add(abs(e-c[i][j]))
        for e in sets[i][j-1]:
            sets[i][j].add(e+c[i][j])
            sets[i][j].add(abs(e-c[i][j]))
print(min(sets[h-1][w-1]))


### FIXED CODE ###

h, w = map(int, input().split())

a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]

c = [[abs(a[i][j] - b[i][j]) for j in range(w)] for i in range(h)]
mask = (1 << (h+w) * 80) - 1
sets = [[0 for j in range(w)] for i in range(h)]
sets[0][0] = (1 << 80+c[0][0]) | (1 << 80-c[0][0])
for i in range(1, h):
    sets[i][0] |= (sets[i - 1][0] << 80 + c[i][0]
                   ) | (sets[i - 1][0] << 80 - c[i][0])
for i in range(1, w):
    sets[0][i] |= (sets[0][i-1] << 80 + c[0][i]
                   ) | (sets[0][i-1] << 80 - c[0][i])
for i in range(1, h):
    for j in range(1, w):
        sets[i][j] |= (sets[i - 1][j] << 80 + c[i][j]
                       ) | (sets[i - 1][j] << 80 - c[i][j])
        sets[i][j] |= (sets[i][j-1] << 80 + c[i][j]
                       ) | (sets[i][j - 1] << 80 - c[i][j])
    sets[i][j] &= mask

s = bin(sets[h - 1][w - 1] + (1 << (h + w) * 80))
min_v = 1 << 80
for i in range(len(s)):
    if s[-1-i] == '1':
        min_v = min(min_v, abs(i - (h + w) * 80 + 80))
print(min_v)
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
plist = []
for i in range(n):
  plist.append(p[:i + 1])
count = 0
minn = n
for j in range(n):
  for k in plist[j]:
    if minn >= k:
      minn = k  
  if minn >= p[j]:
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
minn = n
for j in range(len(p)):
  if minn >= p[j]:
    minn = p[j]
    count += 1
print(count)