Harryxun/stf_run huggingface dataset:
n=int(input())
a=list(map(int,input().split()))

ans=1

d={}

mod=10**9+7

for i in range(n):
  if a[i]==0:
    if 0 not in d:
      d[0]=1
      ans*=3
    else:
      if d[0]==1:
        d[0]=2
        ans*=2
      else:
        d[0]=3
      
  else:
    if a[i] not in d:
      d[a[i]]=1
      ans*=d[a[i]-1]
    else:
      if d[a[i]]==1:
        d[a[i]]=2
        ans*=d[a[i]-1]-1
      else:
        d[a[i]]=3
        ans*=1
        
  ans%=mod
  
print(ans)

### FIXED CODE ###

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

ans=1

d={}

ch=0

mod=10**9+7

for i in range(n):
  if a[i]==0:
    if 0 not in d:
      d[0]=1
      ans*=3
    else:
      if d[0]==1:
        d[0]=2
        ans*=2
      elif d[0]==2:
        d[0]=3
      else:
        ch+=1
        break
      
  else:
    if a[i] not in d:
      d[a[i]]=1
      if a[i]-1 not in d:
        ch+=1
        break
      else:
        ans*=d[a[i]-1]
    else:
      if d[a[i]]==1:
        d[a[i]]=2
        if a[i]-1 not in d:
          ch+=1
          break
        else:
          if d[a[i]-1]>=2:
            ans*=d[a[i]-1]-1
          else:
            ch+=1
            break
      elif d[a[i]]==2:
        d[a[i]]=3
        if a[i]-1 not in d:
          ch+=1
          break
        else:
          if d[a[i]-1]>=3:
            ans*=1
          else:
            ch+=1
            break
      else:
        ch+=1
        break
        
  ans=(ans%mod)
  
if ch==0:
  print(ans)
else:
  print(0)
a = input()
s = 0
for i in (l,len(a)):
  if a[i-1] ==a[i]:
          s+=1
if s>=3:
          print("Yes")
else:print("No")

### FIXED CODE ###

a=list(input())
print('Yes' if((a[0]==a[1]==a[2]) or(a[1]==a[2]==a[3])) else 'No')
s=input()

count=0
for i in range(len(s)-2):
    if s[i]==s[i+1] or s[i]==s[i+2] or s[i+1]=s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

### FIXED CODE ###

s=input()
if len(s)==2:
    if len(set(s))==1:
        print(1,2)
        exit()
    else:
        print(-1,-1)
        exit()
        
for i in range(len(s)-2):
    a=s[i:i+3]
    if len(set(a))<=2 :
        print(i+1,i+3)
        exit()
print(-1,-1)
input_num = input()
input_num = int(input_num)
for i in range(1,10,1):
  flag = False
  for j in range(1,10,1):
    if input_num == i * J:
      print("Yes")
      flag = True
      break
  if flag:
    break
if not flag:
	print("No")

### FIXED CODE ###

input_num = input()
input_num = int(input_num)
for i in range(1,10,1):
  flag = False
  for j in range(1,10,1):
    if input_num == i * j:
      print("Yes")
      flag = True
      break
  if flag:
    break
if not flag:
	print("No")
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
diffs = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
max_diff = 0
for diff in diffs:
    max_diff= max(max_diff, max(diff))
r_k = max_diff*(H+W)
dp = [[[False] * r_k for _ in range(W+1)] for _ in range(H+1)]
for i in range(H+1):
    dp[i][0][0] = True
for j in range(W+1):
    dp[0][j][0] = True
for i in range(H):
    for j in range(W):
        diff = diffs[i][j]
        for k in range(r_k):
            dp[i + 1][j + 1][abs(k - diff)] = dp[i + 1][j][k] or dp[i][j +
                                                                       1][k] or dp[i + 1][j + 1][abs(k - diff)]
            if k + diff < r_k:
                dp[i + 1][j + 1][k + diff] = dp[i + 1][j][k] or dp[i][j +
                                                                      1][k] or dp[i + 1][j + 1][k+diff]

for k in range(r_k):
    if dp[H][W][k]:
        print(k)
        break


### FIXED CODE ###

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
diffs = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
max_diff = 0
for diff in diffs:
    max_diff = max(max_diff, max(diff))
r_k = max_diff*(H+W)//2+1
dp = [[[False] * r_k for _ in range(W)] for _ in range(H)]
dp[0][0][0] = True
for i in range(H):
    for j in range(W):
        diff = diffs[i][j]
        dp_ = dp[i][j]
        if j < W-1:
            dpj = dp[i][j + 1]
            for k in range(r_k):
                if dp_[k] == True:
                    dpj[abs(k - diff)] = True
                    if k+diff<r_k:
                        dpj[k + diff] = True
        if i < H - 1:
            dpi = dp[i + 1][j]
            for k in range(r_k):
                if dp_[k] == True:
                    dpi[abs(k-diff)] = True
                    if k+diff < r_k:
                        dpi[k + diff] = True

ans = pow(80, 3)
diff = diffs[H-1][W-1]
for k, flg in enumerate(dp[H - 1][W - 1]):
    if flg:
        ans = min(ans, abs(k-diff), k+diff)
print(ans)
x, a, b = input().split()

if abs(x-a) > abs(x-b):
  print(A)
else:
  print(B)

### FIXED CODE ###

x, a, b = map(int, input().split())
 
if abs(x-a) > abs(x-b):
  print("B")
else:
  print("A")
mport itertools
import math

def solve():
  s = input()
  if s == "ABC":
    print("ARC")
  else:
    print("ABC")
  return 0

 
if __name__ == "__main__":
  solve()


### FIXED CODE ###

def solve():
  s = input()
  if s == "ABC":
    print("ARC")
  else:
    print("ABC")
  return 0

 
if __name__ == "__main__":
  solve()
N=int(input())
P=[int(input()) for _ in range(N)]
Q=[0 for _ in range(N)]

if N=1:
    print(1)
else:
    for i in range(N):
        Q[P[i]-1]=i

    cnt=0
    tmp=0
    for i in range(N-1):
        if Q[i]<Q[i+1]:
            cnt+=1
        else:
            if tmp<cnt+1:
                tmp=cnt+1
            cnt=0

    print(N-tmp)


### FIXED CODE ###

N=int(input())
P=[int(input()) for _ in range(N)]
Q=[0 for _ in range(N)]

for i in range(N):
    Q[P[i]-1]=i

cnt=0
tmp=0
for i in range(N-1):
    if Q[i]<Q[i+1]:
        cnt+=1
    else:
        if tmp<cnt+1:
            tmp=cnt+1
        cnt=0

if tmp==0:
    tmp=cnt+1

print(N-tmp)
s = input(:)
w = input(:)
S = int(s)
W = int(w)
if S<=W:
  print("unsafe")
else:
  print("safe")

### FIXED CODE ###

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

if S <= W:
    print("unsafe")
else:
    print("safe")
N = list(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
if int(N[2]) in hon:
    print("hon")
elif int(N[2]) in pon:
    print("pon")
else:
    print("bon")

### FIXED CODE ###

N = list(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
if int(N[-1]) in hon:
    print("hon")
elif int(N[-1]) in pon:
    print("pon")
else:
    print("bon")
n = int(input())
a = list(map(int,input().split()))
se = set(n)

if len(se) == len(a):
  print('YES')
else:
  print('NO')

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
se = set(a)
 
if len(se) == len(a):
  print('YES')
else:
  print('NO')
n, k = map(int, input().split())
l = list(map(int, input().split()))
start = 1
seen = []
for i in range(k):
	start = l[start-1]
	if start in seen:
		loop_len = len(seen) - seen.index(start)
		r = (k-i-1)%loop_len
		goal = seen[-loop_len:][r]
		break
	seen.append(start)
print(goal)

### FIXED CODE ###

n,k = map(int,input().split())
*l, = map(int,input().split())
seenl = [1]
seen = {1}
temp=1
for i in range(k):
  temp=l[temp-1]
  if temp in seen:
    lenloop = len(seenl)-seenl.index(temp)
    r = (k-i-1)%lenloop
    temp = seenl[seenl.index(temp):][r]
    break
  seenl.append(temp)
  seen.add(temp)
print(temp)
n, t = map(int,input().split())
mydict = {}
for i in range(n):
	a, b = map(int,input().split())
	mydict.setdefault(a, b)
sortedDict = sorted(mydict.items())
k = 0
for j in sortedDict:
	k += 1
	if j[1] <= t:
		print(j[0])
		break
	if k == len(sortedDict):
		print("TLE")


### FIXED CODE ###

n = int(input())
if n == 1:
	print("Hello World")
elif n == 2:
	a = int(input())
	b = int(input())
	print(a+b)
X,Y,Z,K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A, reverse = True)
B = sorted(B, reverse = True)
C = sorted(C, reverse = True)

ans = []

for i in range(min(K,X)):
  for j in range(min(K//i,Y)):
    for k in range(min(K//i//j,Z)):
      ans.append(A[i]+B[j]+C[k])
    
ans = sorted(ans, reverse=True)

for i in range(K):
  print(ans[i])
      


### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A, reverse = True)
B = sorted(B, reverse = True)
C = sorted(C, reverse = True)

ans = []

for i in range(min(K,X)):
  for j in range(min(K//(i+1),Y)):
    for k in range(min(K//(i+1)//(j+1),Z)):
      ans.append(A[i]+B[j]+C[k])
    
ans = sorted(ans, reverse=True)

for i in range(K):
  print(ans[i])
def main():
    A, B, C, K = map(int, input().split())
    li = [1] * A
    li += ([0] * B)
    li += ([-1] * C)
    print(sum(li[:K]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    A, B, _, K = map(int, input().split())
    if A > K:
        print(K)
        quit()
    print(A - max([0, K - A - B]))


if __name__ == "__main__":
    main()
n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
a0 = a[0]
N = int(a0[0])
K = int(a0[1])
b =[]
for i in range(K):
    di = int(a[2i+1])
    bi = a[2i+2]
for l in range(N):
    for i in range(K):
        for k in range(di):
            if not bi[k] == l:
            	b.append(l)
print(len(b))

### FIXED CODE ###

N, K = map(int, input().split())
d = []
A = []
s = [1] * N
for k in range(K):
  d.append(int(input()))
  A.append([int(i) for i in input().split()])
  
for k in range(K):
  for n in range(1, N+1):
    if n in A[k]:
      if s[n-1] == 1:
        s[n-1] = 0
print(sum(s))
N = int(input())
A = sorted((map(int,input().split())))
A_Max = A[-1]
B = [True]*A_Max

for i in range(N):
    if B[A[i]]:
        for j in range(2, A_Max):
            if A[i]*j > A_Max:
                break
            B[A[i] * j] = False

ans = 0
for i in range(N):
    if B[A[i]]:
            B[A[i]] = False
            ans += 1
        
print(ans)



### FIXED CODE ###

N = int(input())
A = sorted((map(int,input().split())))
a_Max = A[-1]
B = [0]*a_Max

for a in A:
    if B[a-1] == 0:
        B[a-1] = 1
        for j in range(2,a_Max+1):
            if a*j > a_Max:
                break
            B[a*j-1] = 2
    elif B[a-1] == 1:
        B[a-1] = 2
            
ans = 0
for b in B:
    if b == 1:
        ans += 1

print(ans)
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

T=input()

T.replace("?","D")

print(T.count("D")+T.count("PD")


### FIXED CODE ###

import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

T=input()

T=T.replace('?','D')

print(T)
while 1:
    m,f,r=map(int,raw_input().split())
    #m:Midterm exam  f:final exam r:Retest
    score=m+f
    if m == -1 or f == -1
        if r == -1 :
            break
        else: print 'F'
    else :
        if score >= 80:
            print 'A'
        else:
            if score >= 65:
                print 'B'
            else:
                if score >= 50 or (score >= 30 and r >= 50):
                    print 'C'
                else:
                    if score >= 30:
                        print 'D'
                    else:
                        print 'F'

### FIXED CODE ###

while 1:
    m,f,r=map(int,raw_input().split())
    #m:Midterm exam  f:final exam r:Retest
    score=m+f
    if m == -1  or  f ==  -1 :
        if m == -1 and f == -1 and r == -1 :
            break
        else: print 'F'
    elif score >= 80:
        print 'A'
    elif score >= 65:
        print 'B'
    elif score >= 50 or (score >= 30 and r >= 50):
        print 'C'
    elif score >= 30:
        print 'D'
    else:
        print 'F'
n = int(input())
P = list(map(int, input().split()))

ans = 0
Cnt = []
for idx, p in enumerate(P, 1):
    if idx == p:
        Cnt.append(idx)
#print(Cnt)
if len(Cnt) == 0:
    ans = 0

elif len(Cnt) == 2:
    ans += Cnt[1] - Cnt[0]

elif len(Cnt) %2:
    for i in range(1, len(Cnt), 2):
        if i == 0:
            ans += Cnt[i+1] - Cnt[i]
        elif i == len(Cnt)-1:
            ans += Cnt[i] - Cnt[i-1]
        else:
            ans += min(Cnt[i] - Cnt[i-1], Cnt[i+1] - Cnt[i])
else:
    for i in range(0, len(Cnt), 2):
        if i == 0:
            ans += Cnt[i+1] - Cnt[i]
        elif i == len(Cnt)-1:
            ans += Cnt[i] - Cnt[i-1]
        else:
            ans += min(Cnt[i] - Cnt[i-1], Cnt[i+1] - Cnt[i])

print(ans)

########################

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

Cnt = []
cnt = 0
ans = 0
for idx, p in enumerate(P, 1):
    if idx == p:
        Cnt.append(idx)
        cnt += 1
    else:
        cnt = 0
    if cnt == 2:
        ans -= 1
        cnt = 0

ans += len(Cnt)
print(ans)


### FIXED CODE ###

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

Cnt = []
cnt = 0
ans = 0
for idx, p in enumerate(P, 1):
    if idx == p:
        Cnt.append(idx)
        cnt += 1
    else:
        cnt = 0
    if cnt == 2:
        ans -= 1
        cnt = 0

ans += len(Cnt)
print(ans)
l = input().split()
N = l[0]
M = l[1]
ans = 1

# N = 100000                                                                                                                                                                                                                                                                          
# M = 100000                                                                                                                                                                                                                                                                          

if N == (M + 1) or N == (M - 1):
    for n in range(1, N+1):
        ans *= n
        ans %= 1e9 + 7
    for m in range(1, M+1):
        ans *= m
        ans %= 1e9 + 7
elif N == M:
    for n in range(1, N+1):
        ans *= n
        ans %= 1e9 + 7
    for m in range(1, M+1):
        ans *= m
        ans %= 1e9 + 7
    ans *= 2
    ans %= 1e9 + 7
else:
    ans = 0

print int(ans)

### FIXED CODE ###

import sys

N, M = (int(i) for i in raw_input().split())
ans = 1                                                                                                                                                                                                                                                                     

if __name__ == '__main__':
    if N == (M + 1) or N == (M - 1):
        for n in range(1, N+1):
            ans *= n
            ans %= 1e9 + 7
        for m in range(1, M+1):
            ans *= m
            ans %= 1e9 + 7
    elif N == M:
        for n in range(1, N+1):
            ans *= n
            ans %= 1e9 + 7
        for m in range(1, M+1):
            ans *= m
            ans %= 1e9 + 7
        ans *= 2
        ans %= 1e9 + 7
    else:
        ans = 0

    print int(ans)
# -*- coding: utf-8 -*-
import sys
N,M=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
BC=[]   #カードの値、枚数
for _ in range(M):
    b,c=map(int, sys.stdin.readline().split())
    BC.append([c,b])

A.sort()
BC.sort(reverse=True)

NEW_A=[]
idx=0   #BCリストのインデックス
for a in A:
    new_value=BC[idx][0]
    if a<new_value:
        NEW_A.append(new_value)
        BC[idx][1]-=1   #個数を-1
    else:
        NEW_A.append(a)

    if BC[idx][1]==0:
        idx+=1

print sum(NEW_A)

### FIXED CODE ###

import sys

N,M=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
A.sort()

B=[ map(int, sys.stdin.readline().split()) for _ in range(M)] 
B.sort(key=lambda x: x[1], reverse=True)

i=0

for b,c in B:
	for i in range(i,N):
		if A[i]<c and 0<b:
			A[i]=c
			b-=1
		if b==0:
			break
	i+=1

print sum(A)
n=int(input())
a=map(int,input().split())
if len(a)==list(set(a)):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

print("YES" if len(a)==len(list(set(a))) else "NO")
N=int(input())
A=list(map(int,input().split()))

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(N):
        if (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
print(N-1-R+L+(R-L)//2)
#print(L,R)

for i in range(N-1,R,-1):
    print(i+1)

for i in range(L):
    print(1)

A=A[L:R+1]
for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
print(2)


### FIXED CODE ###

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

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(i,N):
        if j==i:
            test=A[i]
            if eval<test:
                eval=test
                L,R=i,i
        elif (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
print(N-1-R+L+(R-L)//2)
#print(L,R)

for i in range(N-1,R,-1):
    print(i+1)

for i in range(L):
    print(1)

for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
        
if L!=R:
    print(2)
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


n = ni()
G = [list() for _ in range(n)]
for _ in range(n-1):
  a, b = nm()
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
  
  
mod = 10**9 + 7
dub = [1]*(n+1)
for i in range(n):
  dub[i+1] = dub[i] * 2
  if dub[i+1] > mod:
    dub[i+1] -= mod
    
size = [1]*n
def dfs_depandsize(tree,v,p):
    for x in tree[v]:
        if x == p:
            continue
        size[v] += dfs_depandsize(tree,x,v)
    return size[v]
dfs_depandsize(G, 0, -1)
ans = 0
for v in range(n):
  c = 0
  res = 1
  for x in G[v]:
    if size[x] < size[v]:
      c += size[x]
      res += dub[size[x]] - 1
  res += dub[n-1-c] - 1
  res %= mod
  ans = (ans + dub[n-1] - res) % mod
print(ans * pow(dub[n], mod-2, mod) % mod)

### FIXED CODE ###

import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


n = ni()
G = [list() for _ in range(n)]
for _ in range(n-1):
  a, b = nm()
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
  
  
mod = 10**9 + 7
dub = [1]*(n+1)
for i in range(n):
  dub[i+1] = dub[i] * 2
  if dub[i+1] > mod:
    dub[i+1] -= mod
    
size = [-1]*n
q = [0]
while q:
  v = q[-1]
  if size[v] < 0:
    for x in G[v]:
      if size[x] < 0:
        q.append(x)
    size[v] = 0
  else:
    size[v] = 1
    for x in G[v]:
      size[v] += size[x]
    q.pop()

ans = 0
for v in range(n):
  c = 0
  res = 1
  for x in G[v]:
    if size[x] < size[v]:
      c += size[x]
      res += dub[size[x]] - 1
  res += dub[n-1-c] - 1
  res %= mod
  ans = (ans + dub[n-1] - res) % mod
print(ans * pow(dub[n], mod-2, mod) % mod)
While True:
    H, W = map(int, raw_input().split())
    if H == W == 0:
        break
    print "#" * W
    for i in xrange(H -2):
        print "#" + "." *(W-2) + "#"
    print "#" * W
    print

### FIXED CODE ###

while True:
    H, W = map(int, raw_input().split())
    if H == W == 0:
        break
    print "#" * W
    for i in xrange(H -2):
        print "#" + "." *(W-2) + "#"
    print "#" * W
    print
import math

N = int(input())

for i in reverse(range(int(math.sqrt(N))+1)):
  if N % i == 0:
    print(i-1+(N//i)-1)
    break

### FIXED CODE ###

import math
 
N = int(input())
 
for i in reversed(range(int(math.sqrt(N))+1)):
  if N % i == 0:
    print(i-1+(N//i)-1)
    break
D,N = map(int,input().split())

if D == 0:
    pritn(N)
elif D == 1:
    print(N * 100)
else:
    print(N * 10000)

### FIXED CODE ###

d, n = map(int, input().split())
print((n + n // 100) * 100 ** d)
import numpy as np

def main():
    N, M, Q = [int(n) for n in input().split()]
    imos = [[0] * N for _ in range(N)]
    for i in range(M):
        l, r = [int(i)-1 for i in input().split()]
        imos[l][r]+=1
    # print(imos)
    for h in range(N):
        for w in range(1, N):
            imos[h][w] += imos[h][w-1]
    for h in reversed(list(range(1, N))):
        for w in range(N):
            imos[h-1][w] += imos[h][w]
    # print(imos)
    ans = [0]*Q
    for q in range(Q):
        ql, qr = [int(i)-1 for i in input().split()]
        ans[q] = imos[ql][qr]
    for a in ans:
        print(a)



if __name__ == "__main__":
    main()

### FIXED CODE ###


def main():
    N, M, Q = [int(n) for n in input().split()]
    imos = [[0] * N for _ in range(N)]
    for i in range(M):
        l, r = [int(i)-1 for i in input().split()]
        imos[l][r]+=1
    # print(imos)
    for h in range(N):
        for w in range(1, N):
            imos[h][w] += imos[h][w-1]
    for h in reversed(list(range(1, N))):
        for w in range(N):
            imos[h-1][w] += imos[h][w]
    # print(imos)
    ans = [0]*Q
    for q in range(Q):
        ql, qr = [int(i)-1 for i in input().split()]
        ans[q] = imos[ql][qr]
    for a in ans:
        print(a)



if __name__ == "__main__":
    main()
x, n= input().split()
x = int(x)
n = int(n)

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1
dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) < dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
            
print(ret)

### FIXED CODE ###

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

array = [[0]]*200
if n == 0:
    print(x)
else:
    for i in range(200):
        array[i] = 0
    tmp = input().split(' ')
    for i in range(n):
        array[int(tmp[i])] = 1
    
    dif_tmp = 999
    ret = 999
    for i in range(200):
        if array[199-i] == 0:
            if abs(x-(199-i)) <= dif_tmp:
                ret = 199-i
                dif_tmp = abs(x-(199-i))
    for i in range(1,100):
        if abs(x+i) <= dif_tmp:
            ret = -i
            dif_tmp = abs(x+i)
    print(ret)
s = list(input())
head = int(s[0] + s[1])
tail = int(s[2] + s[3])

if (0 < head < 13) and (0 < tail < 13):
    print('AMBIGUOUS')
elif 0 < tail < 13:
    print('YYMM')
elif 0 < head < 13:
    print('MMYY')
else:
    print('NA')

### FIXED CODE ###

n, k = map(int, input().split())
s = list(input()) #文字列はそのままだとイミュータブル
s[k-1] = chr(ord(s[k-1]) + 32)
print("".join(s))
N,M,X=map(int,input().split())
Mlist=list(map(int,input().split()))
Nlist=[0]*N
for a in Mlist:
  Nlist[a]=1

a=Nlist[X:]
b=Nlist[:X]
print(min([a,b])

### FIXED CODE ###

# coding: utf-8
# Your code here!

N,M,X=map(int,input().split())
Mlist=list(map(int,input().split()))
Nlist=[0]*N
for a in Mlist:
  Nlist[a]=1

a=sum(Nlist[X:])
b=sum(Nlist[:X])
print(min([a,b]))