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

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

if 3*a < b:
  print(ans)
else:
  for i in range(a+1):
    if i > b:
      continue
    else:
      for j in range(a+1):
        if i+j > b:
          continue
        else:
          for k in range(a+1):
            if i+j+k == b:
              ans += 1
              
  print(ans)

### FIXED CODE ###

k,s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
  mx = min(k, s-x)
  mn = max(0, s-x-k)
  ans += max(0, mx-mn+1)
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
from functools import lru_cache
import sys
sys.setrecursionlimit(10**6)

n,m = [int(i) for i in input().split()]

#ko = [[] for _ in range(n)]
oya = [[] for _ in range(n)]
for _ in range(m):
    x,y = [int(i)-1 for i in input().split()]
#    ko[x].append(y)
    oya[y].append(x)

#memo = [-1]*n

@lru_cache(maxsize=None)
def longest(v): #nを終点とするlongest
#    if memo[v] >= 0:
#        return memo[v]
#    else:
    c=0
    for j in oya[v]:
        c = max(c,longest(j)+1)
#    memo[v] = c
    return c

memo = [longest(i) for i in range(n)]

print(max(memo))    
#print(memo)


### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)

n,m = [int(i) for i in input().split()]

#ko = [[] for _ in range(n)]
oya = [[] for _ in range(n)]
for _ in range(m):
    x,y = [int(i)-1 for i in input().split()]
#    ko[x].append(y)
    oya[y].append(x)

memo = [-1]*n

def longest(v): #nを終点とするlongest
    if memo[v] >= 0:
        return memo[v]
    else:
        c=0
        for j in oya[v]:
            c = max(c,longest(j)+1)
        memo[v] = c
        return c

for i in range(n):
    longest(i)

print(max(memo))    
#print(memo)
### BUGGY CODE ###

def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    n,k=map(int,input().split())
    a=set()
    MOD=998244353
    for i in range(k):
      l,r=map(int,input().split())
      for j in range(l-1,r):
        a.add(j)
    dp=[0]*n*2
    dp[0]=1
    for i in range(1,n):
      x=dp[i-1]
      if x==0:
        continue
      else:
        for j in a:
          dp[i+j]+=x
          dp[i+j]%=MOD
    print(dp[n-1])
    
if __name__ == '__main__':
    resolve()

### FIXED CODE ###

def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    n,k=map(int,input().split())
    MOD=998244353
    lr=[list(map(int,input().split())) for _ in range(k)]
    dp=[0]*(n+1)
    dpsum=[0]*(n+1)
    dp[1]=1
    dpsum[1]=1
    for i in range(2,n+1):
      for l,r in lr:
        li=i-r
        ri=i-l
        if r<0:continue
        li=max(1,li)
        dp[i]+=dpsum[ri]-dpsum[li-1]
      dpsum[i]=(dpsum[i-1]+dp[i])%MOD
    print(dp[n]%MOD)
    
if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (3**q+c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (3**q + c*3) % mod
    q += 1
print(abc)


### FIXED CODE ###

s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (pow(3,q,mod) + c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (pow(3,q,mod) + c*3) % mod
    q += 1
print(int(abc))
### BUGGY CODE ###

s = input()

N = int(s.split()[0])
M = int(s.split()[1])

H = input().split()

tenbo = list(range(1,N+1))

for i in range(M):
  road = input().split()
  A = int(road[0])
  B = int(road[1])
  HA = int(H[A-1])
  HB = int(H[B-1])
  if HA >= HB and B in tenbo:
    tenbo.remove(B)
  if HA <= HB and A in tenbo:
    tenbo.remove(A)
    
print(len(tenbo))

### FIXED CODE ###

s = input()

N = int(s.split()[0])
M = int(s.split()[1])

H = input().split()

tenbo = list(range(1,N+1))
bad_tenbo = []

for i in range(M):
  road = input().split()
  A = int(road[0])
  B = int(road[1])
  HA = int(H[A-1])
  HB = int(H[B-1])
  if HA > HB:
    bad_tenbo.append(B)
  elif HA == HB:
    bad_tenbo.append(A)
    bad_tenbo.append(B)
  elif HA < HB:
    bad_tenbo.append(A)
    
result = list(set(tenbo) - set(bad_tenbo))
    
print(len(result))
### BUGGY CODE ###

S = input()
Q = int(input())

rev_flag = False

for i in range(Q):
  in_ = input()
  if len(in_) > 1:
    _, f, c = in_.split()
    f = int(f)
    
    if rev_flag:
      if f==1:
        S = S + c
      elif f==2:
        S = c+S
    else:
      if f==2:
        S = S + c
      elif f==1:
        S = c + S
    
  else:
    # reverse    
    rev_flag = not rev_flag

if rev_flag:
  print(S[-1::-1])
else:
  print(S)
    
  

### FIXED CODE ###

S = input()
Q = int(input())

rev_flag = False

heads = []
tails = []

for i in range(Q):
  in_ = input()
  if len(in_) > 1:
    _, f, c = in_.split()
    f = int(f)
    
    if rev_flag:
      if f==1:
        #S = S + c
        tails.append(c)
      elif f==2:
        #S = c+S
        heads.append(c)
    else:
      if f==2:
        #S = S + c
        tails.append(c)
      elif f==1:
        #S = c + S
        heads.append(c)
    
  else:
    # reverse    
    rev_flag = not rev_flag

if rev_flag:
  ans = "".join(tails[-1::-1]) + S[-1::-1] + "".join(heads)
else:
  ans = "".join(heads[-1::-1]) + S + "".join(tails)

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

from collections import deque, defaultdict
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    adj = defaultdict(lambda: [])
    for _ in range(M):
        L, R, D = map(int, input().split())
        adj[L].append((R, D))
        adj[R].append((L, -D))
    seen = [0] * (N + 1)

    def dfs(adj, start):
        inf = 10 ** 10
        que = deque()
        que.append(start)
        x = [inf] * (N + 1)
        x[start] = 0
        while que:
            v = que.pop()
            seen[v] = 1
            for u, d in adj[v]:
                if seen[u] == 0:
                    que.append(u)
                    if x[u] == inf:
                        x[u] = x[v] + d
                    else:
                        if x[u] != x[v] + d:
                            print('No')
                            sys.exit()

    for i in range(1, N + 1):
        if seen[i] == 0:
            dfs(adj, i)

    print('Yes')


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque
import sys
import time
input = sys.stdin.readline


def main():
    t1 = time.time()
    N, M = map(int, input().split())
    adj = [[] for _ in range(N + 1)]
    for _ in range(M):
        L, R, D = map(int, input().split())
        adj[L].append((R, D))
        adj[R].append((L, -D))
    seen = [0] * (N + 1)

    def dfs(adj, seen, start):
        inf = 10 ** 10
        que = deque()
        que.append(start)
        x = [inf] * (N + 1)
        x[start] = 0
        while que:
            v = que.pop()
            seen[v] = 1
            for u, d in adj[v]:
                if seen[u] == 0:
                    que.append(u)
                    if x[u] == inf:
                        x[u] = x[v] + d
                    else:
                        if x[u] != x[v] + d:
                            print('No')
                            sys.exit()
            t2 = time.time()
            if t2 - t1 > 1.8:
                print('Yes')
                sys.exit()
        return seen

    for i in range(1, N + 1):
        if seen[i] == 0:
            seen = dfs(adj, seen, i)

    print('Yes')


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

import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
A = np.sort(A)

c = 0
while len(A) > 0:
    ai = A[0]
    if not ai in A[1:]:
        c += 1
    mask = A[1:] % ai != 0
    A = A[1:][mask]

print(c)


### FIXED CODE ###

from collections import Counter
n = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)
A = list(set(A))
ok = [True] * (10**6+1)

for a in A:
    temp = a+a
    while temp < 10**6+1:
        ok[temp] = False
        temp += a

c = 0
for a in A:
    if C[a] == 1 and ok[a] == True:
        c += 1
print(c)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
INL=list(map(float, LS()))
DP=[0.0]*(N+1)
DP[0]=1.0

for p in INL:
    for i in reversed(range(N)):
        DP[i+1] = DP[i+1]*(1.0-p) + DP[i]*p

# print(DP)
print(DP[N//2+1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
INL=list(map(float, LS()))
DP=[0.0]*(N+1)
DP[0]=1.0

for p in INL:
    for i in reversed(range(N)):
        DP[i+1] = DP[i+1]*(1.0-p) + DP[i]*p

# print(DP)
print(DP[N//2+1])
### BUGGY CODE ###

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

count = [0]
sum = 0

for i in A:
    if max(count) > i:
        sum += max(count) -i
        count.append(i)
    else:
        count.append(i)

print(sum)

### FIXED CODE ###

n = input()
x = input().split()
m = 0
cnt = 0
 
for i in x:
    ii = int(i)
    if m < ii:
        m = ii
    elif m > ii:
        cnt += m - ii
 
print(cnt)
### BUGGY CODE ###


N = int(input())

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

P = [0] + P
     
count = 0
for i in range(1, N+1):
    for j in range(1, i+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
else:
    print(count)

### FIXED CODE ###

N = int(input())

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

P = [0] + P
     
count = 0
min = 10000000000000
for i in range(1, N+1):
    if min > P[i]:
        min = P[i]
    elif min < P[i]:
        continue
    """
    for j in range(1, i+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
    """
    count += 1
        
    if P[i] == 1:
        break

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

def calc_g(x,k):
    while(x>=k):
        if(x%k==0):
            return x//k
        x -= (x//k) + 1
    return 0

grundy = 0
it = iter(data)
for a,k in zip(it,it):
    grundy = grundy ^ calc_g(a,k)

if(grundy==0):
    print('Aoki')
else:
    print('Takahashi')

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

def calc_g(x,k):
    while(x>=k):
        if(x%k==0):
            return x//k
        fn = x//k
        x1 = x - (fn + 1)
        x2 = fn*k + (x%k)%(fn+1)
        x = min(x1,x2)
    return 0

grundy = 0
it = iter(data)
for a,k in zip(it,it):
    grundy = grundy ^ calc_g(a,k)

if(grundy==0):
    print('Aoki')
else:
    print('Takahashi')
### BUGGY CODE ###

N, M = map(int, input().split())
ans = 1
for n in range(2, M//N+1):
    if M % n == 0 and M//n >= N:
        ans = n
print(ans)


### FIXED CODE ###

N, M = map(int, input().split())
ans = 1
n = 1
while n*n <= M:
    if M % n == 0:
        if M//n >= N:
            ans = max(n, ans)
        m = M//n
        if M//m >= N:
            ans = max(m, ans)
    n += 1
print(ans)
### BUGGY CODE ###

N = int(input())
C = [int(input()) for _ in range(N)]
   
i=0 
while i+1<len(C):
    if C[i]==C[i+1]:
        C.pop(i+1)
    else:
        i+=1

DP = [1]
dic = {}      

for i in range(len(C)):  
    DP.append(DP[-1]+dic.get(C[i],0))            
    dic[C[i]] = DP[-1]            
print(DP[-1]%(10**9+7))

### FIXED CODE ###

N = int(input())
C = [int(input()) for _ in range(N)]
C = [x for x,y in zip(C[:-1],C[1:]) if x!=y] + [C[-1]]

DP = [1]
dic = {}

for i in range(len(C)):   
    DP.append((DP[-1]+dic.get(C[i],0))%(10**9+7))    
    dic[C[i]] = DP[-1]
print(DP[-1])
### BUGGY CODE ###

from collections import deque
import numpy as np

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

dist = np.full((H, W), -1, dtype='int8')
dq = deque()

for r in range(H):
    for c in range(W):
        if a[r][c] == '#':
            dist[r, c] = 0
            dq.append((r, c))


def in_range(r, c):
    return 0 <= r < H and 0 <= c < W


dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)

d = 0
while dq:
    r, c = dq.popleft()
    d = dist[r][c]
    for dr, dc in zip(dr_s, dc_s):
        nr = r + dr
        nc = c + dc
        if not in_range(nr, nc): continue
        if dist[nr][nc] != -1: continue
        dist[nr][nc] = d + 1
        dq.append((nr, nc))

print(d)


### FIXED CODE ###

from collections import deque

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

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

for r in range(H):
    for c in range(W):
        if a[r][c] == '#':
            dist[r][c] = 0
            dq.append((r, c))


def in_range(r, c):
    return 0 <= r < H and 0 <= c < W


dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)

d = 0
while dq:
    r, c = dq.popleft()
    d = dist[r][c]
    for dr, dc in zip(dr_s, dc_s):
        nr = r + dr
        nc = c + dc
        if not in_range(nr, nc): continue
        if dist[nr][nc] != -1: continue
        dist[nr][nc] = d + 1
        dq.append((nr, nc))

print(d)
### BUGGY CODE ###

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

from collections import Counter

c = Counter(A)

for i in range(1,N+1):
    if str(i) in list(c):
        print(c[str(i)])
    else:
        print(0)



### FIXED CODE ###

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

x = [0]*N

for a in A:
    x[a-1] += 1

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

X, Y = map(int,input().split())
MOD = 10 ** 9 + 7
if (X + Y) % 3 != 0 or 2 * X < Y or 2 * Y < X:
    print(0)
else:
    turn = (X + Y) // 3
    turn2 = X - turn
    turn1 = turn - turn2
    ans = 1
    for i in range(turn1):
        ans *= turn - i
        ans //= i + 1
    print(ans % MOD)

### FIXED CODE ###

X, Y = map(int,input().split())
MOD = 10 ** 9 + 7
if (X + Y) % 3 != 0 or 2 * X < Y or 2 * Y < X:
    print(0)
elif 2 * X == Y or 2 * Y == X:
    print(1)
else:
    turn = (X + Y) // 3
    turn2 = X - turn
    turn1 = turn - turn2
    ans = turn
    inv = [0, 1]
    for i in range(2, min(turn1, turn2) + 1):
        ans = ans * (turn - i + 1) % MOD
        ans = ans * (-inv[MOD % i] * (MOD // i)) % MOD
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    print(ans % MOD)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

def main():

    """
    # color: 親と自らを繋ぐ辺の色
    # now: 現在地
    """
    def dfs(color,now):
        # 現在地が葉のとき
        if not now in a:
            return

        # 現在地から伸びる辺のインデックス
        index = [i for i in range(N-1) if now == a[i]]

        # 子ノードに伸びる辺を色塗り
        number = 1
        for i in range(len(index)):
            if number == color:
                number += 1
            K[index[i]] = number
            # 子ノードで色塗り開始
            dfs(number, b[index[i]])
            number += 1

    N = int(input())
    a = [0] * (N-1)
    b = [0] * (N-1)
    for i in range(N-1):
        a[i],b[i] = map(int,input().split())
    # 辺の色
    K = [0] * (N-1)
    dfs(0,min(a))
    print(len(set(K)))
    for i in K:
        print(i)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N-1)]

# graph[i]: 頂点iの親と子の集合
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

# 根
root = 1
# parent[i]: 頂点iの親
parent = [0]*(N+1)
# トポロジカル順序
order = []
# 未探索の頂点
stack = [root]

# dfsでparentを求める
while stack:
    # n: 探索する頂点
    n = stack.pop()
    order.append(n)
    for j in graph[n]:
        # jがnの親の場合
        if j == parent[n]:
            continue
        parent[j] = n
        stack.append(j)

# color[i]: 頂点iと親を繋ぐ辺の色
color = [-1] * (N+1)
# dfsで色を塗る
for i in order:
    # 既に使用した色
    ng = color[i]
    # 色
    c = 1
    for j in graph[i]:
        # jがiの親の場合(塗装済みなのでcontinue)
        if j == parent[i]:
            continue
        if c == ng:
            c += 1
        # 頂点iと頂点jの辺に色を塗る
        color[j] = c
        c += 1

# 入力順に辺の色を出力する
answer = [color[a] if parent[a]==b else color[b] for a,b in AB]
print(max(answer))
print("\n".join(map(str,answer)))
### BUGGY CODE ###

N, M, Q = list(map(int, input().split(' ')))
st_ed = {}
for i in range(M):
    l, r = list(map(int, input().split(' ')))
    st_ed[(l, r)] = st_ed.get((l, r), 0) + 1
memo = {}
for i in range(Q):  # 1e5
    p, q = list(map(int, input().split(' ')))
    if not (p, q) in memo:
        temp = 0
        for j in range(p, q + 1):  # * 5e2 = 5e7
            for k in range(j, q + 1):  # * 5e2 = 2.5e10 > 2e10 ...
                temp += st_ed.get((j, k), 0)
        memo[(p, q)] = temp
    print(memo[(p, q)])


### FIXED CODE ###

N, M, Q = list(map(int, input().split(' ')))
st_ed = {}
for i in range(M):
    l, r = list(map(int, input().split(' ')))
    st_ed[(l, r)] = st_ed.get((l, r), 0) + 1

memo_g = {}
def g(p, q):
    if p == q:
        return st_ed.get((p, q), 0)
    if not (p, q) in memo_g:
        memo_g[(p, q)] = st_ed.get((p, q), 0) + g(p + 1, q)
    return memo_g[(p, q)]

memo_f = {}
# memo[(p, q)] = memo[(p, q-1)] + sum([st_ed.get((i, q), 0) for i in [1,2,3...p]])
def f(p, q):
    if p == q:
        return st_ed.get((p, q), 0)
    if not (p, q) in memo_f:
        temp = f(p, q - 1) + g(p, q)
        memo_f[(p, q)] = temp
    return memo_f[(p, q)]

memo = {}
for i in range(Q):  # 1e5
    p, q = list(map(int, input().split(' ')))
    if not (p, q) in memo:
        temp = f(p, q)
        memo[(p, q)] = temp
    print(memo[(p, q)])
### BUGGY CODE ###

import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

left = -INF
right = INF
while right - left > 1:
    x = (left + right) // 2
    s = 0 # num of less than or equal to x
    t = 0 # duplication
    for a in A:
        if a > 0:
            l = -1
            r = N
            while r - l > 1:
                m = (l + r) // 2
                if A[m] * a <= x:
                    l = m
                else:
                    r = m
            s += r
        elif a < 0:
            l = -1
            r = N
            while r - l > 1:
                m = (l + r) // 2
                if A[m] * a <= x:
                    r = m
                else:
                    l = m
            s += N - r
        elif a == 0 and x >= 0:
            s += N

        if a * a <= x:
            t += 1
    count = (s - t) // 2
    if count >= K:
        right = x
    else:
        left = x
print(right)


### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

left = -INF
right = INF
while right - left > 1:
    x = (left + right) // 2
    s = 0 # num of less than or equal to x
    t = 0 # duplication
    for a in A:
        if a > 0:
            l = -1
            r = N
            while r - l > 1:
                m = (l + r) // 2
                if A[m] * a <= x:
                    l = m
                else:
                    r = m
            s += r
        elif a < 0:
            l = -1
            r = N
            while r - l > 1:
                m = (l + r) // 2
                if A[m] * a <= x:
                    r = m
                else:
                    l = m
            s += N - r
        elif a == 0 and x >= 0:
            s += N

        if a * a <= x:
            t += 1
    count = (s - t) // 2
    if count >= K:
        right = x
    else:
        left = x
print(right)
### BUGGY CODE ###

N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
B = sorted(A)
count = 0

for i in range(N-1):
  for j in range(i+1, N):
    if B[i] != B[j]:
      continue
    else:
      count += 1

print(count)

### FIXED CODE ###

N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
count = 0

B = sorted(A)
A_unique_count = 1

for i in range(N-1):
  if B[i] == B[i+1]:
    A_unique_count += 1
  else:
    count += A_unique_count * (A_unique_count -1) /2
#    print('i' + str(i))
#    print(count)
    A_unique_count = 1

count += A_unique_count * (A_unique_count -1) /2
print(int(count))
### BUGGY CODE ###

d = {}
N = int(input())

for _ in range(N):
    s = str(input())
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 1

sd = sorted(d.items())

for i in range(len(sd)):
    if sd[i][1] == max(d.values()):
        print(sd[i][0])

### FIXED CODE ###

N = int(input())
l = []

for _ in range(N):
    s = str(input())
    l.append(s)

import collections
c = collections.Counter(l)
c = c.most_common()

most_count = c[0][1]
c.sort()

for i in range(len(c)):
    if c[i][1] == most_count:
        print(c[i][0])
### BUGGY CODE ###

nmq=list(map(int, input().split()))
N=nmq[0]
M=nmq[1]
Q=nmq[2]
ablist=[]
for i in range(Q):
    tp=tuple(map(int, input().split()))
    ablist.append(tp)
sumlist=[]
alist=[i for i in range(1,M+1)]
import itertools as ite
case=list(ite.combinations_with_replacement(alist,N))
for nowcase in case:
    sumd=0
    for i in range(Q):
        a=ablist[i][0]
        b=ablist[i][1]
        c=ablist[i][2]
        d=ablist[i][3]
        aa=nowcase[a-1]
        ab=nowcase[b-1]
        if ab-aa==c:
            sumd+=d
    sumlist.append(sumd)
print(max(sumlist))


### FIXED CODE ###

nmq=list(map(int, input().split()))
N=nmq[0]
M=nmq[1]
Q=nmq[2]
ablist=[]
for i in range(Q):
    tp=tuple(map(int, input().split()))
    ablist.append(tp)
sumlist=[]
alist=[i for i in range(1,M+1)]
import itertools
case=list(itertools.combinations_with_replacement(alist,N))
for nowcase in case:
    sumd=0
    for i in range(Q):
        if nowcase[ablist[i][1]-1]-nowcase[ablist[i][0]-1]==ablist[i][2]:
            sumd+=ablist[i][3]
    sumlist.append(sumd)
print(max(sumlist))
### BUGGY CODE ###

N,Q = map(int,input().split())
S = list(input())
s = []
for i in range(Q):
    l,r = map(int,input().split())
    c = 0
    #print(Q,i)
    s.append(0)
    #print(s)
    for j in range(l-1,r):
        #print(i,j)
        if c == 0 and S[j] == "A":
            c = 1
            #print("a")
        elif c == 1 and S[j] == "C":
            c = 0
            s[i] = s[i]+ 1
            #print("b")
    #print(i)
for i in range(Q):
    print(s[i])

### FIXED CODE ###

N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])