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

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
# 20億^2で10^18を超えるので19乗で
INF = 10 ** 19
MOD = 10 ** 9 + 7

N, K = MAP()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

ans = INF
# 4点組み合わせ全部試す
for i in range(N):
    x1, y1 = XY[i]
    for j in range(i, N):
        x2, y2 = XY[j]
        for k in range(j, N):
            x3, y3 = XY[k]
            for l in range(k, N):
                x4, y4 = XY[l]
                xl, xr = min(x1, x2, x3, x4), max(x1, x2, x3, x4)
                yl, yr = min(y1, y2, y3, y4), max(y1, y2, y3, y4)
                # 4点の内側にいくつ点があるか数える
                k = 0
                for x5, y5 in XY:
                    if xl <= x5 <= xr and yl <= y5 <= yr:
                        k += 1
                if k >= K:
                    ans = min(ans, (xr-xl) * (yr-yl))
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

"""
・座標圧縮
・2次元累積和
"""

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

X, Y = [0]*N, [0]*N
for i in range(N):
    X[i], Y[i] = map(int, input().split())

# 座標圧縮
zip_x, zip_y, unzip_x, unzip_y = {}, {}, {}, {}
X2 = sorted(set(X))
Y2 = sorted(set(Y))
# この後の処理のために添字は1-indexedにする
for i in range(len(X2)):
    zip_x[X2[i]] = i+1
    unzip_x[i+1] = X2[i]
for i in range(len(Y2)):
    zip_y[Y2[i]] = i+1
    unzip_y[i+1] = Y2[i]

# 圧縮した座標に点を割り当て(グリッドは累積和用に一回り大きく作る)
grid = [[0] * (len(X2)+1) for _ in range(len(Y2)+1)]
for i in range(N):
    grid[zip_y[Y[i]]][zip_x[X[i]]] += 1

# 2次元累積和
for i in range(len(Y2)+1):
    for j in range(1, len(X2)+1):
        grid[i][j] += grid[i][j-1]
for i in range(1, len(Y2)+1):
    for j in range(len(X2)+1):
        grid[i][j] += grid[i-1][j]

ans = float('inf')
for i in range(1, len(Y2)+1):
    for j in range(1, len(X2)+1):
        # 終点がK以上あれば始点を動かし始める
        if grid[i][j] >= K:
            for k in range(i):
                for l in range(j):
                    # 部分累積和を出して、点がK以上あるか確認
                    if grid[i][j] - grid[i][l] - grid[k][j] + grid[k][l] >= K:
                        # 長方形の面積を出して最小を保持
                        ans = min((unzip_x[j]-unzip_x[l+1]) * (unzip_y[i]-unzip_y[k+1]), ans)
print(ans)
### BUGGY CODE ###

N,M,K = map(int, input().split())
import math

counter =0

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def painting(length,color_num):
    return color_num*(color_num-1)**(length-1)

for k in range(1,K+1):
    counter += combinations_count(N-1,k)*painting(N-k,M)



all = counter + painting(N,M)
print(all%998244353)


### FIXED CODE ###

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

p = 998244353

factorial = [1]
counter = 0
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i%p)



for k in range(K+1):
    counter += factorial[N-1]*pow(factorial[k],p-2,p)*pow(factorial[N-k-1],p-2,p)*M*pow(M-1,N-1-k,p)
print(counter%p)
### BUGGY CODE ###

from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


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


n = ni()
s = ns()
ans = 0
for num in product(range(0, 10), repeat=3):
    i = 0
    numi = num[0]
    for si in s:
        if int(si) == numi and i == 2:
            ans += 1
            break
        elif int(si) == numi:
            i += 1
            numi = num[i]
print(ans)


### FIXED CODE ###

#create date: 2020-08-11 09:28

import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    s = ns()
    ans = 0

    for a in product(range(10), repeat=3):
        i = 0
        for si in s:
            if int(si) == a[i]:
                i += 1
            if i == 3:
                ans += 1
                break
    print(ans)

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

s = input()
l = len(s)
A = [i for i in range(2019, int(s) + 2019, 2019)]
ans = 0
for a in A:
    di = len(str(a))
    for i in range(l - di + 1):
        # print(s[i:i + di], a)
        if s[i:i + di] == str(a):
            ans +=1
print(ans)

### FIXED CODE ###

s = input()
l = len(s)
dp = [0 for i in range(2019)]
dp[0] = 1
r = 0
for i in range(1, l + 1):
    r += int(s[-i]) * pow(10, i - 1, 2019)
    r %= 2019
    dp[r] += 1
    
print(sum([(i * (i - 1)) // 2 for i in dp]))
### BUGGY CODE ###

from collections import defaultdict
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def tento(xs):
    bit = Bit(max(xs)+1)
    ans = 0
    for i, p in enumerate(xs):
        ans += i-bit.sum(p)
        bit.add(p, 1)
    return ans

N = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
r = 10**18
zs = [0]*N
zs2 = [(0, -1, 0)]*N
for i in range(2**N):
    for j in range(N):
        if i%2:
            zs[j] = (xs[j],(j+1)%2,j)
        else:
            zs[j] = (ys[j],j%2,j)
        i = i>>1
    zs.sort()
    ll,rr,ff=0,1,0
    for l, (z, m, j) in enumerate(zs):
        if m:
            if ll>=N:
                ff = 1
                break
            zs2[ll] = (j, z)
            ll += 2
        else:
            if rr>=N:
                ff = 1
                break
            zs2[rr] = (j, z)
            rr += 2
    if ff:
        continue
    b = 0
    for j, z in zs2:
        if b>z:
            ff = 1
            break
        b = z
    if ff:
        continue
    zs2 = [j+1 for j,_ in zs2]
    r = min(r, tento(zs2))
print(r if r != 10**18 else -1)

#    ff = 0
#    for l, (z, j,m) in enumerate(zs):
#        if (m-l)%2==0: 
#            ff = 1
#            break
#    if ff:
#        continue
#    zs = [j+1 for z,j,m in zs]


### FIXED CODE ###


from collections import defaultdict
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def tento(xs):
    bit = Bit(max(xs)+1)
    ans = 0
    for i, p in enumerate(xs):
        ans += i-bit.sum(p)
        bit.add(p, 1)
    return ans
N = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
us = []
vs = []
for i in range(N):
    a, b = xs[i], ys[i]
    if i%2:
        us.append((a,i))
        vs.append((b,i))
    else:
        us.append((b,i))
        vs.append((a,i))
vs.sort()
r = 10**18
for i in range(2**N):
    t = 0
    tt = 0
    rs = [0]*N
    rs2 = [0]*(N//2)
    for j in range(N):
        if i%2:
            if 2*t < N:
                rs[t*2] = vs[j]
            t += 1
        else:
            if 2*tt+1 < N:
                rs2[tt] = us[vs[j][1]]
            tt += 1
        i = i>>1
    if t != (N+1)//2:
        continue
    rs2.sort()
    for i in range(N//2):
        rs[i*2+1] = rs2[i]
    b,ff = 0,0
    for z,j in rs:
        if b>z:
            ff = 1
            break
        b = z
    if ff:
        continue
#    print(rs)
    rs = [j+1 for _,j in rs]
    r = min(r, tento(rs))
print(r if r != 10**18 else -1)
### BUGGY CODE ###

import networkx as nx
import sys
input = sys.stdin.readline

T = int(input())
for _ in range(T):
    N = int(input())
    G = nx.MultiDiGraph()
    # s: source t: sink
    # 0 ... N-1: camel
    # N ... 2*N-1: loc1
    # 2*N ... 3*N-1: loc2
    G.add_node('s', demand=-N)
    G.add_node('t', demand=N)
    for i in range(N):
        G.add_edge('s', i, weight=0, capacity=1)
    for i in range(N-1):
        G.add_edge(N+i, N+i+1, weight=0, capacity=i+1)
    for i in range(N-1):
        G.add_edge(2*N+i+1, 2*N+i, weight=0, capacity=N-i-1)
    G.add_edge(2*N-1, 't', weight=0, capacity=N)
    G.add_edge(2*N, 't', weight=0, capacity=N)
    for i in range(N):
        K, L, R = map(int, input().split())
        K -= 1
        G.add_edge(i, N+K, weight=-L, capacity=1)
        if K < N - 1:
            G.add_edge(i, 2*N+K+1, weight=-R, capacity=1)
    print(-nx.min_cost_flow_cost(G))

### FIXED CODE ###

from collections import deque
from heapq import heappush, heappushpop
import sys
input = sys.stdin.readline

def calc(camels):
    camels = deque(sorted(camels, key=lambda x: x[0]))
    N = len(camels)
    heap = []
    while camels and camels[0][0] == 0:
        camels.popleft()
    for i in range(1, N+1):
        while camels and camels[0][0] == i:
            _, x = camels.popleft()
            if len(heap) < i:
                heappush(heap, x)
            elif heap[0] < x:
                heappushpop(heap, x)
    for _, x in camels:
        if len(heap) < N:
            heappush(heap, x)
        elif heap[0] < x:
            heappushpop(heap, x)
    return sum(heap)

T = int(input())
for _ in range(T):
    N = int(input())
    s = 0
    ans = 0
    first = []
    second = []
    for i in range(N):
        K, L, R = map(int, input().split())
        if L >= R:
            first.append((K, L - R))
            ans += R
        else:
            second.append((N - K, R - L))
            ans += L
    ans += calc(first) + calc(second)
    print(ans)
### BUGGY CODE ###

from bisect import bisect_left

n = int(input())

a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

second_list = []
for i in b:
    second_list.append(bisect_left(a, i))

ans = 0
for i in c:
    ans += sum(second_list[0:bisect_left(b, i)])

print(ans)

### FIXED CODE ###

from bisect import bisect_left, bisect_right

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

ans = 0
for i in b:
    ans += bisect_left(a, i) * (n - bisect_right(c, i))

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

def bitcount(N):  # 立ってるbitの数
    bitcnt = [0]
    for _ in range(N):
        bitcnt += [i + 1 for i in bitcnt]
    return bitcnt


n, x = int(input()), input()

num, cnt = int(x, 2), x.count('1')
lbit = bitcount(18)
for i in range(n):
    ans = 1
    if x[i] == '0':
        ctmp = cnt + 1
        tmp = (num + pow(2, n - (i + 1), ctmp)) % ctmp
    elif x[i] == '1':
        if cnt == 1:
            print(0)
            continue
        ctmp = cnt - 1
        tmp = (num - pow(2, n - (i + 1), ctmp)) % ctmp
    ctmp = lbit[tmp]
    while tmp > 0:
        ans += 1
        tmp %= ctmp
        ctmp = lbit[tmp]
    print(ans)


### FIXED CODE ###

def bitcount(N):  # 立ってるbitの数
    bitcnt = [0]
    for _ in range(N):
        bitcnt += [i + 1 for i in bitcnt]
    return bitcnt


n, x = int(input()), input()

num, cnt = int(x, 2), x.count('1')
lbit = bitcount(18)
for i in range(n):
    ans = 1
    if x[i] == '0':
        ctmp = cnt + 1
        tmp = num % ctmp + pow(2, n - (i + 1), ctmp)
    elif x[i] == '1':
        ctmp = cnt - 1
        if ctmp == 0:
            print(0)
            continue
        tmp = num % ctmp - pow(2, n - (i + 1), ctmp)
    tmp %= ctmp
    ctmp = lbit[tmp]
    while tmp > 0:
        ans += 1
        tmp %= ctmp
        ctmp = lbit[tmp]
    print(ans)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()
A = [list(input()) for i in range(h)]

def bfs():
    que = deque([])
    
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    d = [[INF] * w for i in range(h)]
    
    for i in range(h):
        for j in range(w):
            if A[i][j] == "#":
                sy, sx = i, j
                d[sy][sx] = 0
                que.append((sy, sx))
    while que:
        p = que.popleft()
        ans = d[p[0]][p[1]]
        for i in range(4):
            ny, nx = p[0] + dy[i], p[1] + dx[i]
            
            if 0 <= ny < h and 0 <= nx < w and d[ny][nx] == INF and A[ny][nx] == ".":
                d[ny][nx] = d[p[0]][p[1]] + 1
                A[ny][nx] = "#"
                que.append((ny, nx))
 
                #ans = max(ans, d[ny][nx])     
    
    return ans



print(bfs())

    



### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()
A = [list(input()) for i in range(h)]


def bfs():
    que = deque([])
    
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    d = [[INF] * w for i in range(h)]
    
    for i in range(h):
        for j in range(w):
            if A[i][j] == "#":
                sy, sx = i, j
                d[sy][sx] = 0
                que.append((sy, sx))
    ans = 0
    while que:
        p = que.popleft()
        for i in range(4):
            ny, nx = p[0] + dy[i], p[1] + dx[i]
            
            if 0 <= ny < h and 0 <= nx < w and d[ny][nx] == INF and A[ny][nx] == ".":
                d[ny][nx] = d[p[0]][p[1]] + 1
                # A[ny][nx] = "#"
                que.append((ny, nx))
 
                ans = max(ans, d[ny][nx])     
#    print(*d, sep="\n")
    return ans


if __name__ == "__main__":
    print(bfs())
### BUGGY CODE ###

a,b,k=map(int,input().split())
ab=[i for i in range(a,b+1)]
c=sorted(list(set(ab[:k]+ab[b-a-(k-1):])))
for j in range(len(c)):
    print(c[j])

### FIXED CODE ###

a,b,k=map(int,input().split())
l=range(a,b+1)
for i in sorted(set(l[:k])|set(l[-k:])):
    print(i)
### BUGGY CODE ###

H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    cnt=1
    a=i
    b=j
    if S[a][b]=='.':
      while a+1 < H and S[a+1][b]=='.':
        cnt+=1
        a+=1
      a=i
      while 0 <= a-1 and S[a-1][b]=='.':
        cnt+=1
        a-=1
      a=i
      while b+1 < W and S[a][b+1]=='.':
        cnt+=1
        b+=1
      b=j
      while 0 <= b-1 and S[a][b-1]=='.':
        cnt+=1
        b-=1
      b=j
    ans=max(cnt,ans)
print(ans)       

### FIXED CODE ###

import numpy as np
H,W=map(int, input().split())
S=np.array([list(input()) for i in range(H)]) == '.'
us=np.zeros((H,W), dtype=int)   
ds=np.zeros((H,W), dtype=int)   
ls=np.zeros((H,W), dtype=int)    
rs=np.zeros((H,W), dtype=int)  

for h in range(1,H):
    us[h, :]=(us[h-1, :]+1) * S[h-1, :]
for h in range(H-2, -1, -1):
    ds[h, :]=(ds[h+1, :]+1) * S[h+1, :]
for w in range(1,W):
    ls[:, w]=(ls[:, w-1]+1) * S[:, w-1]
for w in range(W-2, -1, -1):
    rs[:, w]=(rs[:, w+1]+1) * S[:, w+1]

ans = ((us+ds+ls+rs)*S).max()+1
print(ans)
### BUGGY CODE ###

L,R = map(int,input().split())
if (L-R >= 2019):
  print(0)
else:
  res = 2018
  for i in range(L,R):
    for j in range(i+1,R+1):
      res = min(res,(i*j)%2019)
  print(res)

### FIXED CODE ###

L,R = map(int,input().split())
if (R-L >= 2019):
  print(0)
else:
  res = 2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      res = min(res,(i*j)%2019)
  print(res)
### BUGGY CODE ###

if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1
    for i in range(N):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
    print(cnt)

### FIXED CODE ###

if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)
### BUGGY CODE ###

n=int(input())

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

a.sort()

if n > 1:
    if a[0] == a[1]:
        ans = 0
    else:
        ans = 1
else:
    print(1)
    exit()

for i in range(1,n):
    flag = True
    for j in range(i):
        if a[i] % a[j] == 0:
            flag = False
            break
        if int(a[i]//2)+1 < a[j]:  
            break
    if i == n-1:
        if flag and a[i] != a[i-1]:
            ans += 1
    else:
        if flag and a[i] != a[i-1] and a[i] != a[i+1]:
            ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
if n == 1:
    print(1)
    exit()  
check_list = [0] * (10**6 + 2)
ans = 0
for i in range(n):
    tmp = a[i]
    while tmp <= a[-1]:
        check_list[tmp] += 1
        tmp += a[i]
for aa in a:
    if check_list[aa] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

import re
if __name__ == '__main__':
    s = input()
    t = input()

    str_mat = [list('.'*len(t)), list(t)]
    min = len(t)

    for i in range(2**len(t)-1, -1, -1):
        bin_str = format(i, 'b').zfill(len(t))
        indices = map(int, list(bin_str))
        pattern = ''.join([str_mat[index][num] for num, index in enumerate(indices)])
        m = re.search(pattern, s)
        if m:
            tmp = bin_str.count('0')
            if min > tmp:
                min = tmp
    print(min)

### FIXED CODE ###

if __name__ == '__main__':
    s = list(input())
    t = list(input())

    max_score = 0
    if len(s) == len(t):
        max_score = sum([s[j] == t[j] for j in range(len(t))])
    else:
        for i in range(0, len(s) - len(t)):
            score = sum([s[i + j] == t[j] for j in range(len(t))])
            if max_score < score:
                max_score = score
    print(len(t) - max_score)
### BUGGY CODE ###

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

ans = 10**8 * 3
for i in range(N-K+1):
    light = x[i:i+K]
    l = light[0]
    r = light[-1]
    time = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    if time < ans:
        ans = time
print(ans)

### FIXED CODE ###

N,K = map(int, input().split())
x = list(map(int, input().split()))
ans=min([min(abs(x[i])+abs(x[i]-x[i+K-1]),abs(x[i+K-1])+abs(x[i+K-1]-x[i])) for i in range(N-K+1)])
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import networkx as nx
from random import randint
def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    G=nx.Graph()

    if M == 0 :
        print(1)
        return

    for a, b in zip(A,B):
        G.add_edge(a, b)

    Gc = max(nx.connected_components(G), key=len)
    print(len(Gc))
    return


# Generated by 1.1.7.1 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()
    while True:
        N = randint(10000, 100000)  # type: int
        M = 0 # type: int

        A = [randint(1, N) for i in range(M)]  # type: "List[int]"
        B = [randint(1, N) for i in range(M)]  # type: "List[int]"
        solve(N, M, A, B)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import networkx as nx

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    G=nx.Graph()

    if M == 0 :
        print(1)
        return

    for a, b in zip(A,B):
        G.add_edge(a, b)

    Gc = max(nx.connected_components(G), key=len)
    print(len(Gc))
    return


# Generated by 1.1.7.1 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
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

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

n, q = map(int, input().split())
s = input()
l = [0] * q
r = [0] * q
for i in range(0, q):
    l[i], r[i] = map(int, input().split())
for i in range(0,q):
    print(s[l[i] - 1:r[i]].replace('AC',' ').count(' '))

### FIXED CODE ###

n, q = map(int, input().split())
s = ' ' + input()
heap = [0] * (n + 1)
cnt = 0
for i in range(2, n + 1):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1;
    heap[i] = cnt
ans = []
for i in range(q):
    l, r = map(int, input().split())
    ans.append(heap[r] - heap[l])
for i in ans:
    print(i)
### BUGGY CODE ###

# coding: utf-8
K=int(input())

num=0
i=0

while num!=K:
    i+=1
    list_i=list(map(int,str(i)))
    flg=True
    for j in range(len(list_i)):
        if j>0:
            if abs(list_i[j-1]-list_i[j])>1:
                flg=False
    
    if flg:
        num+=1

print(i)

### FIXED CODE ###

# coding: utf-8
K=int(input())

lun=[[] for i in range(10)]

for i in range(10):
    for j in range(10):
        if abs(i-j)<=1:
            lun[i].append(j)

lunlun=[[1,2,3,4,5,6,7,8,9]]

for i in range(9):
    lunlun.append([])

for i in range(9):
    for j in range(len(lunlun[i])):
        for k in range(len(lun[lunlun[i][j]%10])):
            lunlun[i+1].append(lunlun[i][j]*10+lun[lunlun[i][j]%10][k])
LUNLUN=[]

for i in range(10):
    LUNLUN.extend(lunlun[i])
LUNLUN.sort

print(LUNLUN[K-1])
### BUGGY CODE ###

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

### FIXED CODE ###

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