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

n, m = map(int, input().split())
p, y = [0]*m, [0]*m
dict_p = {}
for i in range(m):
    p[i], y[i] = map(int, input().split())
    if p[i] not in dict_p.keys():
        dict_p[p[i]] = list()

    dict_p[p[i]].append(y[i])
#print(dict_p)
ans = [0]*m
for i in range(m):
    dict_p[p[i]].sort()
    r = dict_p[p[i]].index(y[i]) + 1
    l = p[i]
    ans = str("{:0=6}".format(l)) + str("{:0=6}".format(r))
    print(ans)

### FIXED CODE ###

from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
py = []
dict_p = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    py.append((p, y))
    dict_p[p].append(y)
#print(dict_p)
for values in dict_p.values():
    values.sort()

for p, y in py:
    x = bisect_left(dict_p[p], y)
    ans = "{:006}".format(p) + "{:006}".format(x+1)
    print(ans)
### BUGGY CODE ###

s=list(map(int,list(input())))[::-1]

n=len(s)
D=[0]*(n+1)
c=[0]*(n+1)
ans = 0
f = 0
dp = [0]*(2020)
dp[0]+=1

for e,i in enumerate(s):
    D[e]= i*pow(10,e)%2019
    if e!=0:
        c[e] = (c[e-1] + D[e])%2019
    else:
        c[e] = D[e]
    ans += dp[c[e]]
    dp[c[e]]+=1
# print(c)

# for e, i in enumerate(dp):
#     if i!=0:
#         print(e,i)
print(ans)

### FIXED CODE ###

s=list(map(int,list(input())))[::-1]

n=len(s)
D=[0]*(n+1)
c=[0]*(n+1)
ans = 0
f = 0
dp = [0]*(2020)
dp[0]+=1
tmp =0
x = 1
for e,i in enumerate(s):
    tmp = (tmp+x*i)%2019
    ans += dp[tmp]
    dp[tmp]+=1
    x = x*10 %2019
print(ans)
### BUGGY CODE ###

import itertools
import math


def distribute(i):
    ls = []
    for t in itertools.combinations_with_replacement(range(1, K+1), i):
        # print(t)
        if sum(t) == K:
            ls.append(t)
    return ls


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

for i in range(1, K+1):
    ans = 0
    ls = distribute(i)
    # print(ls)
    for ls_e in ls:
        # print(ls_e)
        c = 1
        for j in range(i):
            if N-K+1-j >= 1:
                c *= N-K+1-j
        # print(ls_e, c)
        for lsn in range(min(ls_e), max(ls_e)+1):
            if ls_e.count(lsn) >= 1:
                c //= math.factorial(ls_e.count(lsn))
        ans += c
    print(ans%(10**9+7))


### FIXED CODE ###

from scipy.misc import comb
mod = 1000000007

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

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
    else:
        print(comb(N-K+1,i,exact=True)*comb(K-1,i-1,exact=True)%mod)
### BUGGY CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[0]
for i in range(1,n): # dp[i]の最小を決めていく。
    dpi=float('inf')
    for j in range(1,k+1):
        if i<j:
            break
        else:
            dpi=min(dp[i-j]+abs(h[i]-h[i-j]),dpi)
    dp.append(dpi)
print(dp[-1])

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[0]
for i in range(1,n): # dp[i]の最小を決めていく。
    dpi=float('inf')
    for j in range(1,k+1):
        if i<j:
            break
        else:
            dpi=min(dp[i-j]+abs(h[i]-h[i-j]),dpi)
    dp.append(dpi)
print(dp[-1])
### BUGGY CODE ###

a,b = tuple(map(int,input().split(" ")))
ans = 1
for i in range(a,b+1):
    ans *= i

if ans>0:
    print("Positive")
elif ans==0:
    print("Zero")
else:
    print("Negative")

### FIXED CODE ###

import math

a,b = tuple(map(int,input().split(" ")))
if a>0:
    print("Positive")
elif a<0 and b>0:
    print("Zero")
elif a%2==0 and b%2==0 or a%2==1 and b%2==1:
    print("Negative")
else:
    print("Positive")
### BUGGY CODE ###

from sys import stdin

if __name__ == '__main__':
    S_R = stdin.readline().rstrip()
    S_L = S_R[::-1]

    len_s = len( S_R )
    H = {}
    for i in range( len_s ):
        H[i] = 0

    # Rの探索
    for i in range( len_s - 1 ):
        s = S_R[i]
        if s == 'R':
            count = 1
            for j in range( i+1, len_s ):
                if S_R[j] == 'L':
                    index = j
                    break
                else:
                    count += 1

            if count % 2 == 0:
                H[ j ] += 1
            else:
                H[ j - 1 ] += 1
        else:
            pass

    # Lの探索
    for i in range( len_s - 1 ):
        s = S_L[i]
        if s == 'L':
            count = 1
            for j in range( i+1, len_s ):
                if S_L[j] == 'R':
                    index = j
                    break
                else:
                    count += 1

            if count % 2 == 0:
                H[ len_s - j - 1 ] += 1
            else:
                H[ len_s - (j - 1) - 1 ] += 1
        else:
            pass

    for i in range( len_s ):
        print( "{} ".format( H[i] ), end="" )
    print()

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    S = input()
    S = list(S) + ['R']
    ans = [0]*len(S)
    b = 'L'
    index = []
    for i, s in enumerate(S):
        if b != s:
            index.append(i)
        b = s
    # print(index)
    for i in range(0, len(index)-2, 2):
        x = index[i]
        y = index[i + 1]
        z = index[i + 2]
        # print(x, y, z)
        a = y - x
        b = z - y
        ans[y-1] = (a+b)//2
        ans[y] = (a+b)//2
        if (a+b)%2 == 1:
            if a%2 == 1:
                ans[y-1] += 1
            if b%2 == 1:
                ans[y] += 1
    print(*ans[:-1])


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

from collections import deque

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and \
                visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])


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

sy, sx, gy, gx = 3, 1, 1, 5

maze = ["#"*(W+2)]
for i in range(H):
    tmp = "#"
    tmp += input()
    tmp += "#"
    maze.append(tmp)
maze.append("#"*(W+2))
    
#for i in range(H+2):
#    print(maze[i])

max_bfs = 0
for sy in range(1, H+2):
    for sx in range(1, W+2):
        for gy in range(1, H+2):
            for gx in range(1, W+2):
                if maze[sy][sx] == "." and maze[gy][gx] == ".":
                    visited = [[-1]*(W+2) for j in range(H+2)]
                    tmp_bfs = bfs(maze, visited, sy, sx, gy, gx)
                    if tmp_bfs > max_bfs:
                        max_bfs = tmp_bfs
                
print(max_bfs)


### FIXED CODE ###

from collections import deque

def bfs(maze, visited, sy, sx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and \
                visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
    return visited[y][x]

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

maze = ["#"*(W+2)]
for i in range(H):
    tmp = "#"
    tmp += input()
    tmp += "#"
    maze.append(tmp)
maze.append("#"*(W+2))
    
#for i in range(H+2):
#    print(maze[i])

max_bfs = 0
for sy in range(1, H+2):
    for sx in range(1, W+2):
        if maze[sy][sx] == ".":
            visited = [[-1]*(W+2) for j in range(H+2)]
            tmp_bfs = bfs(maze, visited, sy, sx)
            if tmp_bfs > max_bfs:
                max_bfs = tmp_bfs
        
print(max_bfs)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split(" ")))

x = 1
for i in range(N):
    x = x * A[i]

if x > 10 ** 18:
    print("-1")

else:
    print(x)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split(" ")))

if 0 in A:
        print(0)
        exit()

x = 1
for i in range(N):
    x = x * A[i]
        
    if x > 10 ** 18:
        print(-1)
        exit()

print(x)
### BUGGY CODE ###

A, B = map(int,input().split())

res = A
for n in range(A+1,B+1):
  res = res ^ n
  
print(res)

### FIXED CODE ###

def xor_a2b(a,b) : 
    flg = a % 2 != 0
    
    if flg: 
        a += 1
    mod = (b - a) % 4
    if mod == 0:
        res = b
    elif mod == 1:
        res =  1
    elif mod == 2:
        res = b + 1
    else:
        res = 0
    if flg:
        return (a-1) ^ res
    else:
        return res
      
a,b = map(int,input().split())

print(xor_a2b(a,b))
### BUGGY CODE ###

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

from collections import Counter

for k in range(n):
    m = l[:]
    m.pop(k)
    c = Counter(m)

    x = list(c.values())

    y = []
    for i in x:
        if i != 1:
            y.append(i)

    from math import factorial
    def combinations_count(n, r):
        return factorial(n) // (factorial(n - r) * factorial(r))
    
    z = []
    for j in y:
        z.append(combinations_count(j, 2))
    print(sum(z))

### FIXED CODE ###

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

from collections import Counter
c = Counter(l)
x = list(c.values())

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

y = 0
for i in range(len(x)):
    if x[i] != 1:
        y += combinations_count(x[i], 2)

for j in range(n):
    print(y - (c[l[j]] - 1))
### BUGGY CODE ###

from collections import defaultdict
n = int(input())
li_a = list(map(int, input().split()))
dd = {}
ans = 0
li_a.sort()
for j in range(len(li_a)):
    i = li_a[j]
    if j+1< len(li_a):
        if li_a[j] == li_a[j+1]:
            dd[i] =True
    b = True
    for key in dd:
        if i % key == 0:
            b = False
            break
    if b:
        ans += 1
        dd[i] = True
    
print(ans)

### FIXED CODE ###

n = int(input())
li = list(map(int, input().split()))
li.sort()
inf = (10**6)+1
isprime = [False]*(inf+1)
for i in li:
    isprime[i] = True
temp = 0
for i in li:
    if i == temp:
        isprime[i] = False
    if not isprime[i]:
        continue
    for k in range(i*2, inf+1, i):
        isprime[k] = False
    temp = i
prime_list = []
for i in range(len(li)):
      if i+1<len(li):
            if li[i] == li[i+1]:
                isprime[li[i]] = False
for i in range(1, inf+1):
    if isprime[i]:
        prime_list.append(i)
print(len(prime_list))
### BUGGY CODE ###

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

num_cnt = {}
res = 0
for num in range(n):
    cnt = a.count(num+1)
    if cnt > 0:
        num_cnt[num+1] = cnt
        res += cnt*(cnt-1)//2

for a_k in a:
    cnt = num_cnt[a_k]
    print(res - (cnt-1)*(cnt - (cnt-2))//2)

### FIXED CODE ###

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

import collections
cnt = collections.Counter(a)

sum_cnt = 0
for v in cnt.values():
    sum_cnt += v*(v-1)//2

res = []
for value in a:
    res.append(str( sum_cnt - (cnt[value]-1) ))
print('\n'.join(res))
### BUGGY CODE ###

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

D=[float("inf")]*N
D[0]=0
D[1]=abs(H[1]-H[0])
for i in range(2,N):
  # print(i, "before:",D)
    D[i]=min(abs(H[i]-H[i-k])+D[i-k] for k in range(1,K+1))
  # print(i, "after:",D)

print(D[-1])

### FIXED CODE ###

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

D=[float("inf")]*N
D[0]=0
D[1]=abs(H[1]-H[0])
for i in range(2,N):
  # print(i, "before:",D)
  #  print(i,i-1,i-K, max(1, i-K))
  D[i]=min(abs(H[i]-H[k])+D[k] for k in range(max(0,i-K),i))
  # print(i, "after:",D)

print(D[-1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
 

# n,m = map(int,input().split())

# a = list(map(int, input().split()))  # n個の文字列がリストに格納される

N = int(input())

A = list(map(int, input().split()))  # n個の文字列がリストに格納される

for i in range(N-1):
    print(A.count(i+1))

print('0')


### FIXED CODE ###

N = int(input())

A = list(map(int, input().split()))  # n個の文字列がリストに格納される

ans = [0] * N

for a in A:
    ans[a-1] += 1

print(*ans,sep='\n')
### BUGGY CODE ###

N, Ma, Mb = map(int, input().split())

G = []
for i in range(N):
 a, b, c = map(int, input().split())
 G.append( (a,b,c) )

M = 401
INF = 1000000000
dp = [INF] * (M * M)
dp[0] = 0
for a, b, c in G:
  for i in reversed(range(0, M - a)):
    for j in reversed(range(0, M - b)):
      dp[(i+a)*M+(j+b)] = min(dp[(i+a)*M+(j+b)], dp[i*M+j] + c)

ans = INF
x = 1
while Ma * x < M and Mb * x < M:
  ans = min(ans, dp[Ma * x * M + Mb * x])
  x += 1
if ans >= INF:
  ans = -1
print(ans)


### FIXED CODE ###

N, Ma, Mb = map(int, input().split())

G = []
for i in range(N):
 a, b, c = map(int, input().split())
 G.append( (a,b,c) )

M = 1 + min(sum([ a for a, b, c in G ]),
            sum([ b for a, b, c in G ]) )
INF = 1000000000
dp = [INF] * (M * M)
dp[0] = 0
for a, b, c in G:
  i = M - a - 1
  while i >= 0:
    j = M - b - 1
    while j >= 0:
      dp[(i+a)*M+(j+b)] = min(dp[(i+a)*M+(j+b)], dp[i*M+j] + c)
      j -= 1
    i -= 1

ans = INF
x = 1
while Ma * x < M and Mb * x < M:
  ans = min(ans, dp[Ma * x * M + Mb * x])
  x += 1
if ans >= INF:
  ans = -1
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]

INF = 10**20
g = [[INF]*N for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    g[a][b] = g[b][a] = c
for i in range(N):
    g[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

h = [[N]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if g[i][j] <= L:
            h[i][j] = h[j][i] = 1
for i in range(N):
    h[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            h[i][j] = min(h[i][j], h[i][k] + h[k][j])

ans = []
for s,t in ST:
    s,t = s-1,t-1
    if h[s][t] == N:
        ans.append(-1)
    else:
        ans.append(h[s][t] - 1)
print(*ans, sep='\n')

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]

INF = float('inf')
dist1 = [[INF]*N for i in range(N)]
dist2 = [[INF]*N for i in range(N)]
for a,b,c in ABC:
    if c > L: continue
    a,b = a-1,b-1
    dist1[a][b] = dist1[b][a] = c
for i in range(N):
    dist1[i][i] = 0
    dist2[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            d = dist1[i][k] + dist1[k][j]
            if dist1[i][j] <= d: continue
            dist1[i][j] = d
for i in range(N):
    for j in range(N):
        if i==j: continue
        if dist1[i][j] <= L:
            dist2[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d = dist2[i][k] + dist2[k][j]
            if dist2[i][j] <= d: continue
            dist2[i][j] = d
ans = []
for s,t in ST:
    d = dist2[s-1][t-1]
    if d == INF:
        ans.append(-1)
    else:
        ans.append(d-1)
print(*ans, sep='\n')
### BUGGY CODE ###

import itertools
#import math
#from collections import deque

n=int(input())
s=list(input())

t=s[:n][::-1]
u=s[n:]
dic=dict()
for i in itertools.product(range(2),repeat=n):
	t_=[[] for _ in range(2)]
	u_=[[] for _ in range(2)]
	for j in range(n):
		t_[i[j]].append(t[j])
		u_[i[j]].append(u[j])
	t0=tuple(t_[0])
	t1=tuple(t_[1])
	u0=tuple(u_[0])
	u1=tuple(u_[1])
	if (t0,t1) not in dic:
		dic[(t0,t1)]=[1,0]
	else:
		dic[(t0,t1)][0]+=1
	if (u0,u1) not in dic:
		dic[(u0,u1)]=[0,1]
	else:
		dic[(u0,u1)][1]+=1

ans=0
for i in dic.keys():
	ans+=dic[i][0]*dic[i][1]
print(ans)



### FIXED CODE ###

import itertools
#import math
#from collections import deque

n=int(input())
s=input()

t=s[:n][::-1]
u=s[n:]
dic=dict()
for i in itertools.product(range(2),repeat=n):
	t_=[""]*2
	u_=[""]*2
	for j in range(n):
		t_[i[j]]+=t[j]
		u_[i[j]]+=u[j]
	if (t_[0],t_[1]) not in dic:
		dic[(t_[0],t_[1])]=[1,0]
	else:
		dic[(t_[0],t_[1])][0]+=1
	if (u_[0],u_[1]) not in dic:
		dic[(u_[0],u_[1])]=[0,1]
	else:
		dic[(u_[0],u_[1])][1]+=1

ans=0
for i in dic.keys():
	ans+=dic[i][0]*dic[i][1]
print(ans)
### BUGGY CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

ans=0
for i in range(n):
  for j in range(i,n):
    if abs(j-i) == a[i]+a[j]:
      ans+=1

print(ans)

### FIXED CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

ans=0

nums = dict()

for i in range(n):
  num_i = i+a[i]
  if num_i not in nums:
    nums[num_i]=0
  nums[num_i]+=1

for j in range(n):
  num_j = j-a[j]
  if num_j in nums:
    ans+=nums[num_j]

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

N,A,B,K = map(int,input().split())
MOD = 998244353

def mul(a,b):
    return (a*b) % MOD

def pow(a,n): # a^n
    ret = 1
    mag = a
    while n > 0:
        if n & 1:
            ret = mul(ret, mag)
        mag = mul(mag, mag)
        n >>= 1
    return ret

def inv(a):
    return pow(a, MOD-2)

fac = [1]
#fac_inv = [1]
for n in range (1,N+10):
    f = mul(fac[n-1], n)
    fac.append(f)
#    fac_inv.append(inv(f))

mem = {}
def ncr(n,r):
    if (n,r) in mem:
        return mem[(n,r)]
    else:
        ret = mul(mul(fac[n], inv(fac[n-r])), inv(fac[r]))
        if len(mem) <= 10**5:
            mem[(n,r)] = ret
        return ret

ans = 0
for a in range(N+1):
    if a*A > K: break
    rem = K-a*A
    if rem%B: continue
    b = rem//B
    for green in range(min(a,b) + 1):
        red = a - green
        blue = b - green
        if red + green + blue > N: continue
        tmp = 1
        tmp = mul(tmp, ncr(N, red+green+blue))
        tmp = mul(tmp, ncr(red+green+blue, green+blue))
        tmp = mul(tmp, ncr(green+blue, blue))
        ans += tmp
print(ans % MOD)

### FIXED CODE ###

N,A,B,K = map(int,input().split())
if A<B: A,B = B,A
MOD = 998244353

def mul(a,b):
    return (a*b) % MOD

def pow(a,n): # a^n
    ret = 1
    mag = a
    while n > 0:
        if n & 1:
            ret = mul(ret, mag)
        mag = mul(mag, mag)
        n >>= 1
    return ret

def inv(a):
    return pow(a, MOD-2)

fac = [1]
fac_inv = [1]
for n in range (1,N+10):
    f = mul(fac[n-1], n)
    fac.append(f)
    fac_inv.append(inv(f))

mem = [0] * (N+1)
def ncr(n,r):
    if mem[r] > 0:
        return mem[r]
    else:
        ret = mul(mul(fac[n], fac_inv[n-r]), fac_inv[r])
        mem[r] = ret
        return ret

ans = 0
for a in range(N+1):
    if a*A > K: break
    rem = K-a*A
    if rem%B: continue
    b = rem//B
    if b > N: continue
    ans += mul(ncr(N,a), ncr(N,b))
print(ans % MOD)
### BUGGY CODE ###

count = int(input())
numbers = map(int, input().split(' '))

counter = 0
while True:
  tmp = 0
  for item in numbers:
    tmp += item % 2
  if tmp > 0:
    break
  counter += 1
  numbers = [item / 2 for item in numbers]

print(counter)

### FIXED CODE ###

count = int(input())
numbers = [int(num) for num in input().split()]

counter = 0
while True:
  tmp = 0
  for item in numbers:
    tmp += item % 2
  if tmp > 0:
    break
  counter += 1
  numbers = [item / 2 for item in numbers]
print(counter)
### BUGGY CODE ###

from collections import deque


def main():
    K = int(input())
    q = deque([(1, 1)])
    visited = [False] * K
    while len(q):
        n, s = q.popleft()
        if visited[n % K]:
            continue
        visited[n % K] = True
        if n % K == 0:
            print(s)
            return
        q.appendleft((n*10, s))
        q.append((n+1, s+1))


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    K = int(input())
    q = deque([(1, 1)])
    visited = [False] * K
    while len(q):
        n, s = q.popleft()
        if visited[n]:
            continue
        visited[n] = True
        if n == 0:
            print(s)
            return
        q.appendleft((n*10 % K, s))
        q.append(((n+1) % K, s+1))


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

n = int(input())
s = '0' + input() + '0'
ans = n
for i in range(1,n+1):
    ans = min(ans, s[:i].count('W') + s[i+1:].count('E'))
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
cum = [0]*(n+1)
for i in range(1,n+1):
    cum[i] = cum[i-1]
    if s[i-1] == 'E':
        cum[i] += 1
cnt = n
for i in range(1,n+1):
    cnt = min(cnt, (i-1)-cum[i-1]+cum[n]-cum[i])
print(cnt)
### BUGGY CODE ###

N, M = map(int, input().split())
tmp = []
PY = [[] for _ in range(N + 1)]
PY_sorted = [[] for _ in range(N + 1)]

for i in range(M):
    p, y = map(int, input().split())
    tmp.append([p, y])
    PY[p].append(y)

for i in range(1, N + 1):
    PY_sorted[i] = sorted(PY[i])

for prefecture, year in tmp:
    text = ""
    text += "%06d" % prefecture
    text += "%06d" % (PY_sorted[prefecture].index(year) + 1)
    print(text)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
PY = [[] for _ in range(N + 1)]

for i in range(M):
    p, y = map(int, input().split())
    PY[p].append((y, i))

ans = []

for pre_id, info in enumerate(PY):
    info.sort()
    for i in range(len(info)):
        ans.append((info[i][1], "%06d" % pre_id, "%06d" % (i + 1)))

ans.sort()
for i, x, y in ans:
    print(str(x) + str(y))
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N, Q = map(int, input().split())
C = list(map(int, input().split()))

div = max(int(Q**.5), 1)
B = N // div

Qs = []
for i in range(Q):
	l, r = map(lambda s: int(s)-1, input().split())
	Qs.append((l, r+1, i))

Qs.sort(key=lambda v: (v[0]//B, v[1] ^ -(v[0]//B & 1)))

cnt = [0] * (N+1)
diff = 0

ans = [-1] * Q

left, right = 0, 0

def add(i):
	global cnt, diff
	x = C[i]
	cnt[x] += 1
	if cnt[x] == 1:
		diff += 1

def remove(i):
	global cnt, diff
	x = C[i]
	cnt[x] -= 1
	if cnt[x] == 0:
		diff -= 1

for l, r, i in Qs:
	while right < r:
		add(right)
		right += 1

	while r < right:
		right -= 1
		remove(right)

	while left < l:
		remove(left)
		left += 1

	while l < left:
		left -= 1
		add(left)

	ans[i] = diff

print('\n'.join(map(str, ans)))


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N, Q = map(int, input().split())
C = list(map(int, input().split()))

by_R = [[] for _ in range(N+1)]
for i in range(Q):
	l, r = map(lambda s: int(s)-1, input().split())
	by_R[r+1].append((l, i))

s = [0] * N
def update(pos, dif):
	while pos < N:
		s[pos] += dif
		pos |= pos + 1

def query(pos):
	res = 0
	while pos > 0:
		res += s[pos-1]
		pos &= pos - 1
	return res

diff = 0
ans = [-1] * Q
last = [-1] * (N+1)

for i, v in enumerate(C):
	if last[v] != -1:
		update(last[v], -1)
	else:
		diff += 1

	update(i, 1)
	last[v] = i

	for l, j in by_R[i+1]:
		ans[j] = diff - query(l)

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

mod = 10**9+7

def kaizyou(x):
    y = 1
    while x != 0:
        y *= x
        x -= 1
    return y%mod


N , M = map(int, input().split())
if abs(N-M) >= 2:
    ans = 0
elif N == M:
    ans = 2 * kaizyou(N) ** 2
elif N > M:
    ans = N * kaizyou(M) ** 2
else:
    ans = M * kaizyou(N) ** 2
print(ans%mod)

### FIXED CODE ###

mod = 10**9+7

def kaizyou(x):
    y = 1
    for i in range(2, x+1):
        y = (y*i)%mod
    return y


N , M = map(int, input().split())
if abs(N-M) >= 2:
    ans = 0
elif N == M:
    ans = 2 * kaizyou(N) ** 2
elif N > M:
    ans = N * kaizyou(M) ** 2
else:
    ans = M * kaizyou(N) ** 2
print(ans%mod)