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

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

counter = 1

for i in range(2, len(P) + 1, 1):
    sl = slice(i)
    if min(P[sl]) >= P[i-1]:
        counter += 1
    else:
        pass

# for i in range(2, len(P) + 1, 1):
#     sl = slice(i)
#     # print(P[sl])
#     # print(P[i-1])
#     if all(elem >= P[i-1] for elem in P[sl]):
#         counter += 1

print(counter)


### FIXED CODE ###

N = int(input())

nums = input().split()
nums = [int(x) for x in nums]

min = None
count = 0

for idx, num in enumerate(nums):
    if idx == 0:
        min = num
        count += 1
        continue

    if min >= num:
        count += 1
        min = num

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

from sys import stdin
readline = stdin.readline

R, C, K = map(int, readline().split())

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

dp = [[[0] * 4 for _ in range(C + 1)] for _ in range(R + 1)]
for i in range(R):
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + goods[i][j])
        for k in range(4):
            dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])

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


### FIXED CODE ###

from sys import stdin
readline = stdin.readline

R, C, K = map(int, readline().split())

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

n = [0] * (C + 1)
for i in range(R):
    c = [0] * 4
    c[0] = n[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
        for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
        if n[j + 1] > c[0]:
            c[0] = n[j + 1]

print(max(c))
### BUGGY CODE ###

# https://abc096.contest.atcoder.jp/tasks/abc096_d

import itertools


def is_prime(n):
    if n < 2: return False
    if n == 2: return True
    if n % 2 == 0: return False

    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1

    return True


N = int(input())


l = []

n = 2
while len(l) < N * 10:
    if is_prime(n):
        l.append(n)
    n += 1


for a in itertools.combinations(l, N):
    if 17 in a:
        continue
    # print(a)
    is_ok = True
    for c in itertools.combinations(a, 5):
        if is_prime(sum(c)):
            # print(str(c) + ' is prime = ' + str(sum(c)))
            is_ok = False
            break
    if is_ok:
        print(' '.join(map(str, a)))
        break



### FIXED CODE ###


def is_prime(n):
    if n < 2: return False
    if n == 2: return True
    if n % 2 == 0: return False

    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1

    return True


N = int(input())


l = []

n = 2
while len(l) < N:
    if is_prime(n) and n % 5 == 1:
        l.append(n)
    n += 1

print(' '.join(map(str, l)))
### BUGGY CODE ###

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

# In[23]:


import math
import itertools


# In[25]:


N = int(input())


# In[26]:


for i in range(1,N+1):
#     print("f(%s)"%i)
    ans = 0
    for x in range(1,int(math.sqrt(i))+1):
        if i - x**2 - x > 0:
            for y in range(x,int(math.sqrt(i-x**2-x))+1):
                if i - x**2 - x - y**2 - y - x*y > 0:
                    for z in range(y,int(math.sqrt(i-x**2-x-y**2-y-x*y)+1)):
                        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                            if x==y and y==z:
                                ans += 1
                            elif x==y:
                                ans += 3
                            elif y==z:
                                ans += 3
                            else:
                                ans += 6
    print(ans)


# In[ ]:






### FIXED CODE ###

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

# In[23]:


import math
import itertools


# In[27]:


N = int(input())


# In[28]:


for i in range(1,N+1):
#     print("f(%s)"%i)
    ans = 0
    for x in range(1,int(math.sqrt(i))+1):
        if i - x**2 - x > 0:
            for y in range(x,int(math.sqrt(i-x**2-x))+1):
                if i - x**2 - x - y**2 - y - x*y > 0:
                    for z in range(y,int(math.sqrt(i-x**2-x-y**2-y-x*y)+1)):
                        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                            if x==y and y==z:
                                ans += 1
                            elif x==y:
                                ans += 3
                            elif y==z:
                                ans += 3
                            else:
                                ans += 6
    print(ans)


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




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

# https://qiita.com/drken/items/03c7db44ccd27820ea0d#f-問題---lcs
S = input().rstrip()
T = input().rstrip()

X = len(S) + 100
dp = [ [0 for _ in range(X)] for _ in range(X) ]

# DP作成
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)

        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

# 復元
ans = ""
i = len(S)
j = len(T)
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]+ans
        i -= 1
        j -= 1

print(ans)

### FIXED CODE ###




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

# https://qiita.com/drken/items/03c7db44ccd27820ea0d#f-問題---lcs
S = input().rstrip()
T = input().rstrip()

X = len(S) + 100
dp = [ [0 for _ in range(X)] for _ in range(X) ]

# DP作成
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)

        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

# 復元
ans = ""
i = len(S)
j = len(T)
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]+ans
        i -= 1
        j -= 1

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

from copy import deepcopy

h, w = map(int, input().split())
s = ["#" * (w + 2)]
for _ in range(h):
    s.append("#" + input() + "#")
s.append("#" * (w + 2))

b = [[0] * (w + 2) for _ in range(h + 2)]
for hi in range(h + 2):
    for wi in range(w + 2):
        if s[hi][wi] == ".":
            b[hi][wi] = 1

u = deepcopy(b)
d = deepcopy(b)
l = deepcopy(b)
r = deepcopy(b)
for hi in range(1, h + 1):
    for wi in range(1, w + 1):
        if s[hi][wi] == ".":
            u[hi][wi] += u[hi-1][wi]
            l[hi][wi] += l[hi][wi-1]

for hi in range(h, 0, -1):
    for wi in range(w, 0, -1):
        if s[hi][wi] == ".":
            d[hi][wi] += d[hi+1][wi]
            r[hi][wi] += r[hi][wi+1]

ans = 0
for hi in range(1, h + 1):
    for wi in range(1, w + 1):
        cnt = u[hi][wi] + d[hi][wi] + l[hi][wi] + r[hi][wi] - 3
        ans = max(ans, cnt)

print(ans)


### FIXED CODE ###

def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]

    m = [[0] + [0 if e == "#" else 1 for e in s[i]] + [0] for i in range(h)]
    m.append([0] * (w + 2))
    m.insert(0, [0] * (w + 2))

    m_t = [[m[i][j] for i in range(h+2)] for j in range(w+2)]

    lr = []
    for i in range(h + 2):
        sm = 0
        row = []
        for j in range(w + 2):
            if m[i][j]:
                sm += 1
            else:
                row += [sm] * sm + [0]
                sm = 0

        lr.append(row)

    ud = []
    for i in range(w + 2):
        sm = 0
        row = []
        for j in range(h + 2):
            if m_t[i][j]:
                sm += 1
            else:
                row += [sm] * sm + [0]
                sm = 0

        ud.append(row)

    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            sm = lr[i][j] + ud[j][i] - 1
            ans = max(ans, sm)

    print(ans)


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

import queue
N,K,L=map(int,input().split())
G=[[] for i in range(N)]
H=[[] for i in range(N)]
#T=[-1 for i in range(N)]
#B=[-1 for i in range(N)]
for i in range(K):
    p,q=map(int,input().split())
    G[p-1].append(q-1)
    G[q-1].append(p-1)
for i in range(L):
    r,s=map(int,input().split())
    H[r-1].append(s-1)
    H[s-1].append(r-1)
def bfs(A):
    k=0
    q=queue.Queue()
    reached=[0 for i in range(N)]
    res=[-1 for i in range(N)]
    for i in range(N):
        if reached[i]==1:
            continue
        q.put(i)
        while(not(q.empty())):
            r=q.get()
            res[r]=k
            for p in A[r]:
                if reached[p]==1:
                    continue
                q.put(p)
                reached[p]=1
        k+=1
    return res
T=bfs(G)
B=bfs(H)
TB=[(T[i],B[i]) for i in range(N)]
D=dict()
for i in range(N):
    if TB[i] in D:
        D[TB[i]]+=1
    else:
        D[TB[i]]=1
ans=[str(D[TB[i]]) for i in range(N)]
print(" ".join(ans))




### FIXED CODE ###

N,K,L=map(int,input().split())
G=[[] for i in range(N)]
H=[[] for i in range(N)]
#T=[-1 for i in range(N)]
#B=[-1 for i in range(N)]
for i in range(K):
    p,q=map(int,input().split())
    G[p-1].append(q-1)
    G[q-1].append(p-1)
for i in range(L):
    r,s=map(int,input().split())
    H[r-1].append(s-1)
    H[s-1].append(r-1)
def bfs(A):
    k=1
    q=[]
    reached=[0 for i in range(N)]
    res=[0 for i in range(N)]
    for i in range(N):
        if reached[i]==1:
            continue
        q.append(i)
        while(len(q)>0):
            r=q[-1]
            q.pop()
            res[r]=k
            for p in A[r]:
                if reached[p]==1:
                    continue
                q.append(p)
                reached[p]=1
        k+=1
    return res
T=bfs(G)
B=bfs(H)
TB=[(T[i],B[i]) for i in range(N)]
D=dict()
for i in range(N):
    if TB[i] in D:
        D[TB[i]]+=1
    else:
        D[TB[i]]=1
ans=[str(D[TB[i]]) for i in range(N)]
print(" ".join(ans))
### BUGGY CODE ###

S = input()
N = len(S)
child = [i for i in range(N)]
child_last = []
t = 0
while True:
  #print(child)
  if t % 2 == 0:
    if child_last == child:
      break
    else:
      child_last = child.copy()
  
  for i in range(N):
    if S[child[i]] == "R":
      child[i] += 1
    else:
      child[i] -= 1
      
  t += 1
  
ans = [0 for _ in range(N)]
for i in range(N):
  ans[child[i]] += 1
  
print(*ans,sep=" ")

### FIXED CODE ###

S = input()
N = len(S)

curr = ["R","L"]
idx = 0
cnt = 0
E = []
for i, ch in enumerate(S):
  if ch != curr[idx]:
    E.append((idx,cnt))
    cnt = 1
    idx = 1 - idx
  else:
    cnt += 1
    
E.append((idx,cnt))
#print(E)

ans = []
for i in range(0,len(E),2):
  Rcnt = E[i][1]
  Lcnt = E[i+1][1]
  Rfill = Lfill = (Rcnt + Lcnt)//2
 
  if (Rcnt + Lcnt) % 2 == 1:
    if Rcnt % 2 == 1:
      Rfill += 1
    else:
      Lfill += 1
  
  for i in range(Rcnt - 1):
    ans.append(0)
  
  ans.append(Rfill)
  ans.append(Lfill)
  
  for i in range(Lcnt - 1):
    ans.append(0)

  
print(*ans,sep=" ")
### BUGGY CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[]

import heapq  
heapq.heapify(a) 

for _ in range(m):
    b,c=map(int,input().split())
    for _ in range(b):
        temp=heapq.heappop(a)
        if temp<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,temp)
            break
#print(a)
print(sum(list(a)))

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
#bc=[]

import heapq  
heapq.heapify(a) 

bc=[]
for _ in range(m):
    b,c=map(int,input().split())
    bc.append((c,b))

bc.sort(reverse=True)
for item in bc:
    b=item[1]
    c=item[0]    
    for _ in range(b):
        temp=heapq.heappop(a)
        if temp<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,temp)
            print(sum(list(a)))
            exit()
#print(a)
print(sum(list(a)))
### BUGGY CODE ###

F=lambda:tuple(int(X)for X in input().split());H,W,N=F();S={F()for _ in[0]*N};T=set();Z=[0]*10
for Y,X in S:
	for A in range(9):
		P=A,B=X-A%3,Y-A//3
		if(0<A<W-1)*(0<B<H-1)*(P not in T):T.add(P);Z[sum((B+C//3,A+C%3)in S for C in range(9))]+=1
Z[0]+=(H-2)*(W-2)-sum(Z);print(*Z,sep='\n')

### FIXED CODE ###

F=lambda:tuple(int(X)for X in input().split());H,W,N=F();S={F()for _ in[0]*N};T=set();Z=[0]*10
for Y,X in S:
	for A in range(9):
		P=A,B=X-A%3,Y-A//3
		if(0<A<W-1)*(0<B<H-1)*(P not in T):T.add(P);Z[sum((B+C//3,A+C%3)in S for C in range(9))]+=1
Z[0]+=(H-2)*(W-2)-sum(Z);print(*Z,sep='\n')
### BUGGY CODE ###

import copy

S = input()
nN = len(S)
nAns = [ 0 for i in range(nN)]

for i in range(nN):
  nTmp = i
  nR = 0
  nFlag = 0
  for j in range(100000):
    sTmp = S[nTmp]
    
    if sTmp =='R':
      nR = 1
    elif sTmp =='L':
      nR = -1
    nTmp += nR
    
    nChk = j & 1
    if nChk == 1 and nFlag != nR:
      nAns[nTmp] += 1
      break
    nFlag = nR
      
      
print(*nAns)



### FIXED CODE ###

import sys
import copy

S = input()
nN = len(S)
nAns = [ 0 for i in range(nN)]
nAnsT = [ 0 for i in range(nN)]
nAnsR = [ 0 for i in range(nN)]

nCnt = S.count('RL')
nRLp = [ 0 for i in range(nCnt)]

nTmpP = 0
for i in range(nCnt):
  nTmp = S.find('RL',nTmpP)
  nRLp[i] = nTmp
  nTmpP = nTmp + 1

nCntE = S.count('LR')
nLRp = [ 0 for i in range(nCntE)]
nTmpP = 0
for i in range(nCntE):
  nTmp = S.find('LR',nTmpP)
  nLRp[i] = nTmp
  nTmpP = nTmp + 1
  
# print(nRLp)
# print(nLRp)

nTmpS = 0
for i in range(nCnt):
  nTmpR = nRLp[i]
  nTmpL = nTmpR + 1
  
  if i == nCnt - 1:
    nTmpE = nN - 1
  else:
    nTmpE = nLRp[i]
    
  nSize = nTmpE-nTmpS+1
  nB1 = nSize // 2
  nB2 = nSize // 2
  nChk = nSize % 2
  if nChk == 1:
    nB1 += 1
  
  nChk = nTmpR - nTmpS
  nChk %= 2
  if nChk == 0:
    nAns[nTmpR]=nB1
    nAns[nTmpL]=nB2
  else:
    nAns[nTmpR]=nB2
    nAns[nTmpL]=nB1
  
  nTmpS = nTmpE + 1

print(*nAns)
### BUGGY CODE ###

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

### FIXED CODE ###

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

N = int(input())

def solve(N):
    for i in range(1,N+1):
        ans = 0
        for x in range(1,int(N**0.5)+1):
            for y in range(1,int(N**0.5)+1):
                for z in range(1,int(N**0.5)+1):
                    if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                        ans += 1
        print(ans)
        
solve(N)

### FIXED CODE ###

N = int(input())

from collections import deque
tmp = []
tmp = deque(tmp)
num = [0]*(10**4*7)
for i in range(1,10**2+1):
    tmp.append(i**2)

for x in tmp:
    xx = int(x**0.5)
    for y in tmp:
        yy = int(y**0.5)
        for z in tmp:
            zz = int(z**0.5)
            ans = x + y + z + xx*yy + yy*zz + zz*xx
            num[ans] += 1
            
for i in range(1,N+1):
    print(num[i])
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N+1):
    for g in range(N+1):
        s = N - R*r - G*g
        if s >= 0 and s % B == 0:
            ans += 1
print(ans)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N+1):
    for g in range(N+1):
        s = N - R*r - G*g
        if s >= 0 and s % B == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

def solve():
  s =input()
  n =len(s)
  #Tの位置とSの位置がほしい
  places = []
  placet = []
  for i in range(n):
    if s[i] == 'S':places.append(i)
    else: placet.append(i)
  places = places[::-1]
  placet = placet[::-1]
  ct = 0
  for j in places:
    if j < placet[0]:
      ct += 2
      placet.pop(0)
  return (n-ct)  
  
  
if __name__ == '__main__':
  print(solve())

### FIXED CODE ###

def solve():
  s =input()
  n =len(s)
  queue = 0
  ans = 0
  for i in range(n):
    if s[i] == 'S': queue+=1
    else: 
      if queue >0:
        queue -= 1
        ans += 2
  return (n-ans)  
  
  
if __name__ == '__main__':
  print(solve())
### BUGGY CODE ###

N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for i in range(N):
    tmp = format(As[i], 'b').zfill(60)
    for j in range(60):
        L[j] += int(tmp[j])

acc = 1
tmps = []
for i in range(60):
    tmps.append(acc)
    acc = acc * 2 % mod

for i in range(60):
    tmp = tmps[-(i + 1)]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod

ans = ans % mod
print(ans)

### FIXED CODE ###

N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for A in As:
    for i in range(60):
        if A >> i & 1 == 1:
            L[i] += 1

acc = 1
tmps = []
for i in range(60):
    tmps.append(acc)
    acc = acc * 2 % mod

for i in range(60):
    tmp = tmps[i]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod

ans = ans % mod
print(ans)
### BUGGY CODE ###

import numpy as np
n = int(input())
*A, = map(int, input().split())
A = np.array(A)
X = []
for _ in range(n):
    X += [sum(A[::2])-sum(A[1::2])]
    A = np.roll(A, -1, 0)
print(*X)

### FIXED CODE ###

n = int(input())
*A, = map(int, input().split())
X = []
p = sum(A[::2])
q = sum(A[1::2])
for a in A:
    X += [p-q]
    p, q = q+a, p-a
print(*X)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans = 1
flg = True
for i in range(N):
    ans *= A[i]
    if A[-1] != 0:
        if ans > 10**18:
            flg = False
            break
    if A[-1] == 0:
        ans = 0
        break
if flg == False:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###


S = int(input())
count = 0
l = [0]*2019
l[0] = 1

for i in range(1,len(str(S))+1):
   l[(S%10**i)%2019] += 1

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

print(count)


### FIXED CODE ###

S = input()
count = 0
l = [0]*2019
l[0] = 1
mod = 2019
tmp = 0

for i in range(1,len(S)+1):
    tmp = (tmp + int(S[len(S)-i])*pow(10,i-1,mod))%mod
    l[tmp] += 1
    

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

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

N = int(input())
S = input()
 
ans = float("inf")
for i in range(len(S)+1):
  left = S[:i].count("#")
  right = S[i:].count(".")
  ans = min(ans, left + right)
  
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
 
left = 0
right = S.count(".")
ans = right

for i in range(len(S)):
    if S[i] == ".":
        right -= 1
    else:
        left += 1

    ans = min(ans, left + right)
  
print(ans)
### BUGGY CODE ###

def Warshall_Floyd(edges,N):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j])
  return edges

H, W, D = map(int,input().split())
dist = [[float("inf") for i in range(H*W+1)] for j in range(H*W+1)]
for i in range(H*W+1):
  dist[i][i] = 0
#dist[i][j]は隣接行列
pos = [[0,0] for i in range(H*W+1)]
for i in range(H):
  A = list(map(int,input().split()))
  for j in range(W):
    pos[A[j]] = [i+1, j+1]
for i in range(H*W+1-D):
  dist[i][i+D] = abs(pos[i][0]-pos[i+D][0])+abs(pos[i][1]-pos[i+D][1])
#print(dist)
dist = Warshall_Floyd(dist,H*W+1)
#print(dist)
Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  print(dist[L][R])

### FIXED CODE ###

H, W, D = map(int,input().split())
dist = [0]*(H*W+1)#dist[i]はiからi+Dまでの距離
pos = [[0,0] for i in range(H*W+1)]
for i in range(H):
  A = list(map(int,input().split()))
  for j in range(W):
    pos[A[j]] = [i+1, j+1]
for i in range(H*W+1-D):
  dist[i] = abs(pos[i][0]-pos[i+D][0])+abs(pos[i][1]-pos[i+D][1])
distances = [[] for i in range(D)]#あまりがiの距離
for i in range(1,H*W+1-D):
  d = dist[i]
  distances[i%D]+=[d]
distances2 = [[0] for i in range(D)]#累積和に直す
for i in range(D):
  for j in range(len(distances[i])):
    distances2[i]+=[distances2[i][-1]+distances[i][j]]
Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  q = L%D
  l, r = (L-1)//D, (R-1)//D
  print(distances2[q][r]-distances2[q][l])
### BUGGY CODE ###

H, W = map(int, input().split())
sh, sw = map(int, input().split())
gh, gw = map(int, input().split())

sh += 1
sw += 1
gh += 1
gw += 1
s = sh*(W+4)+sw
g = gh*(W+4)+gw
S = [0]*(H+4)
S[0] = '*'*(W+4)
S[1] = '*'*(W+4)
S[-2] = '*'*(W+4)
S[-1] = '*'*(W+4)
for h in range(2,H+2):
  S[h] = '**' + input() + '**'

visited = [10**7]*((W+4)*(H+4))
dh1 = [0,1,0,-1]
dw1 = [1,0,-1,0]
dh2 = [2,2,2,2,2,1,1,1,1,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-2]
dw2 = [-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]

from collections import deque
d = deque()
visited[g]=-1
d.append(g)

while len(d)>0:
  a = d.popleft()
  h,w = divmod(a,W+4)
  for i in range(4):
    h1 = h+dh1[i]
    w1 = w+dw1[i]
    a1 = h1*(W+4)+w1
    if S[h1][w1]=='.':
      visited[g]=-1
      d.append(a1)

d = deque()
visited[s] = 0
d.append(s)
ans = 10**8
while len(d)>0:
  a = d.popleft()
  h,w = divmod(a,W+4)
  cnt = visited[a]
  if ans<=cnt:
    continue
  for i in range(4):
    h1 = h+dh1[i]
    w1 = w+dw1[i]
    a1 = h1*(W+4)+w1
    if visited[a1]==-1:
      ans = min(ans,cnt)
    if S[h1][w1]=='.':
      if visited[a1]>cnt:
        visited[a1]=cnt
        d.append(a1)
  for i in range(20):
    h2 = h+dh2[i]
    w2 = w+dw2[i]
    a2 = h2*(W+4)+w2
    if visited[a2]==-1:
      ans = min(ans,cnt+1)
    if S[h2][w2]=='.':
      if visited[a2]>cnt+1:
        visited[a2]=cnt+1
        d.append(a2)
if ans==10**8:
  ans = -1
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
sh, sw = map(int, input().split())
gh, gw = map(int, input().split())

sh += 1
sw += 1
gh += 1
gw += 1
s = sh*(W+4)+sw
g = gh*(W+4)+gw
S = [0]*(H+4)
S[0] = '*'*(W+4)
S[1] = '*'*(W+4)
S[-2] = '*'*(W+4)
S[-1] = '*'*(W+4)
for h in range(2,H+2):
  S[h] = '**' + input() + '**'

visited = [10**7]*((W+4)*(H+4))
dh1 = [0,1,0,-1]
dw1 = [1,0,-1,0]
dh2 = [2,2,2,2,2,1,1,1,1,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-2]
dw2 = [-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]

from collections import deque

d = deque()
visited[s] = 0
d.append(s)
ans = 10**8
while len(d)>0:
  a = d.popleft()
  h,w = divmod(a,W+4)
  cnt = visited[a]
  if ans<=cnt:
    continue
  for i in range(4):
    h1 = h+dh1[i]
    w1 = w+dw1[i]
    a1 = h1*(W+4)+w1
    if (h1,w1)==(gh,gw):
      ans = min(ans,cnt)
    if S[h1][w1]=='.':
      if visited[a1]>cnt:
        visited[a1]=cnt
        d.appendleft(a1)
  for i in range(20):
    h2 = h+dh2[i]
    w2 = w+dw2[i]
    a2 = h2*(W+4)+w2
    if (h2,w2)==(gh,gw):
      ans = min(ans,cnt+1)
    if S[h2][w2]=='.':
      if visited[a2]>cnt+1:
        visited[a2]=cnt+1
        d.append(a2)
if ans==10**8:
  ans = -1
print(ans)
### BUGGY CODE ###

N = int(input())
P = tuple(map(int, input().split()))

cnt = 1
min = N

for i in range(1, N):
  if P[i] > min:
    continue
  for j in range(i-1, -1, -1):
    if P[i] > P[j]:
      break
  else:
    if min >P[i]:
      min = P[i]
    cnt += 1
    if min == 1:
      break


print(cnt)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
min_p = P[0]
cnt = 0

for p in P:
  if p <= min_p:
    min_p = p
    cnt += 1

print(cnt)
### BUGGY CODE ###

import collections as col
cnt = col.Counter()

s = input()
n = len(s)

for i in range(n+1):
    num = 0 if i==0 else int(s[-i:])
    cnt[num%2019] += 1

ans = 0
for key,val in cnt.items():
    ans += val*(val-1)//2

print(ans)


### FIXED CODE ###

arr = [0 for i in range(2019)]
arr[0] = 1

s = input()
n = len(s)

num = 0
for i,ele in enumerate(s[::-1]):
    num += int(ele) * pow(10, i, 2019)
    arr[num%2019] += 1


ans = 0
for m in arr:
    if m==0: continue
    ans += m*(m-1)//2

print(ans)