peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
S = input().strip()

bcnt = S.count("#")
wcnt = N - bcnt

ans = wcnt
cntb = 0
cntw = 0
for i in range(N):
    if S[i] == "#":
        cntb += 1
    else:
        cntw += 1

    ans = min(ans, cntb + wcnt - cntw)


print(ans)
# Judge status: Accepted
import math 
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=max((left+right)//2,1)

while(right-left>=1):
    numofcut=0
    
    for i in range(N):
        numofcut+=math.ceil(A[i]/mid)-1
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    mid=max((left+right)//2,1)
    if mid==1:
        break
print(mid)
# Judge status: Wrong Answer
S=input()
S[3]=="8"
print(S)
# Judge status: Accepted
N = int(input())
l = [[0 for _ in range(10)]for _ in range(10)]

for i in range(1,N+1):
  i = str(i)
  if i[0] == '0' or i[-1] == '0':
    pass
  else:
    l[int(i[0])][int(i[-1])] += 1

ans = 0

for i in range(1,10):
  for j in range(1,10):
    ans += l[i][j]*l[j][i]

print(ans)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
if A > B:
  print(0)
elif A == B:
  print(1)
elif B-A >N:
  print(0)
else:
  X = N-B+A  
  print((B-A)*X+1)
# Judge status: Accepted
a, b = input().split()

print(min(a * int(b), b * int(a)))
# Judge status: Wrong Answer
S = input()
S1 = S[0::2]
S2 = S[1::2]

S_count = S1.count('R') + S1.count('U') + S1.count('D')+ S2.count('L') + S2.count('U') + S2.count('D')

if len(S) == S_count:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
def resolve():
    print(2 ** (len(bin(int(input()))) - 3))


if __name__ == '__main__':
    resolve()
# Judge status: Wrong Answer
arr=raw_input()
ans="No"
for i in range(len(arr)):
  if arr[0]==9:
    ans = "Yes"
  elif arr[1]==9:
    ans = "Yes"
print ans
# Judge status: Accepted
# 1.入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())

# 2.受け取った入力値を使って、適切に処理（計算）すること
answer = a * b

# 3.計算した結果を出力すること
print(answer)
# Judge status: Wrong Answer
s = input()
n = len(s)
a = [0]*(n+1)
for i in range(n):
    if s[i] == '<':
        a[i+1] = max(a[i] + 1, a[i+1])
for i in range(-1, -n, -1):
    if s[i] == '>':
        a[i-1] = max(a[i] + 1, a[i-1])
print(sum(a))
# Judge status: Wrong Answer
n = int(input())

if(n%2 == 1):
    print(0)

else:
    count = 0
    n = n//2
    val  = n/5

    while(int(val) != 0):
        count += int(val)
        val = val/5

    print(count)
# Judge status: Accepted
from collections import Counter
N=int(input())
S=input()
mod = 10**9+7
d = Counter(S)
ans = 1
for v in d.values():
    ans *= v+1
    ans %=mod
print(ans-1)
# Judge status: Accepted
N, M = map(int, input().split())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(M)]
for a, b in ab:
    n = float('inf')
    ans = 0
    for i, tmp in enumerate(cd):
        c, d = tmp
        m = abs(a-c)+abs(b-d)
        if n > m:
            n = m
            ans = i+1
    print(ans)
# Judge status: Accepted
s = input()
ret = "No"
if s[2] == s[3] and s[4]==s[5]:
    ret = "Yes"
print("{}".format(ret))
# Judge status: Wrong Answer
A, B, C = input().split()
A = int(A)
B = int(B)
C = int(C)

if A-B-C<=0:
  print('0')
else:
  print(-1*(A-B-C))
# Judge status: Wrong Answer
a, b, c = map(int, input().split())

if a < b < c or c < b < a:
	print('No')
else:
	print('Yes')
# Judge status: Accepted
n = int(input())
c = input()

ans = 0
l, r = 0, n-1
while True:
  while True:
    if c[l] == "W":
      break
    if l >= r:
      break
    l += 1
    
  while True:
    if c[r] == "R":
      break
    if l >= r:
      break
    r -= 1
  if l >= r:
    break
  ans += 1
  l += 1
  r -= 1
print(ans)
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
amax = a[-1]
tmp1 = amax + 1
for i in a[:n-1]:
    tmp2 = i - amax/2
    if tmp2 > tmp1:
        break
    else:
        r = i
        tmp1 = abs(tmp2)
print(amax, r)
# Judge status: Accepted
import sys

def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)

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

cur = a[0]
for x in a[1:]:
    g = gcd(cur, x)
    if (cur // 2) % g != (x // 2) % g:
        print(0)
        sys.exit(0)
    else:
        cur = cur // g * x
    if cur > m * 2:
        print(0)
        sys.exit(0)

print((m + cur // 2) // cur)
# Judge status: Wrong Answer


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

print(N // (K-1))
# Judge status: Accepted
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

if c1[0]+c2[1]+c3[2] == c1[1]+c2[2]+c3[0] == c1[2]+c2[0]+c3[1]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
k=int(input())
s=str(input())
if k>len(s):
    print(s)
else:
    print(s[0:k]+'...')
# Judge status: Accepted
N, K = map(int, input().split())
mod = 10**9 + 7 
ans = 0 
for i in range(K, N + 2): 
        ans += (((N*(N + 1) // 2) - ((N - i)*(N - i + 1) // 2)) - ((i - 1)*i // 2) + 1) % mod 
print(ans % mod)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

A=sorted(A)

t=0
for i in range(N):
    a=A[3*N-i*2-2]
    t+=a
print(t)
# Judge status: Accepted
n = int(input())
t = [int(input()) for _ in range(5)]
m = min(t)
print((n+m-1)//m+4)
# Judge status: Accepted
a,b = map(int,input().split())

if a%2 == 0 or b%2 == 0:
    print("Even")
else:
    print("Odd")
# Judge status: Accepted
N,X,T = list(map(int, input().split()))

a = N//X
b = N%X
if b > 0:
    a+=1

print(a*T)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline  #文字列入力では注意！

N = int(input())
a,b,c = map(int,input().split())
dp = [[a,b,c]]
for i in range(N-1):
    a,b,c = map(int,input().split())
    A = max(dp[i][1]+a,dp[i][2]+a)
    B = max(dp[i][2]+b,dp[i][0]+b)
    C = max(dp[i][0]+c,dp[i][1]+c)
    dp.append([A,B,C])
print(dp)
print(max(dp[-1]))
# Judge status: Wrong Answer
N, M = map(int,input().split())
A_B = [list(map(int, input().split())) for i in range(N)]

day = 0
ans = 0
A_B = sorted(A_B, key=lambda x:(-x[1], -x[0]))
#print(A_B)
for i in range(N):
  #print(day)
  for j in range(i, N):
    if day + A_B[j][0] <= M:
      ans += A_B[j][1]
      break
  day += 1
print(ans)
# Judge status: Accepted
n=int(input())
ans=0
for i in range(n+1):
  if i%3!=0 and i%5!=0:
    ans+=i
print(ans)
# Judge status: Accepted
n = int(input())
if n == 0:
  print('0')
  exit()
s = ''
while n != 0:
    s = str(n%2)+s
    n //= 2
    n *= -1
print(s)
# Judge status: Wrong Answer
n = int(input())
dat1 = list(map(int,input().split()))
dat2 = list(map(int,input().split()))
dat1.sort()
dat2.sort()
can = True
for i in range(n):
    if dat1[i] > dat2[i]:
        can = False
print("Yes" if can else "No")
# Judge status: Wrong Answer
x = list(map(int,input().split()))

n = x[0]
a = x[1]
b = x[2]

s = input()
c = 0
k = 0

for i in range(0,n):
  if(s[i] == "c"):
    print("No")
    continue
  elif(s[i] == "a"):
    if(c < a + b):
      print("yes")
      c = c + 1
    else:
      print("No")
  else:
    if(c < a + b and k < b):
      print("Yes")
      c = c + 1
      k = k + 1
    else:
      print("No")
      k = k + 1
# Judge status: Accepted
import math
n = int(input())
a = list(map(int,input().split()))
left = [0]*(n+1)
right = [0]*(n+1)

for i in range(n):
  left[i+1] = math.gcd(left[i],a[i])
for i in range(n-1,-1,-1):
  right[i] = math.gcd(right[i+1],a[i])
ans = 0
for i in range(n):
  tmp = math.gcd(left[i],right[i+1])
  ans = max(tmp,ans)
  
print(ans)
# Judge status: Accepted
s=input()
s="2018"+s[4:]
print(s)
# Judge status: Accepted
k, a, b = map(int, input().split())

if b <= a + 1:
	print(k + 1)
else:
	n = (k - (a - 1)) // 2
	r = (k - (a - 1)) % 2
	if r == 0:
		print(n * b - (n - 1) * a)
	elif r == 1:
		print(n * b - (n - 1) * a + 1)
# Judge status: Accepted
def D():
    N, X, Y = map(int, input().split())
    dist = {i: 0 for i in range(1,N)}
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            distance = min(j-i, abs(i-X)+abs(j-Y)+1)
            #print(i, j, distance)
            dist[distance] += 1
    for i in dist:
        print(dist[i])
D()
# Judge status: Wrong Answer
W, H, x, y = map(int, input().split())
print(W*H/2, end=' ')
print(1 if W*y==x**H else 0)
# Judge status: Wrong Answer
S = input()
a = S.count('N') - S.count('S')
b = S.count('E') - S.count('W')

if a == 0 and b == 0:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
import sys

def main(lines):
  line=lines

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)
# Judge status: Accepted
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))

    npa = ct([i+1+j for i, j in enumerate(a)])
    nma = ct([i+1-j for i, j in enumerate(a)])

    cnt = 0

    for i, j in npa.items():
        cnt += j*nma[i]
    print(cnt)


main()
# Judge status: Accepted
N,M,X =map(int,input().split())
CA = [list(map(int,input().split())) for i in range(N)]

ans = float('inf')
for bit in range(1 << N):
    book = [0]*M
    cost = 0
    for i in range(N):
        if(bit >> i) & 1:
            cost += CA[i][0]
            for c in range(M):
                book[c] += (CA[i][c+1])
#    print(book)
    if all(X <= a for a in book):
        ans = min(ans,cost)
if ans == float('inf'):
    print(-1)
else:
    print(ans)
# Judge status: Wrong Answer
n=int(input())
list=list(map(int,input().split()))
for i in range(1,n):
    if list[i-1]>list[i]:
        list[i-1]-=1
        if list[i]==max(list[0:i]):
             continue
        else:
            print("No")
            break
else:print("Yes")
# Judge status: Accepted
n, q = map(int, input().split())
s = str(input())
cum = [0]*n
for i in range(n):
    if i == 0:
        continue
    if s[i-1] == 'A' and s[i] == 'C':
        cum[i] = cum[i-1]+1
    else:
        cum[i] = cum[i-1]
#print(cum)

for i in range(q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    print(cum[r]-cum[l])
# Judge status: Accepted
S = input()
prev = ">"
terrain = []
curr = 0
for c in S:
    if c == prev:
        curr += 1
    else:
        prev = c
        terrain.append(curr)
        curr = 1
terrain += [curr]
ans = (terrain[0] * (terrain[0] + 1)) // 2
for up, down in zip(terrain[1::2], terrain[2::2]):
    if up < down:
        up, down = down, up
    down -= 1
    ans += (up * (up + 1)) // 2
    ans += (down * (down + 1)) // 2
if len(terrain) % 2 == 0:
    ans += terrain[-1] * (terrain[-1] + 1) // 2
print(ans)
# Judge status: Wrong Answer
def test(): 
  arr = input()
  arr = arr.split()
  arr = sorted(arr)
  if arr==[5, 5, 7]:
    print("YES")
  else:
    print("NO")  
test()
# Judge status: Accepted
x = input ()
a = 'Good'
for i in range (3):
  if x[i] == x[i+1]:
    a = 'Bad'
    break
print (a)
# Judge status: Accepted
import sys
import numpy as np

def main():
    n, w = map(int, sys.stdin.buffer.readline().split())
    dp = np.zeros(w+1, dtype = int)

    for x in sys.stdin.buffer.readlines():
        w, v = map(int, x.split())
        np.maximum(dp[w:] , dp[:-w] + v, out = dp[w:])
    print(dp.max())

if __name__ == '__main__':
    main()
# Judge status: Accepted
A,B,T = map(int, input().split())

count = 0
for i in range(A, T+1, A):
  count += B
print(count)
# Judge status: Accepted
LL = input()


count = 0
maxcount = 0

for ll in LL:
    if ll == "R":
        count+= 1
    else:
        count = 0
    
    if maxcount <= count:
        maxcount = count

print(maxcount)
# Judge status: Accepted
n, q = map(int, input().split())
s = input()
lr = [0] * q

def inp(l: list) -> list:
    return [int(l[0]) - 1, int(l[1]) - 1]

for i in range(q):
    lr[i] = tuple(inp(input().split()))

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

# print(count)

for l, r in lr:
    print(count[r] - count[l])
# Judge status: Wrong Answer

N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N

sousa=0
kaisuu=max(K,42)

while sousa<kaisuu:
    for i in range(N):
        ma=i+A[i]+1
        if ma>N:
            ma=N
        mi=i-A[i]
        if mi<0:
            mi=0
        for j in range(mi,ma):
            B[j]+=1
    A=list(B)
    B=[0]*N
    sousa+=1

A=[str(k) for k in A]
print(" ".join(A))
# Judge status: Accepted
s = input()
n = len(s)

for i in range(2, n, 2):
    left = int((n-i)/2)
    tmp1 = s[0:left]
    tmp2 = s[left:n-i]
    if (tmp1 == tmp2):
        print(left * 2)
        break
# Judge status: Accepted
s=input()
s_rev=s[::-1]

mod_count=[0]*2019
mod_count[0]=1
d=1
num=0

for char in s_rev:
  num=num+int(char)*d
  num=num%2019
  d=d*10
  d=d%2019
  #print(type(num),type(mod_count))
  mod_count[num]=mod_count[num]+1

ans=0
for cnt in mod_count:
  ans=ans+cnt*(cnt-1)/2
  
print(int(ans))
# Judge status: Accepted
def ABC_78_B():
    X,Y,Z = map(int, input().split())
    sum=0
    N=0
    while sum<= X:
        sum = Y*N+Z*(N+1)
        N+=1  
    print(N-2)


if __name__ == '__main__':

    ABC_78_B()
# Judge status: Wrong Answer
N = int(input())
points = list(map(int, input().split()))
ans = 0

for k in range(int(sum(points)/2)):
    arc_list = []
    abc_list = []
    for point in points:
        if point >= k:
            arc_list.append(point)
        else:
            abc_list.append(point)
    if len(arc_list) == len(abc_list):
        ans += 1

print(ans)
# Judge status: Accepted
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

n=int(input())
a=list(map(int,input().split()))
b=a[0]
ans=0
for i in range(1,n):
    b=lcm(a[i],b)
for i in range(n):
    ans += b//a[i]
print(ans%(10**9 + 7))
# Judge status: Accepted
s = input()

i1 = int(s[:2])
i2 = int(s[2:])



def f(i):
    if (0 < i < 13):
        return 1
    elif (0 < i < 100):
        return 2
    else:
        return 0


f1 = f(i1)
f2 = f(i2)

if (f1 == 1):
    if (f2 == 1):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if (f2 == 1):
        print("YYMM")
    else:
        print("NA")
# Judge status: Accepted
n=int(input())
if n%2==0:
    print(n//2)
else:
    print(n//2+1)
# Judge status: Wrong Answer
n, a, b = map(int, input().split())
fst = (n - 1) * b + a
sec = (n - 1) * a + b
print(fst - sec + 1)
# Judge status: Accepted
x = int(input())
d = {}
for i in range(1000):
  b = (-1000+i)**5
  d[b] = -1000+i
for i in range(1000):
  a = i**5
  d[a] = i
  if a-x in d:
    b = d[a-x]
    a = i
    break
print(a,b)
# Judge status: Wrong Answer
n, k = map(lambda x: int(x), input().split())
s = input()
 
str = ""
for i in range(n):
  if i - 1 == k:
    str += s[i].lower()
  else:
    str += s[i]
print(str)
# Judge status: Accepted
from collections import Counter
import heapq
N,M = map(int,input().split())
A = Counter(list(map(int,input().split())))

cards = []
for x,y in A.items():
  heapq.heappush(cards, (-x,y))

for _ in range(M):
  b,c = map(int,input().split())
  heapq.heappush(cards, (-c,b))
cnt = N
ans = 0
while cnt <= N:
  v,c = heapq.heappop(cards)
  v *= -1
  if cnt-c < 0:
    ans += v*cnt
    break
  else:
    ans += v*c
    cnt -= c

print(ans)
# Judge status: Accepted
n=int(input())
w=list(map(int,input().split()))
k=sum(w)
s1=w[0]
mi=abs(k-2*w[0])
for i in range(1,n-1):
    s1=s1+w[i]
    if abs(k-2*s1)<mi:
        mi=abs(k-2*s1)
print(mi)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.reverse()
B.reverse()
cnt = 0
tmp = 0
tmp2 = 0

for i in range(N):
    if A[i] >= B[i]:
        cnt += B[i]
    else:
        tmp = B[i] - A[i]
        cnt += A[i]
        if A[i+1] >= tmp:
            cnt += tmp
        else:
            cnt += A[i+1]
            A[i+1] = 0

print(cnt)
# Judge status: Wrong Answer
from collections import Counter

n = int(input())
s = input()
mod = 10**9 + 7

c = Counter(s)
ans = 1

for i in range(ord("a"), ord("z")+1):
    ans *= (c[chr(i)] + 1)

print(ans - 1)
# Judge status: Accepted
N,M = map(int,input().split())

AC = set()
WA = [0]*N

for i in range(M):
    k,l = input().split()
    k = int(k)
    if l=="WA":
        if not k in AC:
            WA[k-1] += 1
    
    else:
        if not k in AC:
            AC.add(k)

counter = 0
for i in AC:
    counter += WA[i-1]

print("{} {}".format(len(AC),counter))
# Judge status: Accepted
N,S = open(0).read().split()
N = int(N)
w = S.count('.')
ans = float('inf')
ws = [0] * (N+1)
for i in range(1,N+1):
    ws[i] = ws[i-1]
    if S[i-1] == '.':
        ws[i] += 1
for i in range(N+1):
    ans = min(ans,i-2*ws[i]+w)
print(ans)
# Judge status: Wrong Answer
N=int(input())
W=list(map(int,input().split()))

val=0
total=sum(W)
while True:
    for i in range(N):
        val+=W[i]
        if val>=total//2:
            break
    break

print(val-(total-val))
# Judge status: Wrong Answer
N = int(input())
S = input()
ind = S.find('#')
if ind == -1:
    print(0)
else:
    print(S.count('.', ind))
# Judge status: Wrong Answer
n=int(input())
l=list(map(int,input().split()))
s=float('inf')
for a in l:
    c=0
    while 1:
        if a%2!=0:
            break
        a/=2
        c+=1
    s=min(s,c)
print(c)
# Judge status: Wrong Answer
s = input()

s = sorted(s)

if s == "abc":
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n,k = map(int, raw_input().split())
s = raw_input()
cd = 0
d = None
for l in s:
	if d != l:
		cd +=1
		d = l
score = 0
for u,v in zip(s,s[1:]):
	if u == v:
		score +=1

if cd > 2:
	score += (cd - 2) * 2
	cd = 2
if cd == 2:
	score +=1
print score
# Judge status: Accepted
a,b = map(int, input().split())
cnt = 0
for i in range(a, b+1):
    s = str(i)
    g = s[::-1]
    if (s == g): cnt += 1
print(cnt)
# Judge status: Accepted
x,y = map(int,input().split())

if x % y == 0:
    print(-1)
else:
    print(x)
# Judge status: Accepted
A, B, K = map(int, input().split())
taka,aoki = 0, 0
taka = max(0,A-K)
aoki = max(0,B + min(0,A-K))
print(taka,aoki)
# Judge status: Wrong Answer
N = int(input())
S = input()
T = input()
ans = S+T
for i in range(1,N+1):
    #print(S[-i:],T[:i])
    if S[-i:] == T[:i]:
        ans = S + T[i:]
print(ans)
# Judge status: Accepted
A,B=map(int,input().split())
if A>=13:
    print(B)
elif 6<=A<=12:
    print(B//2)
else:
    print(0)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))

xor_total = 0
for sunuke in a:
    xor_total = xor_total ^ sunuke

for i in range(N):
    print(xor_total ^ a[i])
# Judge status: Accepted
from fractions import gcd

def calc_lcm(x, y):
    return (x * y) // gcd(x, y)

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

lcm = a[0]
for i in range(1, n):
    lcm = calc_lcm(lcm, a[i])

s = 0
for i in range(n):
    s += lcm // a[i]

ans = s % 1000000007
print(ans)
# Judge status: Accepted
N, K = map(int, input().split())
S = list(input())

S[K-1] = chr(ord(S[K-1]) + 32)

print("".join(S))
# Judge status: Accepted
W, H, x, y = map(int, input().split())

if x == W/2 and y == H/2:
    area = (W*H)/2
    print(area, 1)
else:
    area = (W*H)/2
    print(area, 0)
# Judge status: Accepted
N, K, S = map(int, input().split())

if S == 10**9:
    A = [S]*K + [1]*(N-K)
else:
    A = [S]*K + [S+1]*(N-K)

print(' '.join(map(str, A)))
# Judge status: Accepted
x = int(input())
for i in range(1,20):
    if i*100<=x<=i*105:
        print(1)
        break
else:
    if x>=2000:
        print(1)
    else:
        print(0)
# Judge status: Accepted
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = []
for _ in range(M):
    xyc.append(tuple(map(int, input().split())))

m = min(a) + min(b)
for ticket in xyc:
    x, y, c = ticket
    temp = a[x - 1] + b[y - 1] - c
    m = min(temp, m)
print(m)
# Judge status: Accepted
from collections import deque

K = int(input())
queue = deque([i for i in range(1,10)])

while K != 0:
  if K <= len(queue):
    print(queue[K-1])
    exit(0)

  K -= 1
  num = queue.popleft()

  o = int(str(num)[-1])
  for n in [o-1, o, o+1]:
    if n == -1 or n == 10: continue
    queue.append( int(str(num)+str(n)) )
# Judge status: Accepted
import sys
import math
 
 
def input():
    return sys.stdin.readline().rstrip()
 
 
def main():
    N, Q = map(int, input().split())
    S = list(input())
    t = [0] * N
    count =0
    for i in range(1,N):
        if S[i-1]=="A" and S[i] =="C":
            count +=1
        t[i] =count
 
    for j in range(Q):
        l, r = map(int,input().split())
        print(t[r-1]-t[l-1])
 
if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
h,w = map(int,input().split())

x = h//2 if h%2==0 else h//2+1
y = w//2 if w%2==0 else w//2+1

print(x*y+(h-x)*(w-y))
# Judge status: Accepted
S = input()

res = 0
tmp = ""
last = ""

for s in S:
    tmp += s
    if tmp == last:
        continue

    last = tmp
    tmp = ""
    res += 1

print(res)
# Judge status: Accepted
x = int(input())

if x==0:
  print(1)
elif x==1:
  print(0)
# Judge status: Accepted
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor
import collections

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))


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

ans = "No"


if A==B and A!=C:
    ans = "Yes"
if A==C and A!=B:
    ans = "Yes"
if B==C and A!=B:
    ans = "Yes"

print(ans)
# Judge status: Accepted
n = int(input())
A,B = [],[]
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if n%2==1:
    x = A[n//2]
    y = B[n//2]
else:
    x = A[n//2 - 1]+A[n//2]
    y = B[n//2 - 1]+B[n//2]
print(y-x+1)
# Judge status: Accepted
a,b = map(str, input().split())
c = int(a+b)
line = [i**2 for i in range(1,321)]
if c in line:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    tmp = input()
    if tmp == "AC":
        ac += 1
    elif tmp == "WA":
        wa += 1
    elif tmp == "TLE":
        tle += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))
# Judge status: Accepted
word = input()

if word.isupper() == True:
  print("A")
else:
  print("a")
# Judge status: Wrong Answer
import numpy as np

N, M, X = list(map(int, input().split()))
array = np.array([list(map(int, input().split())) for _ in range(N)])

min_C = np.inf
conbi = None
m = 2**N

for i in range(m):
  tmp = []
  for _ in range(N):
    tmp.append(i%2)
    i //= 2
  
  sum_array = np.sum(array[np.where(tmp)], axis=0)
  #print(tmp)
  if np.all(sum_array>=X):
    if sum_array[0] < min_C:
      min_C = sum_array[0]
      conbi = tmp
      
if conbi is None:
  print(-1)
else:
  print(min_C)
# Judge status: Wrong Answer
def main():
    n = int(input())
    num = n
    name = []
    cap = [chr(i) for i in range(97, 97+26)]
    cap.insert(0, 'z')
    del cap[-1]
    if n == 26:
        return 'z'
    while n >= 27:
        last = n % 26 
        n = n // 26
        name.insert(0, cap[last])
    last = (n % 26) - 1
    name.insert(0, cap[last])
    ans = "".join(name)
    return ans
print(main())
# Judge status: Accepted
N = int(input())
B = list(map(int,input().split()))

import copy
A = copy.deepcopy(B)
for i in range(1,N-1):
    if B[i-1]<B[i]:
        A[i] = B[i-1]
        
A.append(B[-1])
print(sum(A))
# Judge status: Accepted
import math
N,H=map(int,input().split())
sword=[list(map(int,input().split())) for _ in range(N)]
throw=0
smash=0
cnt=0
sword.sort(key=lambda x:x[0],reverse=True)
smashmax=sword[0][0]
sword.sort(key=lambda x:x[1],reverse=True)
for i in range(N):
    if (smashmax<=sword[i][1])and(throw<H):
        throw=throw+sword[i][1]
        cnt=cnt+1
if throw>=H:
    print(cnt)
else:
    print(cnt+math.ceil((H-throw)/smashmax))
# Judge status: Wrong Answer
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
s=0 #本数
t=0 #値段
for i in range(N):
  s+=A[i][1]
  if M>s:
    t+=A[i][0]*A[i][1]
  else:
    over=s-M
    t+=A[i][0]*A[i][1]-A[i][0]*over
print(t)