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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    rsw = [0]
    a = 0
    
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)

    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, q = map(int, input().split())
s=input().rstrip("\n")

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

from operator import mul
from functools import reduce
from collections import Counter
from copy import deepcopy
import sys
sys.setrecursionlimit(10**7)

def main():
    nCr = {}
    def cmb(n, r):
        if r == 0 or r == n: return 1
        if r == 1: return n
        if (n,r) in nCr: return nCr[(n,r)]
        nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
        return nCr[(n,r)]

    n = int(input())
    A = [int(x) for x in input().split()]
    a_c= Counter(A)
    cnt = 0
    for a in A:
        a_c_c = deepcopy(a_c)
        a_c_c[a] = a_c_c[a] - 1
        values = a_c_c.values()
        val_cnt = Counter(values)
        cnt = {cmb(k, 2) * v  if k > 1 else 0 for k, v in val_cnt.items()}
        print(sum(cnt))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
 
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c = Counter(A)
    res = [int(v*(v-1)/2) for v in a_c.values()]
    cnt = sum(res)
    for a in A:
        ans = (cnt - (a_c[a]-1))
        print(ans)
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*n 
for i in range(1,n):
    if i==1:
        dp[i]=abs(a[i]-a[i-1]) 
    else:
        dp[i]=dp[i-1]+abs(a[i]-a[i-1])
        for j in range(2,k+1):
            if j<=i:
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]))    
print(dp[n-1])        

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*n 
for i in range(1,n):
    if i==1:
        dp[i]=abs(a[i]-a[i-1]) 
    else:
        dp[i]=dp[i-1]+abs(a[i]-a[i-1])
        for j in range(2,k+1):
            if j<=i:
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]))
            else:
                break
print(dp[n-1])
### BUGGY CODE ###

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

for x in lr:
    ans = 0
    l = x[0]
    r = x[1]
    a = s[l-1:r]
    for i in range(r-l):
        if a[i] == "A" and a[i+1] == "C":
            ans += 1
    print(ans)

### FIXED CODE ###

n, q = map(int,input().split())
s = list(input())
lr = [list(map(int,input().split())) for i in range(q)]
ans = [0]
x = 0

for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        x += 1
    ans.append(x)

for i in lr:
    l = i[0]
    r = i[1]
    print(ans[r-1] - ans[l-1])
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
M = [0 for i in range(N)]

for i in range(A[0]+1):
    M[0] = i*2
    for j in range(N-1):
        M[j+1] = (A[j] - int(M[j]//2)) * 2
    if A[N-1] == int((M[0]//2) + ((M[N-1])//2) ):
        break;

for i in range(N):
    print(M[i], end=" ")


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
M = [0 for i in range(N)]

M[0] = 0
for j in range(N-1):
    M[j+1] = (A[j] - int(M[j]//2)) * 2

n = int((A[N-1] - M[0]//2 - M[N-1]//2)//2)

for i in range(N):
    if i%2 == 0:
        print(M[i] + 2*n, end=" ")
    else:
        print(M[i] - 2*n, end=" ")
### BUGGY CODE ###

def check(a,b,c,d):
	while(a!=0 and c!=0):
		c-=b
		if(c==0):
			return 1
		a-=d
		if(a==0):
			return 0
	if(a==0):
		return 0
	else:
		return 1
inp1=list(map(int,input().strip().split()))[:4]
a,b,c,d=inp1[0],inp1[1],inp1[2],inp1[3]
if(check(a,b,c,d)):
	print("Yes")
else:
	print("No")

### FIXED CODE ###

def check(a,b,c,d):
	while(a>0 and c>0):
		c-=b
		if(c<=0):
			return 1
		a-=d
		if(a<=0):
			return 0
inp1=list(map(int,input().strip().split()))[:4]
a,b,c,d=inp1[0],inp1[1],inp1[2],inp1[3]
if(check(a,b,c,d)):
	print("Yes")
else:
	print("No")
### BUGGY CODE ###

s=str(input())
se=[s]
n=len(s)
s_="0"+s
for i in range(n):
  for j in range(1,n-i):
    k=s_[1:i+1]+s_[i+j+1:i:-1]+s_[i+j+2:]
    se+=[k]
uniq = list(set(se))
print(len(uniq))

### FIXED CODE ###

s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)
### BUGGY CODE ###

N = int(input())
S = [input()for i in range(N)]
ans=[]
for i in range(N):
    if not S[i] in ans:
        ans.append(S[i])
print(len(ans))

### FIXED CODE ###

N = int(input())
S = [input()for i in range(N)]
print(len(set(S)))
### BUGGY CODE ###

def main():
    n,x,d=map(int,input().split())
    s=set()
    s_add=s.add
    for k in range(n+1):
        for j in range(k*(k-1)//2, 1+k*(2*n-k-1)//2):
            s_add(j*d+x*k)
    print(len(s))

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
from fractions import gcd
n, x, d = map(int, input().split())
if x == d == 0:
	print(1);sys.exit()
elif d == 0:
	print(n+1);sys.exit()
if x < 0 and x + (n-1) * d < 0:
	x, d = -x, -d
if x >= 0 and d < 0:
	x, d = x + (n-1) * d, -d
g = gcd(x, d);ans = 1
if x >= 0:
	for i in range(1, n+1):
		k = max((i- d//g) *(2*n -1 -i +d//g)//2 -x//g, i *(i-1) //2 -1)
		ans += max((i * (2*n-1-i)) //2 -k, 0)
else:
	for i in range(1, n+1):
		overlap_u = min((i -d//g) *(2*n -1 -i +d//g) //2 -x//g, i *(2*n-1-i) //2)
		overlap_l = max((i -d//g) *(i -d//g -1) //2 -x//g, i *(i-1) //2)
		ans += i *(2*n-1-i) //2 -i *(i-1) //2 +1 -max(overlap_u -overlap_l+1, 0)
print(ans)
### BUGGY CODE ###

k = int(input())

def is_lun(n):
    d, m = divmod(n, 10)
    last = m
    while d:
        n = d
        d, m = divmod(n, 10)
        if abs(last - m) > 1:
            return False
        last = m
    return True

from sys import exit
ans = 1
cnt = 0
while 1:
    if is_lun(ans):
        cnt += 1
    if cnt == k:
        print(ans)
        exit()
    ans += 1

### FIXED CODE ###

from collections import deque
d = deque(range(1,10))
k = int(input())

for _ in range(k):
    ans = d.popleft()
    mod = ans % 10
    if mod != 0:
        d.append(ans * 10 + mod - 1)
    d.append(ans * 10 + mod)
    if mod != 9:
        d.append(ans * 10 + mod + 1)

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

n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+[i]
        else:
            l[p] = [i]
    if q > 0:
        if q in r:
            r[q] = r[q]+[i]
        else:
            r[q] = [i]
ans = 0
for i in l:
    if i in r:
        ans+= len(l[i])*len(r[i])
print(ans)



### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+1
        else:
            l[p] = 1
    if q > 0:
        if q in r:
            r[q] = r[q]+1
        else:
            r[q] = 1
ans = 0
for i in l:
    if i in r:
        ans+= l[i]*r[i]
print(ans)
### BUGGY CODE ###

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

fp = [a[0]]
now = a[0]
cnt = 0

while now != 2:
    cnt += 1
    now = a[now-1]
    if now in fp:
        print(-1)
        exit()
    fp.append(now)

if now == 2:
    cnt += 1

print(cnt)

### FIXED CODE ###

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

now = a[0]
cnt = 0

while cnt <= n:
    cnt += 1
    if now == 2:
        print(cnt)
        exit()
    now = a[now-1]

print(-1)
### BUGGY CODE ###

import itertools


def main():
    n = int(input())
    # d,t,s = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    l = []
    for i in range(len(a)):
        l.append(i)

    c_list = list(itertools.combinations(l, 2))

    sm = 0
    for tpl in c_list:
        sm += (a[tpl[0]] * a[tpl[1]]) % (10**9+7)

    print(sm % (10**9+7))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    # d,t,s = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    mod = 10**9+7

    s = sum(a)

    sm = 0

    for i in a:
        s -= i
        sm += i * s % mod

    print(sm % mod)


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

n = int(input())
a = []
for i in range(n):
  x = int(input())
  if x in a:
    a.remove(x)
  else:
    a.append(x)
print(len(a))

### FIXED CODE ###

n = int(input())
a = []
flag = 0
d = 0
for i in range(n):
  a.append(int(input()))
a.sort()
for i in range(n - 1):
  if flag == 1:
    flag = 0
  elif a[i] == a[i + 1]:
    d = d + 2
    flag = 1
print(len(a) - d)
### BUGGY CODE ###

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

def gcd(a, b):
    if(b > a):
        a, b = b, a

    while(a != b):
        temp = b
        b = a - b
        a = temp
    return a

if max(T) > 5*10**17:
    print(max(T))
else:
    tmp = T[0]
    for i in range(1, N):
        tmp = tmp/gcd(tmp, T[i])*T[i]

    print(int(tmp))

### FIXED CODE ###

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

def gcd(a, b):
    if(b > a):
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

if max(T) > 5*10**17:
    print(max(T))
    
else:
    tmp = max(T)
    for i in range(N):
        if tmp % T[i] != 0:
            tmp = T[i]//gcd(tmp, T[i])*tmp

    print(int(tmp))
### BUGGY CODE ###

H,W = map(int,input().split())
data = [list(map(str,input())) for _ in range(H)]

def g(m):
  if data[0][0] == '.':
    a = 0
  else:
    a = 1
    
  for i in range(1,m,1):
    if data[0][i] == '.':
      continue
    elif data[0][i] == '#' and data[0][i-1] == '.':
      a += 1
    else:
      continue
  return a

M = [g(m) for m in range(1,W+1,1)]

def h(n):
  if data[0][0] == '.':
    a = 0
  else:
    a = 1
    
  for i in range(1,n,1):
    if data[i][0] == '.':
      continue
    elif data[i][0] == '#' and data[i-1][0] == '.':
      a += 1
    else:
      continue
  return a

N = [g(n) for n in range(1,H+1,1)]
  
def f(n,m):
  if n == 1:
    return M[m-1]
  elif m == 1:
    return N[n-1]
  else:
    if data[n-1][m-1] == '.':
      return min(f(n-1,m),f(n,m-1))
    elif data[n-2][m-1] == '.':
      if data[n-1][m-2] == '.':
        return min(f(n-1,m)+1,f(n,m-1)+1)
      else:
        return min(f(n-1,m)+1,f(n,m-1))
    else:
      if data[n-1][m-2] == '.':
        return min(f(n-1,m),f(n,m-1)+1)
      else:
        return min(f(n-1,m),f(n,m-1))
      
print(f(H,W))

### FIXED CODE ###

H, W = map(int, input().split())
data = [list(map(str, input())) for _ in range(H)]


def g(m):
    if data[0][0] == '.':
        a = 0
    else:
        a = 1

    for i in range(1, m, 1):
        if data[0][i] == '.':
            continue
        elif data[0][i] == '#' and data[0][i - 1] == '.':
            a += 1
        else:
            continue
    return a


def h(n):
    if data[0][0] == '.':
        a = 0
    else:
        a = 1

    for i in range(1, n, 1):
        if data[i][0] == '.':
            continue
        elif data[i][0] == '#' and data[i - 1][0] == '.':
            a += 1
        else:
            continue
    return a

A = [0] + [g(i) for i in range(1,W+1)]
B = [0] + [h(i) for i in range(1,H+1)]
C = [[0]*(W+1) for i in range(H+1)]

for n in range(1,H+1):
    for m in range(1,W+1):
        if n == 1:
            C[n][m] = A[m]
        elif m == 1:
            C[n][m] = B[n]
        else:
            if data[n - 1][m - 1] == '.':
                C[n][m] = min(C[n - 1][m], C[n][m - 1])
            elif data[n - 2][m - 1] == '.':
                if data[n - 1][m - 2] == '.':
                    C[n][m] = min(C[n - 1][m] + 1, C[n][m - 1] + 1)
                else:
                    C[n][m] =  min(C[n - 1][m] + 1, C[n][m - 1])
            else:
                if data[n - 1][m - 2] == '.':
                    C[n][m] = min(C[n - 1][m], C[n][m - 1] + 1)
                else:
                    C[n][m] = min(C[n - 1][m], C[n][m - 1])


print(C[H][W])
### BUGGY CODE ###

s=input()
ans=[0]*len(s)
rl_list=[]
rl=s[0]
c=0
for ts in s[1:]:
  c+=1
  if rl!=ts:
    rl_list.append(c)
    rl=ts
    c=0
rl_list.append(c+1)
for i in range(0,len(rl_list),2):
  index=sum(rl_list[:i+1])
  num=rl_list[i]//2
  if rl_list[i]%2==0:
    ans[index]+=num
    ans[index-1]+=num
  else:
    ans[index-1]+=num+1
    ans[index]+=num
  num=rl_list[i+1]//2
  if rl_list[i+1]%2==0:
    ans[index-1]+=num
    ans[index]+=num
  else:
    ans[index]+=num+1
    ans[index-1]+=num
print(*ans)
    

### FIXED CODE ###

s=input()
ans=[0]*len(s)
rl_list=[]
ind=[]
rl=s[0]
c=0
for i,ts in enumerate(s[1:]):
  c+=1
  if rl!=ts:
    rl_list.append(c)
    if ts=='L':
      ind.append(i+1)
    rl=ts
    c=0
rl_list.append(c+1)
for i in range(0,len(rl_list),2):
  index=ind[i//2]
  num=rl_list[i]//2
  if rl_list[i]%2==0:
    ans[index]+=num
    ans[index-1]+=num
  else:
    ans[index-1]+=num+1
    ans[index]+=num
  num=rl_list[i+1]//2
  if rl_list[i+1]%2==0:
    ans[index-1]+=num
    ans[index]+=num
  else:
    ans[index]+=num+1
    ans[index-1]+=num
print(*ans)
### BUGGY CODE ###

n = int(input())
s = []

for i in range(n):
    s.append(input())

buf = []
cnt = [0]*n
for i in s:
    if i not in buf:
        buf.append(i)
    cnt[buf.index(i)] += 1

ans = [i for i, x in enumerate(cnt) if x == max(cnt)]

ans2 = [buf[i] for i in range(len(buf)) if i in ans]

ans3 = sorted(ans2)

for i in ans3:
    print(i)

### FIXED CODE ###

n = int(input())
s = []

for i in range(n):
    s.append(input())

word_buf = {}

for i in s:
    if i in word_buf.keys():
        word_buf[i] += 1
    else:
        word_buf[i] = 1

max_cnt = max(word_buf.values())
max_word = [i[0] for i in word_buf.items() if i[1] == max_cnt]
max_word.sort()

for i in max_word:
    print(i)
### BUGGY CODE ###

from collections import deque

H,W = map(int,input().split())
src = [input() for _ in range(H)]

dxy = [(0,1),(1,0),(0,-1),(-1,0)]

dist = [[-1]*W for _ in range(H)]
d = deque([])

for h in range(H):
    for w in range(W):
        if src[h][w]=="#":
            dist[h][w]=0
            d.append((w,h))
while d:
    x,y = d.popleft()
    for dx, dy in dxy:
        nx,ny = x+dx, y+dy
        if not 0<=nx<W: continue
        if not 0<=ny<H: continue
        if src[ny][nx] == "#": continue
        if dist[ny][nx] > 0: continue
        dist[ny][nx] = dist[y][x] + 1
        d.append((nx,ny))
print(max(map(max,dist)))

### FIXED CODE ###

from collections import deque

H,W = map(int,input().split())
src = [input() for _ in range(H)]

dxy = [(0,1),(1,0),(0,-1),(-1,0)]

dist = [[-1]*W for _ in range(H)]
d = deque([])

for h in range(H):
    for w in range(W):
        if src[h][w]=="#":
            dist[h][w]=0
            d.append((w,h))
while d:
    x,y = d.popleft()
    for dx, dy in dxy:
        nx,ny = x+dx, y+dy
        if not 0<=nx<W: continue
        if not 0<=ny<H: continue
        if src[ny][nx] == "#": continue
        if dist[ny][nx] > 0: continue
        dist[ny][nx] = dist[y][x] + 1
        d.append((nx,ny))
print(max(map(max,dist)))
### BUGGY CODE ###

N = int(input())
K = 0
for C in range(1,N):
  K += sum(A*B==N-C for A in range(1,N) for B in range(1,N))

print(K)

### FIXED CODE ###

import math
N = int(input())
A = [0]*(N)
for i in range(0,N):
    A[i] = math.floor((N-1)/(i+1))
print(sum(A))
### BUGGY CODE ###

N = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    s = input()
    num = 0
    for i,a in enumerate(alphabet):
        if s.count(a) == 10:
            continue #アナグラムはない
        num += s.count(a)*10**i
    d[num] += 1

ans = 0

for key in d.keys():
    ans += d[key]*(d[key]-1)//2
print(ans)

### FIXED CODE ###

N = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    s = input()
    num = 0
    sorted(alphabet)
    for i,a in enumerate(alphabet):
        if s.count(a) == 10:
            continue #アナグラムはない
        num += s.count(a)*10**i
    d[num] += 1

ans = 0

for key in d.keys():
    ans += d[key]*(d[key]-1)//2
print(ans)
### BUGGY CODE ###

s=list(input())
mod=10**9+7
n=len(s)
for i in range(n):
    if s[i]!="?":
        s[i]=int(s[i])
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    if s[i]=="?":
        for k in range(10):
            for j in range(13):
                p=(k+10*j)%13
                dp[i+1][p]+=dp[i][j]
                dp[i+1][p]%=mod

    else:
        for j in range(13):
            p=(s[i]+10*j)%13
            dp[i+1][p]+=dp[i][j]
            dp[i+1][p]%=mod
print(dp[n][5])

### FIXED CODE ###

s=list(input())
mod=10**9+7
n=len(s)
for i in range(n):
    if s[i]!="?":
        s[i]=int(s[i])
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    if s[i]=="?":
        for k in range(10):
            for j in range(13):
                p=(k+10*j)%13
                dp[i+1][p]+=dp[i][j]
                dp[i+1][p]%=mod

    else:
        for j in range(13):
            p=(s[i]+10*j)%13
            dp[i+1][p]+=dp[i][j]
            dp[i+1][p]%=mod
print(dp[n][5])
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
grid = []
graph = [[10000 for i in range(w)] for j in range(h)]
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False

#graph => そこまでの距離を保存した二次元配列　grid=>与えられた迷路
def bfs(que):
    finished = set()
    while que:
        x , y, cost = que.popleft()
        if not check(y,x):
            continue
        if (grid[y][x] == '#' and cost != 0):
            continue
        if (x,y) not in finished and graph[y][x] > cost:
            finished.add((x,y))
            graph[y][x] = cost
            que.append([x+1,y,cost+1])
            que.append([x, y+1, cost+1])
            que.append([x-1,y,cost+1])
            que.append([x,y-1,cost+1])
for i in range(h):
    grid.append(list(input()))
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            que = deque([(j,i,0)])
            bfs(que)
ans = 0
for i in range(h):
    ans = max(ans, max(graph[i]))
print(ans)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
h, w = map(int, input().split())
grid = []
graph = [[2000 for i in range(w)] for j in range(h)]
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False

#graph => そこまでの距離を保存した二次元配列　grid=>与えられた迷路
def bfs(que):
    finished = set()
    while que:
        x ,y = que.popleft()
        if y*w+x not in finished:
            finished.add(y*w+x)
            for n_x,n_y in [(x+1,y),(x,y+1),(x-1,y),(x,y-1)]:
                if check(n_y,n_x) and graph[n_y][n_x] > graph[y][x] + 1:
                    graph[n_y][n_x] = graph[y][x] + 1
                    que.append((n_x,n_y))
for i in range(h):
    grid.append(list(input()))
que = deque()
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            graph[i][j] = 0
            que.append((j,i))
bfs(que)
ans = 0
for i in range(h):
    ans = max(ans, max(graph[i]))
print(ans)
### BUGGY CODE ###

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


for _ in range(K):
    T = [0]*N
    for i in range(N):
        for j in range(max(0,i-A[i]), min(N-1, i+A[i])+1):
            T[j] += 1
    for i in range(N):
        A[i] = T[i];
    
T = [str(i) for i in A]
print(" ".join(T))


### FIXED CODE ###

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

#累積和
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    B, A = A, B
    if min(A) == N:
        break

print(*A)
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

ans = [0] * (n + 1)

for i in range(q):
    p, x = map(int, input().split())
    ans[p] += x


def solve(graph, ans):
    curr, root = 1, -1

    def dfs(curr, root):
        for leaf in graph[curr]:
            if leaf == root:
                continue
            ans[leaf] += ans[curr]
            dfs(leaf, curr)
        return ans

    return dfs(curr, root)


ans = solve(graph, ans)

print(*ans[1:])

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

for i in range(q):
    p, x = map(int, input().split())
    arr[p] += x


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])
### BUGGY CODE ###

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

for g in range(M//N,0,-1):
    if (M-(N-1)*g)%g==0:
        break

print(g)

### FIXED CODE ###

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

for g in range(M//N,0,-1):
    if (M-(N-1)*g)%g==0:
        break

print(g)
### BUGGY CODE ###

import numpy
# TLE

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

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
remain = numpy.arange(M+1)
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    for i in (remain[ remain>=hiya[0] ]):
        if reward[i] == 0:
            reward[i] = hiya[1]
            remain[i] = -1
            break

print(sum(reward))

### FIXED CODE ###

from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)