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

from collections import deque


def bfs(root):
    global time
    Q = deque()
    distance[root] = 0
    Q.append(root)
    i = root
    while len(Q) > 0:
        i = Q.popleft()
        for v in range(n):
            if v in adjDict[i] and color[v] == 'white':
                Q.append(v)
                color[v] = 'gray'
                distance[v] = distance[i] + 1
        color[i] = 'black'
        label[i] = time


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

n = firstline[0]
adjDict = {i: [] for i in range(n)}
color = ['white'] * n
distance = [-1] * n
label = [-1] * n

m = firstline[1]
for _ in range(m):
    adj = list(map(int, input().split()))
    adjDict[adj[0]].append(adj[1])
    adjDict[adj[1]].append(adj[0])

time = 0
for i in range(n):
    if color[i] == 'white':
        bfs(i)
        time += 1

q = int(input())
for _ in range(q):
    question = list(map(int, input().split()))
    if label[question[0]] == label[question[1]]:
        print('yes')
    else:
        print('no')

### FIXED CODE ###

from collections import deque


def bfs(root):
    global time
    Q = deque()
    distance[root] = 0
    Q.append(root)
    i = root
    while len(Q) > 0:
        i = Q.popleft()
        for v in adjDict[i]:
            if color[v] == 'white':
                Q.append(v)
                color[v] = 'gray'
                distance[v] = distance[i] + 1
        color[i] = 'black'
        label[i] = time


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

n = firstline[0]
adjDict = {i: [] for i in range(n)}
color = ['white'] * n
distance = [-1] * n
label = [-1] * n

m = firstline[1]
for _ in range(m):
    adj = list(map(int, input().split()))
    adjDict[adj[0]].append(adj[1])
    adjDict[adj[1]].append(adj[0])

time = 0
for i in range(n):
    if color[i] == 'white':
        bfs(i)
        time += 1

q = int(input())
for _ in range(q):
    question = list(map(int, input().split()))
    if label[question[0]] == label[question[1]]:
        print('yes')
    else:
        print('no')
### BUGGY CODE ###

n=input()
n=int(n)
i=0
count = 0
lst=list()
while i<n:
	S=input()
	if S not in lst:
		# print(S)
		count += 1
		lst.append(S)
	# print(S)
	i+=1
print(count)

### FIXED CODE ###

n=input()
n=int(n)
i=0
d=dict()
while i<n:
	s=input()
	d[s]=d.get(s,0)+1
	i+=1
print(len(d.keys()))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
INF = 10 ** 9
MOD = 10 ** 9 + 7

def main(): 
    h,w,d = map(int,input().split())
    n = h * w

    idx = [0]*(1+n)
    for i in range(1,h+1):
        a = tuple(map(int,input().split()))
        for j in range(w):
            idx[a[j]] = (i,j+1)
    idx[0] = idx[d]

    D = [[0]*(n+1) for _ in range(n+1)]
    
    def dist(i,j):
        return abs(idx[i][0] - idx[j][0]) + abs(idx[i][1] - idx[j][1])
        
    for i in range(d):
        num = i
        while num <= n - d:
            D[num + d][i] = D[num][i] + dist(num,num + d)
            num += d
    
    q = int(input())
    for _ in range(q):
        l,r = map(int,input().split())
        modd = l%d
        print(D[r][modd] - D[l][modd])        

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
INF = 10 ** 9
MOD = 10 ** 9 + 7

def main(): 
    h,w,d = map(int,input().split())
    n = h * w

    idx = [0]*(1+n)
    for i in range(h):
        a = tuple(map(int,input().split()))
        for j in range(w):
            idx[a[j]] = (i + 1 , j + 1)
    idx[0] = idx[d]

    D = [0] * (n + 1)
    
    def dist(i,j):
        return abs(idx[i][0] - idx[j][0]) + abs(idx[i][1] - idx[j][1])
        
    for i in range(d):
        for j in range(i,n - d + 1,d):
            D[j + d] = D[j] + dist(j,j + d)
    
    q = int(input())
    for _ in range(q):
        l,r = map(int,input().split())
        print(D[r] - D[l])        

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

# coding: utf-8
# Your code here!
import numpy as np

N,M = map(int,input().split(' '))
A = []
B = []

for _ in range(N):
    AB = list(map(int,input().split()))
    A.append(AB[0])
    B.append(AB[1])

A=np.array(A)
B=np.array(B)
Money = 0
Drink = 0
while True:
    minidx = np.argmin(A)
    Money += A[minidx]*B[minidx]
    Drink += B[minidx]
    if Drink >= M:
        Money = Money - (A[minidx]*(Drink - M))
        break
    A = np.delete(A, minidx)
    B = np.delete(B, minidx)
    
print(Money)

### FIXED CODE ###

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

AB = sorted(list(map(int,input().split())) for _ in range(N))
Money = 0
for A,B in AB:
    x = min(B,M)
    Money += A * x
    M -= x
print(Money)
### BUGGY CODE ###

import numpy as np
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
f=np.zeros(9000001,int)
#f[0]=1
#f[a[0]]=1
ans=0
for ai in a:
  ff=np.zeros(9000001,int)
  ff+=f
  ff[ai:]+=f[:-ai]
  ff[0]+=1
  ff[ai]+=1
  f=ff
  f%=mod
  ans+=f[s]
  ans%=mod
print(ans)



### FIXED CODE ###

import numpy as np
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
f=np.zeros(3001,int)

ans=0
for ai in a:
  ff=np.zeros(3001,int)
  ff+=f
  ff[ai:]+=f[:-ai]
  ff[0]+=1
  ff[ai]+=1
  f=ff
  f%=mod
  ans+=f[s]
  ans%=mod
print(ans)
### BUGGY CODE ###


def main():
    N, M = map(int, input().split())
    lr = [list(map(int, list(input().split()))) for i in range(M)]
    # lr = []
    # for i in range(M):
    #     lr.append(list(map(int, list(input()))))
    # N, M = 4, 2
    # lr = [[1, 3], [2, 4]]

    count = 0

    for i in range(N):
        f = True
        for line in lr:
            f = f and line[0] <= i+1 <= line[1]
        if f:
            count += 1
    print(count)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    lr = [list(map(int, list(input().split()))) for i in range(M)]
    # N, M = 4, 2
    # lr = [[1, 1], [3, 4]]
    ll = []
    rl = []
    for line in lr:
        ll.append(line[0])
        rl.append(line[1])
    diff = min(rl) - max(ll)
    if diff < 0:
        print(0)
        return
    print(diff + 1)


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

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

for i in range(N):
  ans = ans * A[i]

if ans > 10**18:
  ans = -1
  
print(ans)


### FIXED CODE ###

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

for i in range(N):
  ans = ans * A[i]
  if abs(ans) > 10**18:
    ans = -1
    break
c = 1
for i in range(N):
  if A[i] == 0:
    c = 0
    break
print(ans*c)
### BUGGY CODE ###

N=int(input())
A=[int(x) for x in input().split()]
A_s=list(dict.fromkeys(A))
Com=0
for k in A_s:
    x=A.count(k)
    Com+=int(x*(x-1)/2)
    
for i in range(N):
    y=A.count(A[i])
    print(Com-y+1)

### FIXED CODE ###

from collections import Counter

N=int(input())
A=[int(x) for x in input().split()]
Com=0

A_C=Counter(A)

for name,x in A_C.items():
    Com+=int(x*(x-1)/2)
    
for i in range(N):
    y=A_C[A[i]]
    print(Com-y+1)
### BUGGY CODE ###

s=list(input())
n1=len(s)

import sys
sys.setrecursionlimit(10**9)

def a(s,n1):
    for i in range(1,len(s)):
        if s[i-1]=="0" and s[i]=="1" or s[i-1]=="1" and s[i]=="0":
            s[i-1]=s[i]="a"
    s=list("".join(s).replace("a",""))
    
    if len(set(s))==1 or s==[]:
        print(n1-len(s))
    else:
        a(s,n1)
a(s,n1)    


### FIXED CODE ###

s=list(input())
c0=0
c1=0
for i in range(len(s)):
    if s[i]=="0":c0+=1
    else: c1+=1
print(2*min(c0,c1))
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

for i in A:
    t = 0
    for k in a.keys():
        c = a[k]
        if k == i:
            c -= 1
        t += (c * (c-1)) // 2
    print(t)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

T = 0
for k in a.keys():
    c = a[k]
    T += (c * (c-1)) // 2

for i in A:
    t = 0
    c = a[i]
    t = T
    t -= (c * (c-1)) // 2
    c -= 1
    t += (c * (c-1)) // 2
    print(t)
### BUGGY CODE ###

import itertools
N = int(input())
l = []
num = int(N**0.5)+1

# for x in range(1,num+1):
#     for y in range(1,num+1):
#         for z in range(1,num+1):

for x,y,z in itertools.product(range(1, num+1), repeat=3):
    fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
    l.append(fn)

for i in range(1,N+1):
    print(l.count(i)) 


### FIXED CODE ###

import itertools
N = int(input())
num = int(N**0.5)+1

ans = [0]*(N+1)

# for x in range(1,num+1):
#     for y in range(1,num+1):
#         for z in range(1,num+1):

for x,y,z in itertools.product(range(1, num+1), repeat=3):
    fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if fn > N:
        continue
    else:
        ans[fn] += 1

for i in range(1,len(ans)):
    print(ans[i])
### BUGGY CODE ###

h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=9**9]*h*w
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if d[t]==I:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)

### FIXED CODE ###

I=9**9
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I]*h*w
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if d[t]==I:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)
### BUGGY CODE ###

import collections
n = int(input())
s=[input() for i in range(n)]

c = collections.Counter(s)

ans = list()

if n == 1:
    print(s[0])
elif n >= 2 and len(c.keys()) == 1:
    print(c.most_common()[0][0])
else:
    for i in range(n):
        if c.most_common()[0][1] == c.most_common()[i][1]:
            ans.append(c.most_common()[i][0])
        else:
            break

ans = sorted(ans)
[print(i) for i in ans]

### FIXED CODE ###

import collections
n = int(input())
s=[input() for i in range(n)]
ans = list()

c = collections.Counter(s)

m = max(c.values())
for k,v in c.items():
    if v ==m:
        ans.append(k)
ans.sort()
print(*ans,sep="\n")
### BUGGY CODE ###

n, k  = list(map(int, input().split()))
h = list(map(int, input().split()))
c = [0]*n

for i in range(1, n):
  c[i] = min(abs(h[i] - h[i - j]) + c[i - j] for j in range(1, min(i, k)+1))
  
print(c[-1])


### FIXED CODE ###

n, k  = list(map(int, input().split()))
h = list(map(int, input().split()))

c = [0]
for i in range(1, n):
  tmp = 10**100
  for j in range(1, min(i, k)+1):
    tmp = min(abs(h[i] - h[i - j]) + c[i - j], tmp)
  c.append(tmp)
  
print(c[-1])
### BUGGY CODE ###

import numpy as np
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
s = np.array([N, 0, 0, 0, 0])
m = np.array([A, B, C, D, E])
T = 0
while True:
    t = np.minimum(s, m)
    s -= t
    s[1:] += t[:-1]
    T += 1
    if np.max(s) == 0:
        break
print(T)

### FIXED CODE ###

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
s = min(A, B, C, D, E)
if N % s == 0:
    print(N // s + 4)
else:
    print(N // s + 5)
### BUGGY CODE ###

INF = 1010101010

def main():
    N,Ma,Mb = map(int,input().split())

    a = [0 for _ in range(N)]
    b = [0 for _ in range(N)]
    c = [0 for _ in range(N)]

    for i in range(N):
        a[i],b[i],c[i] = map(int,input().split())

    dp = [[[INF for k in range(401)] for j in range(401)] for i in range(41)]
    dp[0][0][0] = 0

    for i in range(N):
        for A in range(401):
            for B in range(401):
                dp[i+1][A][B] = min(dp[i+1][A][B], dp[i][A][B])
                if A+a[i]<=400 and B+b[i]<=400:
                    dp[i+1][A+a[i]][B+b[i]] = min(dp[i+1][A+a[i]][B+b[i]], dp[i][A][B]+c[i])

    ans = INF
    for A in range(1,401):
        for B in range(1,401):
            if Ma*B == Mb*A:
                ans = min(ans, dp[N][A][B])

    return -1 if ans == INF else ans

if __name__ == '__main__':
    print(main())


### FIXED CODE ###

INF = 1010101010

def main():
    N,Ma,Mb = map(int,input().split())

    a = [0 for _ in range(N)]
    b = [0 for _ in range(N)]
    c = [0 for _ in range(N)]

    for i in range(N):
        a[i],b[i],c[i] = map(int,input().split())

    dp = [[[INF for k in range(401)] for j in range(401)] for i in range(41)]
    dp[0][0][0] = 0

    for i in range(N):
        for A in range(401):
            for B in range(401):
                dp[i+1][A][B] = min(dp[i+1][A][B], dp[i][A][B])
                if A+a[i]<=400 and B+b[i]<=400:
                    dp[i+1][A+a[i]][B+b[i]] = min(dp[i+1][A+a[i]][B+b[i]], dp[i][A][B]+c[i])

    ans = INF
    for A in range(1,401):
        for B in range(1,401):
            if Ma*B == Mb*A:
                ans = min(ans, dp[N][A][B])

    return -1 if ans == INF else ans

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

N,K = map(int,input().split())
note = [[] for i in range(N)]
for i in range(N):
    t,d = map(int,input().split())
    t -= 1
    note[t].append(d)
head = []
remain = []
for e in note:
    if e == []:
        continue
    e.sort()
    e.reverse()
    head.append(e[0])
    if len(e) != 1:
        remain += e[1:]

head.sort()
head.reverse()
remain.sort()
remain.reverse()

ans = -float("inf")
for i in range(1,min(K,len(head))+1):
    if K - i > len(remain):
        continue
    deli = sum(head[:i]) + sum(remain[:K-i])
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
note = [list(map(int,input().split())) for i in range(N)]
note = sorted(note,key=lambda x:(x[0],-x[1]))
cnt = 0
head = []
remain = []
for i in range(N):
    if note[i][0] > cnt:
        cnt = note[i][0]
        head.append(note[i][1])
    else:
        remain.append(note[i][1])
head = sorted(head,reverse = True)
remain = sorted(remain,reverse = True)
ans = 0
acc_head = [0]
acc_remain = [0]
tmp_head = 0
tmp_remain = 0
for i in range(len(head)):
    tmp_head += head[i]
    acc_head.append(tmp_head)
for i in range(len(remain)):
    tmp_remain += remain[i]
    acc_remain.append(tmp_remain)
for i in range(max(0,K-len(remain)),min(K,len(head))+1):
    deli = acc_head[i] + acc_remain[K-i]
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))

a = [0]*n

for i in range(1, n):
  b = a[max(0, i-k)] + abs(h[i]-h[max(0, i-k)])
  for j in range(max(0, i-k), i):
    b = min(b, a[j] + abs(h[i]-h[j]))
  a[i] = b
print(a[-1])

### FIXED CODE ###

n, k = map(int, input().split())
hs = list(map(int, input().split()))
 
dp = [0]*n
 
for i in range(1, n):
  first = max(0, i-k)
  dp[i] = min([d + abs(hs[i]-h) for d, h in zip(dp[first:i], hs[first:i])])
print(dp[-1])
### BUGGY CODE ###

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

c=collections.Counter(b)
n,m=zip(*c.most_common())
n,m=list(n),list(m)

for i in range(1,a+1):
    if i in n:
        print(c[i])
    else:
        print(0)

### FIXED CODE ###

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

c=collections.Counter(b)
n,m=zip(*c.most_common())
n,m=list(n),list(m)
o=c.most_common()

result=[0]*a
for i in range(len(o)):
    result[o[i][0]-1]=o[i][1]

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

# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b

n = INT()
s = INT()

if n < s:
    print(-1)
elif n == s:
    print(n+1)
else:
    for i in range(2, n+1):
        if f(i, n) == s:
            print(i)
            exit()
    print(-1)


### FIXED CODE ###

# -*- coding: utf-8 -*-

"""
・参考：http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
　　　　https://www.youtube.com/watch?v=LzxPxJ-cSHk
・b <= √nは愚直に当たっていく。
・b > √nは、b^2 > nなので、b進数で2桁以下になる。
　例) 10^2は10進数で100、100 > n → nは99以下
　その2桁の数字はn = p*b + qと表せる。
　例) 67 = 6*10 + 7
　今回の問題の条件から、s = p + q
　n = p*b + q
　s = p + q
　上記2つの式から、連立方程式でqを消すと、
　n-s = p*b - p
　と表せる。
　pはb以上なら桁が上がってしまうので p < b
　p < b から p*p < p*b なので、p*b > p^2
　よって、n = p*b + q >= p*b > p^2
　n > p^2 なので、√n > p
　つまりpについて√nまでを全探索すればOK。
　n-s = p*b - p をbについての形に変形すればbが出せる。
　b = (n-s)/p + 1
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b

n = INT()
s = INT()

if s > n:
    print(-1)
elif s == n:
    print(n+1)
elif ceil(n/2) < s < n:
    print(-1)
else:
    # b <= √n の全探索
    for b in range(2, int(sqrt(n))+2):
        if f(b, n) == s:
            print(b)
            exit()
    # b > √n について、式を元に探す
    # pが大きい程bが小さいので、このループは逆順で回す
    for p in range(int(sqrt(n))+2, 0, -1):
        # 整数にならないものは除外
        if (n-s)%p: continue
        b = (n-s)//p + 1
        if f(b, n) == s:
            print(b)
            exit()
    # 見つからなかった
    print(-1)
### BUGGY CODE ###

import numpy as np

def get_expect(p):
    return 1.0 * (p + 1) / 2

def main():
    N, K = map(int, input().split(" "))
    P = np.array(list(map(int, input().split(" "))))

    e = np.frompyfunc(get_expect, 1, 1)(P)

    print(max([
        np.sum(
            e[i:i + K]
        )
        for i in range(N - K + 1)
    ]))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
from scipy import signal

def main():
    N, K = map(int, input().split(" "))
    P = np.array(list(map(int, input().split(" "))))

    e = (P + 1) / 2

    t = np.ones((K))

    print(np.amax(
        signal.fftconvolve(
            e,
            t
        )
    ))

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

S=list(map(int,input()))
num=0
ans=0
for i in range(len(S)-3):
    num=S[i]*1000+S[i+1]*100+S[i+2]*10+S[i+3]
    if num%2019==0:
        ans=ans+1
    for j in range(i+4,len(S)):
        num=num*10+S[j]
        if num%2019==0:
            ans=ans+1
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
S=list(map(int,input()))
N=len(S)
P=2019
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + S[i] * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

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

num = int(input())

strs = [[] for i in range(num)]
for i in range(num):
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
new_strs.sort()
shorten_strs = list(set(new_strs))

cnt = 0

import math
def comb_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for str in shorten_strs:
    nums = new_strs.count(str)
    if nums >= 2:
        cnt += comb_count(nums, 2)

print(cnt)


### FIXED CODE ###

from collections import Counter

num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def sort(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: sort(v), strs))
strs_length = len(new_strs)

sum = 0
counter = Counter()
for tmp_str in new_strs:
    sum += counter[tmp_str]
    counter[tmp_str] += 1

print(sum)
### BUGGY CODE ###

import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    if len(l):
        while True:
            a = l.find('0')
            if a<0:
                break
            bc = l.rfind('1')
            if a < bc:
                l = l[a+1:bc]
                count += (bc-a)
            else:
                break
 
print(str(count))

### FIXED CODE ###

import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    a = sum([i for i,x in enumerate(l) if '1' in x])
    su=sum([x for x in range(l.count('1'))])
    count += (a-su)
print(str(count))
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
res=[]
for i in range(n):
    if i+k>n:break
    tmp=sum(p[i:i+k])
    ans=max(ans, tmp)
    if ans==tmp:
        res=p[i:i+k]
ans=0
for j in res:
    ans+=sum(range(1,j+1))/j
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
p=[(i+1)/2 for i in map(float,input().split())]
MAX=sum(p[0:k])
s=[MAX]*n
for i in range(0,n-k):
    s[i+1]=p[i+k]+s[i]-p[i]
    MAX=max(MAX,s[i+1])
print(MAX)
### BUGGY CODE ###

from collections import deque

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

tmp = [0 for _ in range(N + 1)]

if 1 not in A:
    tmp[1] = 1
    
if 2 not in A and N >= 2:
    tmp[2] = tmp[1] + 1

for i in range(3, N+1):
    
    if i not in A:
        tmp[i] = tmp[i-1] + tmp[i-2] 
        

    
print(tmp[-1]%(10**9+7))




### FIXED CODE ###

from collections import deque

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

tmp = [0 for _ in range(N + 1)]

now = 0
if 1 not in A:
    tmp[1] = 1
    
else:
    now += 1
    
if (2 not in A) and N >= 2:
    tmp[2] = tmp[1] + 1
    
else:
    now += 1

for i in range(3, N+1):
    
    try:
        if i != A[now]:
            tmp[i] = tmp[i-1] + tmp[i-2] 
            
        else:
            now += 1
        
    except:
        tmp[i] = tmp[i-1] + tmp[i-2] 

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

import sys
from fractions import gcd
def main(a, b):
    #a, b = [int(i) for i in sys.stdin.readline().split()]
    _gcd = gcd(a,b)
    #memo_ls = [0 for i in range(_gcd)]
    #memo_set = set()
    cnt = 0
    if _gcd == 1:
        print(1)
    else:
        div = 2
        while _gcd > 1:
            if _gcd % div == 0:
                while _gcd % div == 0:
                    _gcd /= div
                cnt += 1
            div += 1
        #print(memo_set)
        print(cnt + 1)

if __name__ == "__main__":
    a, b = [int(i) for i in sys.stdin.readline().split()]
    main(a, b)

### FIXED CODE ###

import sys
from fractions import gcd
def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

def main(a, b):
    #a, b = [int(i) for i in sys.stdin.readline().split()]
    _gcd = gcd(a,b)
    #memo_ls = [0 for i in range(_gcd)]
    #memo_set = set()
    cnt = 0
    if _gcd == 1:
        print(1)
    else:
        res = prime_factorize(_gcd)
        print(len(res) + 1)
if __name__ == "__main__":
    a, b = [int(i) for i in sys.stdin.readline().split()]
    main(a, b)
### BUGGY CODE ###

import numpy as np
import itertools
 
k,s = map(int, input().split())
l = np.arange(k+1)
 
p = np.array(list(itertools.product(l,repeat=2)))
p = np.array(s - np.sum(p,axis=1))
p = np.array(p[p>=0])
print(np.count_nonzero(p<=k))

### FIXED CODE ###

k,s = map(int, input().split())
ans = 0

for x in range(k+1):
  for y in range(k+1):
    if 0<=s-x-y and s-x-y <=k:
      ans+=1
print(ans)