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

h,w,m=map(int,input().split())
B=[[] for i in range(h)]
H=[0]*h
W=[0]*w
for i in range(m):
    p,q=map(int,input().split())
    B[p-1].append(q-1)
    H[p-1]+=1
    W[q-1]+=1
mH=max(H)
mW=max(W)
CH=[]
for i in range(h):
    if H[i]==mH:
        CH.append(i)
CW=[]
for i in range(w):
    if W[i]==mW:
        CW.append(i)
flag=0
if len(CH)*len(CW)>m:
    flag=1
else:
    for ch in CH:
        b=B[ch]
        for cw in CW:
            if cw in b:
                continue
            else:
                flag=1
                break
        if flag:
            break
if flag:
    print(mH+mW)
else:
    print(mH+mW-1)

### FIXED CODE ###

h,w,m=map(int,input().split())
B=[[] for i in range(h)]
H=[0]*h
W=[0]*w
for i in range(m):
    p,q=map(int,input().split())
    B[p-1].append(q-1)
    H[p-1]+=1
    W[q-1]+=1
mH=max(H)
mW=max(W)
CH=[]
for i in range(h):
    if H[i]==mH:
        CH.append(i)
CW=[]
for i in range(w):
    if W[i]==mW:
        CW.append(i)
CW=set(CW)
flag=0
if len(CH)*len(CW)>m:
    flag=1
else:
    for ch in CH:
        b=set(B[ch])
        if CW<=b:
            continue
        else:
            flag=1
            break
if flag:
    print(mH+mW)
else:
    print(mH+mW-1)
### BUGGY CODE ###

h,w = list(map(int,input().split()))
sx, sy = list(map(int,input().split()))
gx, gy = list(map(int,input().split()))
maze = [list(input()) for _ in range(h)]
sx -= 1; sy -= 1; gx -= 1; gy -= 1

mx = [0,1,0,-1]
my = [1,0,-1,0]
mazemap = [[10**9]*w for _ in range(h)]
from collections import deque
q = deque()
nq = deque()
q.append([sx,sy,0])

while q or nq:
    x,y,z = q.popleft() if q else nq.popleft()
    if x == gx and y == gy:
        ans = z
        break
    fast = 0
    for i in range(4):
        nx = x + mx[i]; ny = y + my[i]
        if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z:
            q.append([nx,ny,z])
            mazemap[nx][ny] = z
            fast += 1
    if fast < 3:
        for i in range(-2,3):
            for j in range(-2,3):
                nx = x+i; ny = y+j
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z+1:
                    nq.append([nx,ny,z+1])
                    mazemap[nx][ny] = z+1
else:
    ans = -1

print(ans)

### FIXED CODE ###

h,w = list(map(int,input().split()))
sx, sy = list(map(int,input().split()))
gx, gy = list(map(int,input().split()))
maze = [list(input()) for _ in range(h)]
sx -= 1; sy -= 1; gx -= 1; gy -= 1

mx = [0,1,0,-1]
my = [1,0,-1,0]
mazemap = [[10**9]*w for _ in range(h)]
from collections import deque
q = deque()
nq = deque()
q.append([sx,sy,0])

while q or nq:
    x,y,z = q.popleft() if q else nq.popleft()
    if x == gx and y == gy:
        ans = z
        break
    for i in range(4):
        nx = x + mx[i]; ny = y + my[i]
        if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z:
            q.append([nx,ny,z])
            mazemap[nx][ny] = z
        for i in range(-2,3):
            for j in range(-2,3):
                nx = x+i; ny = y+j
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z+1:
                    nq.append([nx,ny,z+1])
                    mazemap[nx][ny] = z+1
else:
    ans = -1

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

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    cumprod = []

    for i in range(K, N):
        prev_score = 1
        curr_score = 1
        for j in range(i-K, i+1):
            if j == i-K:
                prev_score *= A[j]
            elif j == i:
                curr_score *= A[j]
            else:
                prev_score *= A[j]
                curr_score *= A[j]
        
        if prev_score < curr_score:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

### FIXED CODE ###

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for i in range(N-K):
        if A[i] < A[i+K]:
            print('Yes')
        else:
            print('No')

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

N = int(input())
c = []
for _ in range(N):
    c.append(int(input()))

dp = [0] * N
dp[0] = 1

for i in range(1, N):
    if c[i] == c[i - 1]:
        dp[i] = dp[i - 1]
        continue
    for j in range(i):
        if j == 0 and c[j] == c[i]:
            dp[i] += 1
        if c[i] == c[j + 1] and c[j] != c[j + 1]:
            dp[i] += dp[j]
print(dp[N - 1])

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
c = []
for _ in range(N):
    c.append(int(input()))

dp = [0] * N
dp[0] = 1
dpc = [0] * (max(c) + 1)
dpc[c[0]] = 1

for i in range(1, N):
    dp[i] = dp[i - 1]
    if c[i] != c[i - 1]:
        dp[i] += dpc[c[i]]
        dpc[c[i]] += dp[i - 1]

print(dp[N - 1] % (10**9+7))
### BUGGY CODE ###

mod=10**9 + 7
#print(bin(9))
N=int(input())
A=list(map(int,input().split()))
A.sort()
#print(A)
A=[bin(i)[2:] for i in A]
#print(A)
nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]

#print(A)

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

    for a in range(len(S)):
        nowdata[a]+=int(S[-a-1])
    S=A[i+1]
    for a in range(len(S)):
        if S[-a-1]=="0":
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]
    #print(nowdata)


num=0
#print(data)
for i in range(60):
    num+=data[i]* (2**i)
    num%=mod

print(num)


### FIXED CODE ###

mod=10**9 + 7
#print(bin(9))
N=int(input())
A=list(map(int,input().split()))
A=[bin(i)[2:] for i in A]
A=[(60-len(i)) * "0" + i for i in A]
#print(A)
nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]

#print(A)

for i in range(N-1):
    S=A[i]
    #print(nowdata)
    for a in range(len(S)):
        if S[a]=="1":
            nowdata[a]+=1
    S=A[i+1]
    for a in range(len(S)):
        if S[a]=="0":
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]


num=0
#print(data)
for i in range(60):
    num+=data[-i-1]* (2**i)
    num%=mod

print(num)
### BUGGY CODE ###

import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(k):
    next = [1]*n
    stack = 0
    for j, v in enumerate(current):
        next[j] += int(str(stack)[-1])
        stack = str(stack)
        stack = stack[:len(stack)-1]
        if len(stack):
            stack = int(stack)
        else:
            stack = 0
        if v > 0:
            stack += int('1'*v)
    stack = 0
    next = next[::-1]
    for j, v in enumerate(current[::-1]):
        next[j] += int(str(stack)[-1])
        stack = str(stack)
        stack = stack[:len(stack) - 1]
        if len(stack):
            stack = int(stack)
        else:
            stack = 0
        if v > 0:
            stack += int('1' * v)
    current = next[::-1]
print(*current)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(min(42, k)):
    nex = [0]*n
    for i, v in enumerate(current):
        l = max(0, i-v)
        r = min(n-1, i+v)
        nex[l] += 1
        if r+1 < n:
            nex[r+1] -= 1
    for i in range(1, n):
        nex[i] += nex[i-1]
    current = nex

print(*current)
### BUGGY CODE ###

import itertools

"""
整数K,S
2 <= K <= 2500, 0 <= S <= 3K

0 <= X,Y,Z <= K
X + Y + Z = Sを満たすX,Y,Zの割り当ては何通り？

"""
K, S = map(int, input().strip().split(' '))
X = list(range(K + 1))
Y = list(range(K + 1))
Z = list(range(K + 1))
count = 0

for i, j, k in list(itertools.product(X,Y,Z)):
  if i + j + k == S:
    count += 1
print(count)

### FIXED CODE ###

import itertools

K, S = map(int, input().strip().split(' '))
X = list(range(K + 1))
count = 0
for i, j in itertools.product(X, repeat=2):
  if 0 <= S - i - j <= K:
    count += 1
print(count)
### BUGGY CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

MAX = 10**18
result = 1
for i in input().split():
    result *= int(i)

if result > MAX:
    print(-1)
else:
    print(result)

### FIXED CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

MAX = 10**18
result = 1
A = FLI()
if 0 in A:
    print(0)
    exit()
    
for i in A:
    result *= int(i)
    if result > MAX:
        print(-1)
        exit()

print(result)
### BUGGY CODE ###

from collections import Counter
n, k = map(int, input().split())
a = Counter((i for i in input().split()))

sort_count = sorted(a.items(), key=lambda x: x[1])

total = 0
while len(sort_count) > k:
    _, n = sort_count.pop(0)
    total += n

print(total)

### FIXED CODE ###

N, K = map(int, input().split())
B = [0]*(N+1)
for i in input().split():
  B[int(i)] += 1
print(sum(sorted(B)[:-K]))
### BUGGY CODE ###

from re import match
N = int(input())
S = input()

cnt = 0
for i in range(1000):
    s = '{:03}'.format(i)
    if match('.*' + s[0] + '.*' + s[1] +'.*' + s[2], S):
        cnt += 1

print(cnt)


### FIXED CODE ###

N = int(input())
S = input()

def search(c, text):
    pos = -1
    for i, s in enumerate(text):
        if s == c:
            pos = i
            break
    return pos

cnt = 0
for i in range(10):
    ip = search(str(i), S[0:])
    if ip < 0:
        continue
    for j in range(10):
        jp = search(str(j), S[ip+1:])
        if jp < 0:
            continue
        for k in range(10):
            kp = search(str(k), S[ip+jp+2:])
            if kp < 0:
                continue
            cnt += 1

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

numberOfInput=int(input())
primeNumbers=[]

def isPrime(researchNumber):
    for devidedBy in range(1,researchNumber+1):
        if researchNumber%devidedBy==0 and devidedBy!=1 and devidedBy!=researchNumber:
            break
        elif researchNumber%devidedBy==0 and devidedBy==researchNumber:
            primeNumbers.append(researchNumber)


#----------------------------------main------------------------------------------
while numberOfInput>0:
    researchNumber=int(input())
    if researchNumber==1:
        pass
    else:
        isPrime(researchNumber)
    numberOfInput-=1
print(len(primeNumbers))


### FIXED CODE ###

n =  int(input())
index=0
count=0
while index<n:
    number = int(input())
    stock =[]
    devideN = 1
    while devideN <= number:
        if len(stock)>2:
            break
        elif devideN==10000:
            stock.append(devideN)
            break
        elif number%devideN==0:
            if devideN!=1 and devideN!=number:
                break
            else:
                stock.append(devideN)
        else:
            pass
        devideN+=1
    if len(stock) == 2:
        count+=1
    index+=1
print(count)
### BUGGY CODE ###


import math


def fact(x):
    for cand in range(2, math.ceil(math.sqrt(x)) + 1):
        q, r = divmod(x, cand)
        if r == 0:
            return min(q, cand), max(q, cand)
    return 1, x


# def check(a, b):
#     a2 = a * a
#     a3 = a2 * a
#     a4 = a3 * a
#     b2 = b * b
#     b3 = b2 * b
#     b4 = b3 * b
#     return a4 + a3*b + a2*b2 + a*b3 + b4

def pow5(x):
    return x ** 5


def func(a, b):
    return pow5(a) - pow5(b)


def submit():
    x = int(input())

    if x == 1:
        print("0 -1")
        return

    q1, q2 = fact(x)
    # パターン1, a, b > 0
    a = 0
    b = -q1
    f = func(a, b)
    while f != x:
        a += 1
        b += 1
        f = func(a, b)
    print("{} {}".format(a, b))


        
submit()

### FIXED CODE ###



def submit():
    x = int(input())

    for a in range(-200, 200):
        for b in range(-200, 200):
            if a ** 5 - b ** 5 == x:
                print(a, b)
                return


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

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

mod = 998244353

for _ in range(K):
    L, R = map(int,input().split())
    for d in range(L, R+1):
        moves.add(d)

dp = [0] * (N + 1)
dp[1] = 1
# for dis in moves:
#     dp[dis] = 1

for n in range(1, N+1):
    for dis in moves:
        if n - dis >= 1:
            # print(n, n - dis)
            dp[n] += dp[n - dis]

# print(dp)
print(dp[N] % mod)


### FIXED CODE ###

n, k = map(int, input().split())
sec = [list(map(int, input().split())) for _ in range(k)]
sec.sort()
    
mod = 998244353
    
dp = [0] * n
dp[0] = 1
sum_dp = [0, 1]
for i in range(1, n):
    for l, r in sec:
        if i - l < 0:
            break
        elif i - r > 0:
            dp[i] = ((dp[i] + sum_dp[i-l+1]) % mod - sum_dp[i-r]) % mod
        else:
            dp[i] = (dp[i] + sum_dp[i-l+1]) % mod
    
    sum_dp.append((sum_dp[-1] + dp[i]) % mod)
    
print(dp[n-1])
### BUGGY CODE ###

n, q = map(int, input().split())
s = str(input())
lr = []
for i in range(q):
    lr.append(list(input().split()))

for i in range(q):
    cnt = 0
    start = int(lr[i][0])
    end = int(lr[i][1])

    cnt = s[start-1:end].count('AC')

    print(cnt)


### FIXED CODE ###

n, q = map(int, input().split())
s = str(input())
lr = []
for i in range(q):
    lr.append(list(input().split()))

n = len(s)
ary = [0 for i in range(len(s)+1)]

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        ary[i+1] = ary[i] + 1
    else:
        ary[i+1] = ary[i]

for i in range(q):
    ans = ary[int(lr[i][1])] - ary[int(lr[i][0])]
    print(ans)
### BUGGY CODE ###

def judge753(n):
    a=list(str(n))
    if str(n).replace('3','').replace('5','').replace('7','')=='' and '3' in a and '5' in a and '7' in a:
        return 1
    else:
        return 0
n=int(input())
count=0
for i in range(357,n+1):
    count+=judge753(i)
print(count) 

### FIXED CODE ###

a3={'357','375','537','573','735','753'}
def make_a(a,n):
    new_a=set()
    for i in a:
        for j in range(n+1):
            new_a.add(i[:j]+'3'+i[j:])
            new_a.add(i[:j]+'5'+i[j:])
            new_a.add(i[:j]+'7'+i[j:])
    return new_a
a4=make_a(a3,3)
a5=make_a(a4,4)
a6=make_a(a5,5)
a7=make_a(a6,6)
a8=make_a(a7,7)
a9=make_a(a8,8)
a=list(map(int,a3))+list(map(int,a4))+list(map(int,a5))+list(map(int,a6))+list(map(int,a7))+list(map(int,a8))+list(map(int,a9))
n=int(input())
a.append(n)
a.sort()
ans=a.index(n)
if ans!=len(a)-1:
    if a[ans]==a[ans+1]:
        ans+=1
print(ans)
### BUGGY CODE ###

class Deque:
    class Node:  # ??????????????????
        def __init__(self, x, y=None, z=None):
            self.key = x
            self.next = y
            self.prev = z

        def search(self, x):  # listSearch??¨???????????????????????????????????????
            if(self.key == x or self.key is None):
                return self
            else:
                return self.prev.search(x)

        def delete(self):
            self.prev.next = self.next
            self.next.prev = self.prev

    def __init__(self):
        self.size = 0
        self.head = Deque.Node(None)
        self.tail = Deque.Node(None, self.head, None)
        self.head.prev = self.tail

    # insert x:??£??????????????????????????????x?????????????´???????????¶????
    def insert(self, x):
        p = Deque.Node(x, self.head, self.head.prev)
        self.head.prev.next = p
        self.head.prev = p
        self.size += 1

    # deleteFirst:??£????????????????????????????´???????????????????
    def deleteFirst(self):
        if self.size == 0:
            raise IndexError
        self.head.prev.delete()
        self.size -= 1

    # deleteLast:??£???????????????????°????????´???????????????????
    def deleteLast(self):
        if self.size == 0:
            raise IndexError
        self.tail.next.delete()
        self.size -= 1

    # ???????????????????????¢?´¢
    def listSearch(self, x):
        return self.head.prev.search(x)

    # ??¢?´¢?????\????£?
    def listSearch2(self, x):
        node = self.tail.next
        while(node.key is not None):
            if(node.key == x):
                return node
            else:
                node = node.next

    # delete:x???????????????????´??????????????????°?????¢?´¢????????¨
    def delete(self, x):
        if self.size == 0:
            raise IndexError
        node = self.listSearch(x)
        if(node.key is not None):
            node.delete()
        self.size -= 1

    # ??????
    def printList(self):
        ret = []
        node = self.head.prev
        while node.key is not None:
            ret.append(str(node.key))
            node = node.prev
        print(" ".join(ret))


n = int(input())
d = Deque()
for i in range(n):
    i = input().split()
    if i[0] == "insert":
        x = int(i[1])
        d.insert(x)
    if i[0] == "delete":
        x = int(i[1])
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] == "deleteLast":
        d.deleteLast()
d.printList()

### FIXED CODE ###

from collections import deque
n = int(input())
L = deque()

for i in range(n):
    cmdline = input().split()

    if cmdline[0] == "insert":
        L.appendleft(cmdline[1])
    elif cmdline[0] == "delete":
        try:
            L.remove(cmdline[1])
        except ValueError: pass
    elif cmdline[0] == "deleteFirst":
        L.popleft()
    elif cmdline[0] == "deleteLast":
        L.pop()

print(" ".join(L))
### BUGGY CODE ###

input()
a=list(map(int,input().split()))
d=[0]*(max(a)+1)
for i in a:d[i]=i*a.count(i)+d[i-1]
m=int(input())
b,c=[list(map(int,input().split())) for _ in [0,0]]
[print(['Yes','No'][d[b[i]]<c[i]])for i in range(m)]

### FIXED CODE ###

import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
d=[0]*(n+1)
for i in range(1,n+1):d[i]=d[i-1]+a[i-1]
m=int(input())
b,c=[list(map(int,input().split())) for _ in [0,0]]
[print(['Yes','No'][d[bisect.bisect_right(a,b[i])]<c[i]]) for i in range(m)]
### BUGGY CODE ###

N, M = map(int, input().split())
a = list(map(int, input().split()))
for i in range(M):
    B, C = map(int, input().split())
    a += [C for _ in range(B)]
    a.sort(reverse=True)
    a = a[:N]
print(sum(a))

### FIXED CODE ###

#import sys
#input = sys.stdin.readline
import numpy as np
N, M = map(int, input().split())
C = list(map(int, input().split()))
B = [1 for _ in range(N)]

for i in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
C = np.array(C)
D = np.argsort(-C)
#print(B, C, D)
S = 0
n = 0
for i in D:
    #print(B[i], N-n, min(B[i], N-n))
    S += C[i] * (min(B[i], N-n))
    n += min(B[i], N-n)
    #print(S, n)
    if n == N:
        break
print(S)
### BUGGY CODE ###

n = int(input())
a = [int(_)%(10**9+7) for _ in input().split()]
c = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    c += (a[i]%(10**9+7))*(a[j]%(10**9+7))
    c %= (10**9+7)
print(c)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))
### BUGGY CODE ###

import itertools
x,y,z,k = list(map(int, input().split())) 
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = [i + j for (i, j) in list(itertools.product(a, b))]

ab.sort(reverse=True)

abc = [ij + h for (ij, h) in list(itertools.product(ab[:min(k,x*y)], c[:min(k,z)]))]

abc.sort(reverse=True)

for g in range(k):
  print(abc[g])

### FIXED CODE ###

import heapq
x,y,z,k = list(map(int, input().split())) 
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)

ans = []
log = set()

total = (a[0] + b[0] + c[0]) * (-1)
heapq.heappush(ans, (total, 0, 0, 0))
log.add((0, 0, 0))

for i in range(k):
  (total, aa, bb, cc) = heapq.heappop(ans)
  print(total * (-1))
  if (aa+1, bb, cc) not in log:
    if aa+1 < x:
      total = (a[aa+1] + b[bb] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa+1, bb, cc))
      log.add((aa+1, bb, cc))
  if (aa, bb+1, cc) not in log:
    if bb+1 < y:
      total = (a[aa] + b[bb+1] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa, bb+1, cc))
      log.add((aa, bb+1, cc))
  if (aa, bb, cc+1) not in log:
    if cc+1 < z:
      total = (a[aa] + b[bb] + c[cc+1]) * (-1)
      heapq.heappush(ans, (total, aa, bb, cc+1))
      log.add((aa, bb, cc+1))
### BUGGY CODE ###

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

### FIXED CODE ###

n, q = map(int,input().split())
s = input()
t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)
for i in range(q):
    l, r = map(int,input().split())
    print(t[r-1]-t[l-1])
### BUGGY CODE ###

import itertools
H, W, M = map(int, input().split())
Bh = [0]*(H+1)
Bw = [0]*(W+1)
OD = []

for _ in range(M):
    h, w = map(int, input().split())
    Bh[h] += 1
    Bw[w] += 1
    OD.append((h, w))

M1 = max(Bh)
M2 = max(Bw)
l1 = [i for i, x in enumerate(Bh) if x == M1]
l2 = [j for j, x in enumerate(Bw) if x == M2]
for i, j in itertools.product(l1, l2):
    if (i, j) not in OD:
        break
else:
    print(M1+M2-1)
    exit()
print(M1+M2)


### FIXED CODE ###

import itertools
H, W, M = map(int, input().split())
Bh = [0]*(H+1)
Bw = [0]*(W+1)
OD = set()

for _ in range(M):
    h, w = map(int, input().split())
    Bh[h] += 1
    Bw[w] += 1
    OD.add((h, w))

M1 = max(Bh)
M2 = max(Bw)
l1 = [i for i, x in enumerate(Bh) if x == M1]
l2 = [j for j, x in enumerate(Bw) if x == M2]
for i, j in itertools.product(l1, l2):
    if (i, j) not in OD:
        break
else:
    print(M1+M2-1)
    exit()
print(M1+M2)
### BUGGY CODE ###

L,R = map(int,input().split())
S = set()
if (R-L)>=673:
    print(0)
else:
    for i in range(R-L+1):
        for j in range(R-L+1):
            if i != j:
                S = S | {((L+i)*(L+j))%2019}
    print(min(S))

### FIXED CODE ###

L,R = map(int,input().split())
S = list()
n = R-L
if n >= 673:
    print(0)
else:
    for i in range(n+1):
        for j in range(i+1,n+1):
            l = L+i
            r = L+j
            S.append((l*r)%2019)
    print(min(S))