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

import itertools

s = list(str(input()))
t = list(str(input()))
s_all, t_all = [], []

for i in itertools.permutations(s):
    s_all.append("".join(i))

for j in itertools.permutations(t):
    t_all.append("".join(j))

for k in s_all:
    for l in t_all:
        if k < l:
            print("Yes")
            quit(0)
        else:
            continue

print("No")


### FIXED CODE ###

s = "".join(sorted(input()))
t = "".join(sorted((input()))[::-1])
if s < t:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

from collections import Counter
N = input()
S=0
mod_count=[0]
ans=0
i=0
for X in N[::-1]:
  S = (int(X)*(10**(i))) % 2019
  S=mod_count[i]+S
  mod_count.append(S%2019)
  i+=1

c = Counter(mod_count)
ans = sum(Y * (Y-1)/2 for Y in c.values())
print(int(ans))

### FIXED CODE ###

from collections import Counter
N = input()
S=0
mod_count=[0]
ans=0
i=0
for X in N[::-1]:
  S = int(X)*pow(10,i,2019) % 2019
  S=mod_count[i]+S
  mod_count.append(S%2019)
  i+=1

c = Counter(mod_count)
ans = sum(Y * (Y-1)/2 for Y in c.values())
print(int(ans))
### BUGGY CODE ###

S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i])*10**(N-i-1))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = cnt[0]
for i in range(1,p):
  if cnt[i] > 0:
    ans += cnt[i]-1

print(ans)

### FIXED CODE ###

S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = 0
for i in range(p):
  m = cnt[i]
  if i == 0 and m > 0:
    ans +=  (m*(m+1))//2
  else:
    ans += (m*(m-1))//2
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [[0] * (N-1)]+[list(map(int,input().split())) for _ in range(N)]

idx = [0] * (N+1)
cnt = 0
day = 0
flag_max = [False] * (N+1)
while cnt != N:
    
    error = True
    flag =[False] * (N+1)
    looplist = [i for i in range(1,N+1) if not(flag_max[i])]
    
    for i in looplist:
        if (flag[i]):continue
        tmp = A[i][idx[i]]
        if (flag[tmp]):continue
    
        if A[tmp][idx[tmp]] == i:
            idx[tmp] = idx[tmp] + 1
            idx[i] = idx[i] + 1
            if idx[tmp] == N-1:
                flag_max[tmp] = True
                cnt += 1
            if idx[i] == N-1:
                flag_max[i] = True
                cnt += 1
            flag[i] = True
            flag[tmp] = True
            error = False
    if error:
        print(-1)
        sys.exit()
    
    day += 1
            
    
    
print(day)
    
    


### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [[0] * (N-1)]+[list(map(int,input().split())) for _ in range(N)]

idx = [0] * (N+1)
cnt = 0
day = 0
flag_max = [False] * (N+1)
while cnt != N:
    
    error = True
    flag =[False] * (N+1)
    looplist = [i for i in range(1,N+1) if not(flag_max[i])]
    
    for i in looplist:
        if (flag[i]):continue
        tmp = A[i][idx[i]]
        if (flag[tmp]):continue
    
        if A[tmp][idx[tmp]] == i:
            idx[tmp] = idx[tmp] + 1
            idx[i] = idx[i] + 1
            if idx[tmp] == N-1:
                flag_max[tmp] = True
                cnt += 1
            if idx[i] == N-1:
                flag_max[i] = True
                cnt += 1
            flag[i] = True
            flag[tmp] = True
            error = False
    if error:
        print(-1)
        sys.exit()
    
    day += 1
            

    if day > 10000:
        print(N*(N-1)//2)
        sys.exit()
    
    
print(day)
### BUGGY 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())) 
e=[]
d=[]
 
a.sort()
b.sort()
c.sort()
 
for i in range(1,x+1):
    for j in range(1,y+1):
        e.append(a[-i]+b[-j])
e.sort()

del e[:-k]
for i in range(1,len(e)+1):
    for j in range(1,z+1):
        d.append(e[-i]+c[-j])
        
d.sort()
for i in range(1,k+1):
    print(d[-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()))

ans1=[]
ans2=[]

for i in range(x):
    for j in range(y):
        ans1.append(a[i]+b[j])
ans1.sort()
ans1.reverse()

if len(ans1)>=k:
    del ans1[k:]
    
for i in range(len(ans1)):
    for j in range(z):
        ans2.append(ans1[i]+c[j])
ans2.sort()
ans2.reverse()

for i in range(k):
    print(ans2[i])
### BUGGY CODE ###

N,T = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]

dp0 = [{0:0} for i in range(N+1)]
dp1 = [{0:0} for i in range(N+1)]

for i,(a,b) in enumerate(AB):
    for k0,v0 in dp0[i].items():
        if k0 in dp0[i+1]:
            dp0[i+1][k0] = max(dp0[i+1][k0], v0)
        else:
            dp0[i+1][k0] = v0
        if k0+a < T:
            if k0+a in dp0[i+1]:
                dp0[i+1][k0+a] = max(dp0[i+1][k0+a], v0+b)
            else:
                dp0[i+1][k0+a] = v0+b
        if k0 in dp1[i+1]:
            dp1[i+1][k0] = max(dp1[i+1][k0], v0+b)
        else:
            dp1[i+1][k0] = v0+b
    for k1,v1 in dp1[i].items():
        if k1 in dp1[i+1]:
            dp1[i+1][k1] = max(dp1[i+1][k1], v1)
        else:
            dp1[i+1][k1] = v1
        if k1+a < T:
            if k1+a in dp1[i+1]:
                dp1[i+1][k1+a] = max(dp1[i+1][k1+a], v1+b)
            else:
                dp1[i+1][k1+a] = v1+b

print(max(dp1[-1].values()))

### FIXED CODE ###

N,T = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]

dp0 = {0:0}
dp1 = {0:0}

for i,(a,b) in enumerate(AB):
    _dp0 = {0:0}
    _dp1 = {0:0}
    for k0,v0 in dp0.items():
        if k0 in _dp0:
            _dp0[k0] = max(_dp0[k0], v0)
        else:
            _dp0[k0] = v0
        if k0+a < T:
            if k0+a in _dp0:
                _dp0[k0+a] = max(_dp0[k0+a], v0+b)
            else:
                _dp0[k0+a] = v0+b
        if k0 in _dp1:
            _dp1[k0] = max(_dp1[k0], v0+b)
        else:
            _dp1[k0] = v0+b
    for k1,v1 in dp1.items():
        if k1 in _dp1:
            _dp1[k1] = max(_dp1[k1], v1)
        else:
            _dp1[k1] = v1
        if k1+a < T:
            if k1+a in _dp1:
                _dp1[k1+a] = max(_dp1[k1+a], v1+b)
            else:
                _dp1[k1+a] = v1+b
    dp0 = _dp0
    dp1 = _dp1

print(max(dp1.values()))
### BUGGY CODE ###

from collections import deque
N, K = map(int, input().split())

H = deque(list(map(int, input().split())))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

dp = [float('inf')] * (N + max_K)
dp[0] = 0

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

dp = [float('inf')] * (N + max_K)
dp[0] = 0

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])
### BUGGY CODE ###

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a_s = sorted(a)
    ans = []
    for i in a_s:
        ans.append(a.index(i)+1)
    print(*ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = [None] * n
    for idx, ea in enumerate(a):
        ans[ea-1] = idx+1
    print(*ans)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

L,R = map(int,input().split())
lst = []

if L <= 2019 and R >= 2019:
    print(0)
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            lst.append((i*j)%2019)
    print(min(lst))


### FIXED CODE ###

import sys
input = sys.stdin.readline

L,R = map(int,input().split())
lst = []

if L <= 2019 and R >= 2019:
    print(0)
else:
    for i in range(L,R+1):
        if i % 2019 == 0:
            lst.append(0)
            break
        for j in range(i+1,R+1):
            if j % 2019 == 0:
                lst.append(0)
                break
            lst.append((i * j) % 2019)
        else:
            continue
        break
    print(min(lst))
### BUGGY CODE ###

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

m = 0

for x in reversed(range(max(1,n-b),n+1)):
    if m > (a*x) // b:
        break
    else:
        y = (a*x)//b - a * (x//b)
        if m < y:
            m = y

print(m)

### FIXED CODE ###

import math

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

m = 0
x = n

while x >= n-b:
    if m > (a*x) // b:
        break
    else:
        y =  math.floor((a * (x / b - math.floor(x / b))))
        if m < y:
            m = y
            x = b * math.floor(x / b) - 1
        else:
            x-=1  

print(m)
### BUGGY CODE ###

# 2019/12/27

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

L,U,R,D=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":continue
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

ans=0

for i in range(h,0,-1):
    for j in range(w,0,-1):
        if s[i][j]=="#":continue
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1
        lit=L[i][j]+U[i][j]+R[i][j]+D[i][j]-3
        ans=max(ans,lit)
print(ans)

### FIXED CODE ###

# 2019/12/27

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

L,U,R,D=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":continue
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

ans=0

for i in range(h,0,-1):
    for j in range(w,0,-1):
        if s[i][j]=="#":continue
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1
        lit=L[i][j]+U[i][j]+R[i][j]+D[i][j]-3
        ans=max(ans,lit)
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
min_v = float('inf')
for i in range(1,n):
    tmp1 = a[:i]
    tmp2 = a[i:]
    min_v = min(abs(sum(tmp1) - sum(tmp2)), min_v)

print(min_v)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
x = 0
y = sum(l)
xy = [10**15]*n
for i in range(n-1):
    x += l[i]
    y -= l[i]
    xy[i] = abs(x-y)
print(min(xy))
### BUGGY CODE ###

n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    b=str(input())
    if b in a:
        c[a.index(b)]+=1
    else:
        a.append(b)
        c.append(1)
t=max(c)
e=[]
for i in range(len(c)):
    if c[i]==t:
        e.append(a[i])
e.sort()
for i in range(len(e)):
    print(e[i])



### FIXED CODE ###

n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    b=str(input())
    a.append(b)
freq = {}
for item in a:
        if (item in freq):
            freq[item] += 1
        else:
            freq[item] = 1

t=0
b=[]
for items in freq.values():
    if items>t:
        t=items

for key,val in freq.items():
    if val==t:
        b.append(key)
b.sort()
for i in range(len(b)):
    print(b[i])
### BUGGY CODE ###

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

print(ans)

### FIXED CODE ###

n = int(input())
s = input()
ans = 10**10
s_E = [0]
s_W = [0]
e = 0
w = 0
for i in range(n):
    if s[i] == 'E':
        e += 1
    else:
        w += 1
    s_E.append(e)
    s_W.append(w)

for i in range(n):
    ans = min(ans,s_W[i]+s_E[-1]-s_E[i+1])

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

n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

dp = [[0,0] for _ in range(n+1)]

check = True
while(check):
    check = False
    for i in range(m):
        x, y  =xy[i]
        if(dp[x][1] < dp[y][1]+1):
            dp[x][1] =  dp[y][1]+1
            check = True
        if(dp[y][0] < dp[x][0]+1):
            dp[y][0] = dp[x][0]+1
            check = True

ans = 0
for i in range(n+1):
     ans = max(ans, dp[i][0])

print(ans)

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

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

xy_dict = {}
for i in range(1,n+1):
    xy_dict[i] = []

for i in range(m):
    x,y = map(int, input().split())
    xy_dict[x].append(y)

dp = [-1]*(n+1)
dp[0] = 0

def get_longest(x):
    global dp

    if( dp[x] >= 0):
        return dp[x]
    else:
        y_list = xy_dict[x]
        temp_max = 0
        for y in y_list:
            temp_max = max(temp_max, get_longest(y)+1)

        dp[x] = temp_max
        return temp_max

ans = 0
for i in range(1,n+1):
    ans = max(ans, get_longest(i))

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

N = int(input())

L = []
for i in range(N):
    L.append(sorted(input().strip()))

Sum = 0
for i in range(N):
    if i == N - 1:
        break
    
    for j in range(i+1, N):
        if L[i] == L[j]:
            #print(L[i], L[j])
            Sum += 1

print(Sum)
        


### FIXED CODE ###

import sys

N = int(input())
L = {}
count = 0
for i in range(N):
    A = ''.join(sorted(sys.stdin.readline().strip()))
    if A not in L:
        L[A] = 1
    else:
        count += L[A]
        L[A] += 1

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

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

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
p = 1
if A.count(0)>0:
    p = 0
for i in range(N):
    p = p * A[i]
    if p > 10**18:
        p=-1
        break
    if p == 0:
        break
print(p)
### BUGGY CODE ###

n = int(input())
a_i = input().split()
ans = ""
for i in range(len(a_i)):
  ans += str(a_i.index(str(i+1)) + 1)
  if i != (len(a_i) - 1):
    ans += " "
print(ans)

### FIXED CODE ###

n = int(input())
a_i = input().split()
ans = ""
ans_l = [0] * n
for i in range(len(a_i)):
  ans_l[int(a_i[i])-1] = i + 1
for j in range(n):
  ans += str(ans_l[j])
  if j != (n - 1):
    ans += " "
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
  memo = a[i]
  a[i] = 0
  print(max(a))
  a[i] = memo

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

reverse_A = sorted(A, reverse=True)
max1 = reverse_A[0]
max2 = reverse_A[1]

for a in A:
  if a == max1:
    print(max2)
  else:
    print(max1)
### BUGGY CODE ###

def is_prime(x):
    # Perform prime number discrimination for odd numbers of 3 or more.
    return pow(2, x - 1, x) == 1

def solve():
    n = int(input())
    ans = n
    if n % 2 == 0:
        ans -= ans // 2
        while n % 2 == 0:
            n //= 2
    d = 3
    while d <= n // 2:
        if is_prime(d) and n % d == 0:
            ans -= ans // d
            while n % d == 0:
                n //= d
        d += 2
    if is_prime(n):
        ans -= ans // n
    print(ans)

solve()

### FIXED CODE ###

def is_prime(x):
    # Perform prime number discrimination for odd numbers of 3 or more.
    return pow(2, x - 1, x) == 1

def solve():
    n = int(input())
    ans = n
    if n % 2 == 0:
        ans -= ans // 2
        while n % 2 == 0:
            n //= 2
    d = 3
    while d <= n ** 0.5:
        if is_prime(d) and n % d == 0:
            ans -= ans // d
            while n % d == 0:
                n //= d
        d += 2
    if is_prime(n):
        ans -= ans // n
    print(ans)

solve()
### BUGGY CODE ###

import numpy as np
#n = int(input())
#s = input()
n,x = map(int,input().split())
da = list(map(int,input().split()))
m = 100010
mod = 1000000007

dp = [0]*m
da.sort()
da.reverse()
dp[x] = 1
for i in range(n):
    for j in range(m):
        if j >= da[i]:
            dp[j%da[i]] += dp[j]
            dp[j] *= n-i-1
            if dp[j] >= mod: dp[j] %= mod
            if dp[j%da[i]] >= mod: dp[j] %= mod
        else:
            dp[j] *= n-i
            if dp[j] >= mod: dp[j]%=mod
ans = 0
for i in range(m):
    ans += dp[i] * i
    if ans >= mod: ans %= mod
print(ans)


### FIXED CODE ###

#n = int(input())
#s = input()
n,x = map(int,input().split())
da = list(map(int,input().split()))
m = 100010
mod = 1000000007

dp = [0 for i in range(m)]
da.sort()
da.reverse()
dp[x] = 1
for i in range(n):
    for j in range(m):
        if j >= da[i]:
            dp[j%da[i]] += dp[j]
            dp[j] *= n-i-1
            if dp[j] >= mod: dp[j] %= mod
            if dp[j%da[i]] >= mod: dp[j] %= mod
        else:
            dp[j] *= n-i
            if dp[j] >= mod: dp[j]%=mod
ans = 0
for i in range(m):
    ans += dp[i] * i
    if ans >= mod: ans %= mod
print(ans)
### BUGGY CODE ###

# coding : utf-8

import numpy as np

N = int(input())

A = [int(i) for i in input().split()]


count = 0

#dist = [0 for i in range(N)]
dist = np.zeros(N)
suml = sum(A)

for i in range(N):
	dist[:i+1] += A[i]
	#print(dist)
	count += sum(dist[:i+1]==0)

#print(dist)

print(count)

### FIXED CODE ###

# coding : utf-8
 
import numpy as np
 
N = int(input())
 
A = [int(i) for i in input().split()]

S = [0 for i in range(N+1)]

for i in range(N):
	S[i+1] = S[i] + A[i]

S = sorted(S)
cnt = 0
block = 1
s = S[0]
for i in range(1,N+1):
	if s == S[i]:
		cnt += block
		block += 1
	else:
		s = S[i]
		block = 1

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

# -*- coding: utf-8 -*-
A,B,K = map(int, input().split())

for i in range(K):
	if A>0:
		A-=1
	elif B>0:
		B-=1
	else:
		pass
print('{} {}'.format(A,B))

### FIXED CODE ###

# -*- coding: utf-8 -*-
A,B,K = map(int, input().split())

if A>K:
	print('{} {}'.format(A-K,B))
else:
	if K-A<B:
		print('{} {}'.format(0,B-(K-A)))
	else:
		print('{} {}'.format(0,0))
### BUGGY CODE ###

n, k = input().split()
n=int(n)
k=int(k)
while(True):
    if abs(n - k) < n:
        n = abs(n - k)
    else:
        break
print(n)

### FIXED CODE ###

n, k = input().split()
n=int(n)
k=int(k)
if n % k > abs((n % k) - k):
    print(abs((n % k) - k))
else:
    print(n % k)
### BUGGY CODE ###

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

class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA), BridgeEdge(nodeB)]

class BridgeEdge:
    def __init__(self, node):
        self.node = node
        self.judge = 0

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)


nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(M)):
    b = Bridge(nodes[A], nodes[B])
    nodes[A].addEdge(b.edges[1])
    nodes[B].addEdge(b.edges[0])
    bridges.append(b)


s = [(None, nodes[1], 1)]
idx = 0
while idx < len(s):
    pre, cur, level = s[idx]
    idx += 1

    if level > N * 2:
        break

    for nxt in cur.bridges:
        if not pre is nxt.node:
            nxt.judge += 1
            s.append((cur, nxt.node, level+1))

cnt = 0
for bd in bridges:
    if sum(1 for b in bd.edges if b.judge <= 1) > 0:
        cnt += 1

print(cnt)


### FIXED CODE ###

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

class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA), BridgeEdge(nodeB)]

class BridgeEdge:
    def __init__(self, node):
        self.node = node
        self.judge = 0

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)


nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(M)):
    b = Bridge(nodes[A], nodes[B])
    nodes[A].addEdge(b.edges[1])
    nodes[B].addEdge(b.edges[0])
    bridges.append(b)


s = [(None, nodes[1], 1)]
idx = 0
while idx < len(s):
    pre, cur, level = s[idx]
    idx += 1

    if level > N * 2:
        break

    for nxt in cur.bridges:
        if not pre is nxt.node and nxt.judge < 2:
            nxt.judge += 1
            s.append((cur, nxt.node, level+1))

cnt = 0
for bd in bridges:
    if sum(1 for b in bd.edges if b.judge <= 1) > 0:
        cnt += 1

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

import numpy as np
N, Q = map(int, raw_input().split())
S = raw_input()
L = np.zeros(Q)
R = np.zeros(Q)
for i in range(Q):
    L[i], R[i] = map(int, raw_input().split())
num = np.zeros(Q)
for i in range(N+1):
    if S[i:i+2] == "AC":
        for j in range(Q):
            if int(L[j]-1) <= i and i < int(R[j]-1):                                                                
                num[j] += 1
for i in num:
    print int(i)


### FIXED CODE ###

import numpy as np
N, Q = map(int, raw_input().split())
S = raw_input()
L = np.zeros(Q)
R = np.zeros(Q)
for i in range(Q):
    L[i], R[i] = map(int, raw_input().split())
num = np.zeros(N)
num_tmp = 0
for i in range(1,N):
    if S[i-1:i+1] == "AC":
        num_tmp += 1
    num[i] = num_tmp
for i in range(Q):
    print int(num[int(R[i]-1)] - num[int(L[i]-1)])
### BUGGY CODE ###

H,N = map(int,input().split())
X = []
for _ in range(N):
    a,b = map(int,input().split())
    X.append([a,b])
dp = [10000000000000 for i in range(H+1)] 
dp[0] = 0
for i in range(1,H+1):
    for j in range(N):
        a = X[j][0]
        b = X[j][1]
        dp[i] = min(dp[i],dp[max(0,i-a)] + b)
#print(dp)
print(dp[H])

### FIXED CODE ###

H,N = map(int,input().split())
X = []
for _ in range(N):
    a,b = map(int,input().split())
    X.append([a,b])
dp = [10000000000000 for i in range(H+1)] 
dp[0] = 0
for i in range(1,H+1):
    for j in range(N):
        a = X[j][0]
        b = X[j][1]
        dp[i] = min(dp[i],dp[max(0,i-a)] + b)
#print(dp)
print(dp[H])
### BUGGY CODE ###

N, M, Q = map(int,input().split())
Mlist = [input().split() for l in range(M)]
Qlist = [input().split() for l in range(Q)]
Mlist.sort()
for i in range(len(Mlist)):
    for j in range(len(Mlist[i])):
        Mlist[i][j] = int(Mlist[i][j])
for i in range(len(Qlist)):
    for j in range(len(Qlist[i])):
        Qlist[i][j] = int(Qlist[i][j])
p = [[0 for i in range(N)] for j in range(N)]
q = 0
r = [[0 for i in range(N)] for j in range(N)]
def count(k,l):
    s = k
    j = l
    p[s-1][j-1] = p[s-1][j-1] + 1
for i in range(len(Mlist)):
    count(Mlist[i][0],Mlist[i][1])
for i in range(N):
    for j in range(N):
        r[i][j] = r[i][j-1] + p[i][j]
for i in range(len(Qlist)):
    q = 0
    for j in range(Qlist[i][0],Qlist[i][1]+1):
        q = q + r[j-1][Qlist[i][1]-1]
        if j - 1> 0:
            q = q - r[j-1][j-2]
    print(q)

### FIXED CODE ###

N, M, Q = map(int,input().split())
Mlist = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    Mlist.append(array)
Qlist = []
for i in range(Q):
    array = list(map(int, input().strip().split()))
    Qlist.append(array)
p = [[0 for i in range(N)] for j in range(N)]
q = 0
r = [[0 for i in range(N)] for j in range(N)]
def count(k,l):
    s = k
    j = l
    p[s-1][j-1] = p[s-1][j-1] + 1
for i in range(len(Mlist)):
    count(Mlist[i][0],Mlist[i][1])
for i in range(N):
    for j in range(N):
        if i == 0:
            r[i][j] = p[i][j] + r[i][j-1]      
        elif j == 0:
            r[i][j] = p[i][j] +r[i-1][j]
        else:
            r[i][j] = r[i-1][j] + r[i][j-1] - r[i-1][j-1] + p[i][j]
for i in range(len(Qlist)):
    q = 0
    if Qlist[i][0] == 1:
        b = r[Qlist[i][1]-1][Qlist[i][1]-1]
    else:
        b = r[Qlist[i][1]-1][Qlist[i][1]-1] - r[Qlist[i][0]-2][Qlist[i][1]-1]
    print(b)