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

from queue import Queue

def bfs(HW, q, goal):
    num = 0
    mem = []
    while not q.empty():
        current = q.get()
        if current[0] >= H or current[0] < 0 or current[1] >= W or current[1] < 0:
            continue
        if HW[current[0]][current[1]] == '#':
            continue

        if (current[0] == goal[0]) and (current[1] == goal[1]):
            return current[2]

        if [current[0]+1,current[1]]  not in mem:
            mem.append([current[0]+1,current[1]])
            q.put([current[0]+1,current[1],current[2]+1])
        if [current[0],current[1]+1]  not in mem:
            mem.append([current[0],current[1]+1])
            q.put([current[0],current[1]+1,current[2]+1])
        if [current[0]-1,current[1]]  not in mem:
            mem.append([current[0]-1,current[1]])
            q.put([current[0]-1,current[1],current[2]+1])
        if [current[0],current[1]-1]  not in mem:
            mem.append([current[0],current[1]-1])
            q.put([current[0],current[1]-1,current[2]+1])
    return -1


H,W = map(int, input().split())

HW = [[''] * W for i in range(H)]
for i in range(H):
    h = str(input())
    for j in range(len(h)):
        HW[i][j] = h[j]

ans = 0
for si in range(H):
    for sj in range(W):
        if HW[si][sj] == '#':
            continue
        for gi in range(H):
            for gj in range(W):
                if HW[gi][gj] == '#':
                    continue
                q = Queue()
                q.put([si,sj,0])
                ans = max(ans, bfs(HW, q, [gi,gj]))
print(ans)

### FIXED CODE ###

from queue import Queue

def bfs(HW, q, x, y):
    num = 0
    mem = [[-1]*(W+1) for i in range(H+1)]
    max_dist = 0
    mem[x][y] = 0
    while not q.empty():
        current = q.get()
        if current[0] >= H or current[0] < 0 or current[1] >= W or current[1] < 0:
            continue
        if HW[current[0]][current[1]] == '#':
            continue
        dist = mem[current[0]][current[1]]
        max_dist = max(max_dist, dist)
        if mem[current[0]+1][current[1]] == -1:
            mem[current[0]+1][current[1]] = dist+1
            q.put([current[0]+1,current[1]])
        if mem[current[0]][current[1]+1] == -1:
            mem[current[0]][current[1]+1] = dist+1
            q.put([current[0],current[1]+1])
        if mem[current[0]-1][current[1]] == -1:
            mem[current[0]-1][current[1]] = dist+1
            q.put([current[0]-1,current[1]])
        if mem[current[0]][current[1]-1] == -1:
            mem[current[0]][current[1]-1] = dist+1
            q.put([current[0],current[1]-1])
    return max_dist


H,W = map(int, input().split())

HW = [[''] * W for i in range(H)]
for i in range(H):
    h = str(input())
    HW[i] = h

ans = 0
for si in range(H):
    for sj in range(W):
        if HW[si][sj] == '#':
            continue
        q = Queue()
        q.put([si,sj,0])
        ans = max(ans, bfs(HW, q, si, sj))
print(ans)
### BUGGY CODE ###

k=int(input())
ans=0
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      ans=ans+gcd(i,gcd(j,l))
print(ans)

### FIXED CODE ###

from math import gcd
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      ans=ans+gcd(gcd(i,j),l)
print(ans)
### BUGGY CODE ###

N = int(input())
para = [input() for i in range(N)]
def check(a,b):
    p = []
    q = []
    for i in range(10):
        if a[i] == b[i] :
            continue
        else :
            p.append(a[i])
            q.append(b[i])
    p.sort()
    q.sort()
    if p == q :
        return True 
            
a = 0 
for i in range(N):
    for j in range(i+1,N):
        if check(para[i],para[j]):
            a += 1
print(a)


### FIXED CODE ###

N = int(input())
para = [[c for c in input()] for i in range(N)]
b = []
dict = {}
ans = 0
for i in range(N):
    para[i].sort()
    b.append("".join(para[i]))
    if b[i] not in dict:
        dict[b[i]] = 1
    else :
        ans += dict[b[i]]
        dict[b[i]] += 1 

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

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

m = 0
for i in range(n - k + 1):
    tmp = P[i:i+k]
    if m < sum(tmp):
        m = sum(tmp)

print((m + k) / 2)

### FIXED CODE ###

import numpy as np
from scipy.signal import fftconvolve

n, k = map(int, input().split())
P = np.array(input().split(), dtype=int)
template = np.ones(k)

a = fftconvolve(P, template, mode="valid")

print((max(a) + k) / 2)
### BUGGY CODE ###

M=1000000007
N=int(input())
C=sorted(map(int,input().split()),reverse=True)
def pow(x,p):
  if(p==0):
    return 1;
  if(p%2):
    a=pow(x,p-1)%M;
    return x*a%M
  else:
    a=pow(x,p//2)%M
    return a*a%M
ans=0;
for k in range(N):
  ans=(ans+(C[k]*((pow(2,2*N-2)*k)%M+pow(2,2*N-1)))%M)%M
print(ans)

### FIXED CODE ###

M=1000000007
N=int(input())
C=sorted(map(int,input().split()),reverse=True)
def pow(x,p):
  if(p==0):
    return 1;
  if(p%2):
    a=pow(x,p-1)%M;
    return x*a%M
  else:
    a=pow(x,p//2)%M
    return a*a%M
ans=0;
p2=pow(2,2*N-2)%M
for k in range(N):
  ans=(ans+(C[k]*((p2*k)%M+2*p2))%M)%M
print(ans)
### BUGGY CODE ###

s=input()
k=int(input())
n=len(s)
ans=[]
for i in range(n):
    for j in range(n-i):
        ans.append(s[i:i+j+1])
print(sorted(list(set(ans)))[k-1])

### FIXED CODE ###

s=input()
k=int(input())
n=len(s)
koho=[]
for i in range(n):
    for j in range(k):
        if len(s[i:i+j+1])<=k:
            koho.append(s[i:i+j+1])

print(sorted(list(set(koho)))[k-1])
### BUGGY CODE ###

import sys
import numpy as np

input = sys.stdin.readline

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

X = [0 for _ in range(N)]



X = np.array(X)
A = np.array(A)
for i in range(N):
    B  = np.hstack((A[i:N+i], A[:i]))
    X = X + (-1)**i * B
 
print(*X)

### FIXED CODE ###

import sys

input = sys.stdin.readline

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

X = [0 for _ in range(N)]


for i in range(N):
    X[0] += (-1)**i * A[i]
for i in range(1, N):
    X[i] = -X[i-1] + 2*A[i-1]
 
 
print(*X)
### BUGGY CODE ###

N, K = input().split(" ")
N, K = int(N), int(K)
p_list = [int(i) for i in input().split(" ")]

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])+K
  else:
    tmp = sum(p_list[i:i+K])+K
    if max_sum < tmp:
      max_sum = tmp

print(max_sum/2)

### FIXED CODE ###

N, K = input().split(" ")
N, K = int(N), int(K)
p_list = [int(i) for i in input().split(" ")]

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])
    now_sum = max_sum
  else:
    now_sum += (p_list[i-1+K] - p_list[i-1])
    if max_sum < now_sum:
      max_sum = now_sum

print((max_sum + K)/2)
### BUGGY CODE ###

s = list(input())
n = len(s)
pos = 0
cnt = 0

while pos != n - 1 and n != 0:
    if s[pos] != s[pos + 1]:
        del s[pos]
        del s[pos]
        pos = 0
        n -= 2
        cnt += 2
    else:
        pos += 1

print(cnt)


### FIXED CODE ###

s = input()
a = s.count('0')
b = s.count('1')
print(min(a, b) * 2)
### BUGGY CODE ###

a,b,k = map(int,input().split())
for _ in range(k):
    if a > 0:
        a-=1
    elif b > 0:
        b-=1
    else:
        break
print("{} {}".format(a,b))

### FIXED CODE ###

a,b,k = map(int,input().split())

if k >= a:
    k = k-a
    a = 0
    if k >= b:
        b = 0
    else:
        b = b - k
else:
    a = a-k
print(a,b)
### BUGGY CODE ###

from collections import defaultdict
n=int(input())
dd = defaultdict(int)
A=[int(i) for i in input().split()]
for i in A:
    dd[i]+=1
ans = 0
for i in range(n):
    for j in dd:
        if A[i]==j:
            ans+=(((dd[j]-1)*(dd[j]-2))//2)
        else:
            ans+=(dd[j]*(dd[j]-1))//2
    print(ans)
    ans=0


### FIXED CODE ###

from collections import defaultdict
n=int(input())
dd = defaultdict(int)
A=[int(i) for i in input().split()]
for i in A:
    dd[i]+=1
memo = [0]*(n+1)
for i in dd:
    memo[i]=(dd[i]*(dd[i]-1))//2
ans = sum(memo)
done = [-1]*(n+1)
for i in range(n):
    if done[A[i]]==-1:
        done[A[i]]=(int(ans-memo[A[i]]+(memo[A[i]])*((dd[A[i]]-2)/dd[A[i]])))
        print(done[A[i]])

    else:
        print(done[A[i]])
### BUGGY CODE ###

N = int(input())
T = [ [] for _ in range(N) ]
ans = []
for i in range(N-1):
    a,b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)
    ans.append([a-1,b-1])


color = [ [0]*N for _ in range(N)]
total = 0
q = [0]

while(len(q) > 0):
    k = 0
    c = 1
    r = q[0]
    q.remove(r)
    m = min(T[r])
    if r > m:
        k = color[r][m]
        T[r].remove(m)
    for j in T[r]:
        if c != k:
            color[r][j] = c
            color[j][r] = c
        else:
            c += 1
            color[r][j] = c
            color[j][r] = c
        c += 1
        q.append(j)
    total = max(total,c-1)

print(total)
for pair in ans:
    print(color[pair[0]][pair[1]])

### FIXED CODE ###

from collections import deque

N = int(input())
T = [ [] for _ in range(N) ]
ans = []
for i in range(N-1):
    a,b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)
    ans.append((a-1,b-1))


used = [0]*N
used[0] = 1
a = dict()
parent = [0]*N
total = 0
q = deque()
q.append(0)

while(len(q) > 0):
    c = 1
    r = q.popleft()
    for j in T[r]:
        if used[j] == 0:
            used[j] = 1
            if c == parent[r]:
                c += 1
            a[(r,j)] = c
            parent[j] = c
            c += 1
            q.append(j)
    total = max(total,c-1)


print(total)
for pair in ans:
    print(a[pair])
### BUGGY CODE ###

n, m = map(int, input().split(' '))

WA_nums = dict()
AC = []
penalty = 0
for i in range(m):
    p, s = input().split()
    if p in AC:
        continue
    if s == 'AC':
        if p in WA_nums:
            penalty += WA_nums[p]
        AC.append(p)
    else:
        if p in WA_nums:
            WA_nums[p] += 1
        else:
            WA_nums[p] = 1

print(len(AC), penalty)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split(' '))

WAs = [0] * n
correct = 0
penalty = 0
for i in range(m):
    p, s = input().strip().split(' ')
    p = int(p) - 1
    if WAs[p] == -1:
        continue
    if s == 'AC':
        penalty += WAs[p]
        correct += 1
        WAs[p] = -1
    else:
        WAs[p] += 1

print(correct, penalty)
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC65 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heapify
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
par = [i for i in range(n)]
rank = [0]*n
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x,y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

x,y,c = [],[],[]
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    x.append((a,i))
    y.append((b,i))
    c.append((a,b))
x.sort()
y.sort()
h = []
heapify(h)
for i in range(n-1):
    x1, j1 = x[i]
    x2, j2 = x[i+1]
    y1, k1 = y[i]
    y2, k2 = y[i+1]
    heappush(h,(x2-x1, j1, j2))
    heappush(h,(y2-y1, k1, k2))
ans = 0
while h:
    w,s,t = heappop(h)
    if find(s) != find(t):
        union(s,t)
        ans += w
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC65 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heapify
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
par = [i for i in range(n)]
rank = [0]*n
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x,y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

x,y = [],[]
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    x.append((a,i))
    y.append((b,i))
x.sort()
y.sort()
h = []
heapify(h)
for i in range(n-1):
    x1, j1 = x[i]
    x2, j2 = x[i+1]
    y1, k1 = y[i]
    y2, k2 = y[i+1]
    heappush(h,(x2-x1, j1, j2))
    heappush(h,(y2-y1, k1, k2))
ans = 0
x = 0
while h:
    w,s,t = heappop(h)
    if find(s) != find(t):
        x += 1
        union(s,t)
        ans += w
    if x == n-1:
        break
print(ans)
### BUGGY CODE ###

import bisect
n = int(input())
a = [int(input()) for i in range(n)]
tmp = [a[0]]
for i in range(1,n):
  if a[i] <= min(tmp):
    tmp.append(a[i])
    tmp=sorted(tmp,reverse=True)
  else:
    index=bisect.bisect_left(tmp,a[i])
    tmp.insert(index,a[i])
    del tmp[index-1]
print(len(tmp))

### FIXED CODE ###

import bisect
n = int(input())
a = [- int(input()) for i in range(n)]
tmp = [a[0]]
for i in range(1,n):
  idx=bisect.bisect_right(tmp,a[i])
  if idx==len(tmp):
    tmp.append(a[i])
  else:
    tmp[idx] =a[i]
print(len(tmp))
### BUGGY CODE ###

class Quicksort:
    def quicksort(self, a, p, r):
        if p < r:
            q = self.partion(a, p, r)
            self.quicksort(a, p, q - 1)
            self.quicksort(a, q + 1, r)
        return(a)

    def partion(self, a, p, r): 
        x = a[r][1]
        i = p - 1
        for j in range(p, r):
            if a[j][1] <= x:
                i += 1
                a[i], a[j] = a[j], a[i]
        a[i + 1], a[r] = a[r], a[i + 1]
        return(i+1)

def bubbleSort(a, n):
    flag = 1
    while flag == 1:
        flag = 0
        for j in range(n-1, 0, -1):
            if a[j][1] < a[j - 1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
    return(a)

if __name__ == '__main__':
    n = int(input().rstrip())
    cards = []
    for i in range(n):
        tmp = input().rstrip().split(" ")
        tmp[1] = int(tmp[1])
        cards.append(tmp)
    a = cards[:]
    b = cards[:]
    
    x = Quicksort()
    a = x.quicksort(a, 0, n-1)
        
    b = bubbleSort(b, n)

    if a == b:
        print("Stable")
    else:
        print("Not stable")
    
    for i in a:
        i[1] = str(i[1])
        print(" ".join(i))

### FIXED CODE ###

class Quicksort:
    def quicksort(self, a, p, r):
        if p < r:
            q = self.partion(a, p, r)
            self.quicksort(a, p, q - 1)
            self.quicksort(a, q + 1, r)
        return(a)

    def partion(self, a, p, r): 
        x = a[r][1]
        i = p - 1
        for j in range(p, r):
            if a[j][1] <= x:
                i += 1
                a[i], a[j] = a[j], a[i]
        a[i + 1], a[r] = a[r], a[i + 1]
        return(i+1)

def bubbleSort(a, n):
    flag = 1
    while flag == 1:
        flag = 0
        for j in range(n-1, 0, -1):
            if a[j][1] < a[j - 1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
    return(a)

if __name__ == '__main__':
    n = int(input().rstrip())
    cards = []
    for i in range(n):
        tmp = input().rstrip().split(" ")
        tmp[1] = int(tmp[1])
        cards.append(tmp)
    a = cards[:]
    b = cards[:]
    x = Quicksort()
    a = x.quicksort(a, 0, n-1)
    b = sorted(b, key=lambda i: i[1])
    
    if a == b:
        print("Stable")
    else:
        print("Not stable")
    
    for i in a:
        i[1] = str(i[1])
        print(" ".join(i))
### BUGGY CODE ###

a, b = map(int, input().split())
for n in range(1, 1000):
    h1 = n*(n+1)//2
    h2 = (n+1)*(n+2)//2
    for x in range(1, h2+1):
        if h1 - x == a and h2 - x == b:
            print(x)
            exit(0)

### FIXED CODE ###

a, b = map(int, input().split())
for n in range(1, 1000):
    h1 = n*(n+1)//2
    h2 = (n+1)*(n+2)//2
    if h1 - a == h2 - b:
        print(h1-a)
        break
### BUGGY CODE ###

H, N = map(int, input().split())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for i in range(N):
  A[i], B[i] = map(int, input().split())

dplength = H+max(A)+1
INF = 100000000000
# dp[i] : 体力をi減らすための魔力の最小値
dp = [ INF for _ in range(dplength)]
dp[0] = 0
answer = INF
for i in range(dplength):
  for j in range(N):
    if A[j] <= i:
      dp[i] = min(dp[i], dp[i-A[j]] + B[j])
    else:
      dp[i] = min(dp[i], B[j])
  if H <= i:
    answer = min(answer, dp[i])

print(answer)

### FIXED CODE ###

H, N = map(int, input().split())
dp = [ 1001001001 for _ in range(H+1)]
dp[0] = 0
for i in range(N):
  A, B = map(int, input().split())
  for j in range(H):
    nj = min(j+A, H)
    dp[nj] = min(dp[nj], dp[j] + B)

print(dp[H])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
idx = 0
cnt = 0
for n in range(N):
    if A[idx] == idx+1:
        idx += 1
    else:
        A.pop(idx)
        cnt += 1
 
if cnt == N:
    print(-1)
else:
    print(cnt)

### FIXED CODE ###

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

i = 1
ans = 0
for n in range(N):
  if i == A[n]:
    i += 1
  else:
    ans += 1
if ans == N:
  ans = -1
  
print(ans)
### BUGGY CODE ###

from fractions import gcd
k = int(input())
ans = 0
for h in range(1,k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            ans += gcd(h, gcd(i, j))
print(ans)


### FIXED CODE ###

from math import gcd
k = int(input())
ans = 0
for h in range(1,k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            ans += gcd(h, gcd(i, j))
print(ans)
### BUGGY CODE ###

import math
from itertools import accumulate

def is_prime(n):
  if n == 1: return False
  for k in range(2, int(math.sqrt(n))+1):
    if n % k == 0: return False
  return True

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    A = [i for i in range(l, r+1, 2)]
    B = [(a+1)//2 for a in A]
    A_B = [0] +[1 for i in range(len(A)) if is_prime(A[i]) and is_prime(B[i])]
    print(max(accumulate(A_B)))

### FIXED CODE ###

import math
from itertools import accumulate

def is_prime(n):
  if n == 1: return False
  for k in range(2, int(math.sqrt(n))+1):
    if n % k == 0: return False
  return True

MAX = (10**5)+1
q = int(input())
A = [1 if is_prime(i)and is_prime((i + 1)//2) else 0 for i in range(MAX) ]
S = [0] + list(accumulate(A))

Q =[]
Q_append = Q.append
for _ in range(q):
    l, r = map(int, input().split())
    Q_append((l, r))

for qi in Q:  
    print(S[qi[1]+1]-S[qi[0]])
### BUGGY CODE ###

import math

input = str(input()).split(" ")
for index in range(len(input)):
    input[index] = int(input[index])
x = input[0]
y = input[1]


def test(x, y):
    for index in range(1, min(abs(y), math.floor((10**18)/x))):
        if (x * index % y != 0 and abs(x * index) <= 10**(18)):
            return x * index
    return -1
print(test(x,y))


### FIXED CODE ###

b=[]
b = input().strip().split()
b[0]=int(b[0])
b[1]=int(b[1])
if b[0]%b[1]==0:
	print("-1")
else:
	print(b[0])
### BUGGY CODE ###

#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_d

# input
n, k = [int(s) for s in input().split()]
S = input()
# get ans
node = [len(s) for s in S.split('0')]
node = [s for i, s in enumerate(node) if not (s==0 and i!=0 and i!=len(node)-1)]
arch = [len(s) for s in S.split('1')]
arch = list(filter(int, arch))
k = min(k, len(arch))
sls = [(i,i+k) for i in range(len(arch)-k+1)]
m = (sum(arch[i:j])+sum(node[i:j+1]) for i, j in sls)
ans = max(m)
# output
# print(node)
# print(arch)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_d

# input
n, k = [int(s) for s in input().split()]
S = input()
# get ans
node = [len(s) for s in S.split('0')]
node = [s for i, s in enumerate(node) if not (s==0 and i!=0 and i!=len(node)-1)]
arch = [len(s) for s in S.split('1')]
arch = list(filter(int, arch))
from itertools import chain
flatten = chain.from_iterable
xs = list(flatten(zip(node, arch))) + node[-1:]
l = len(xs)
sumlist = [None]*(l+2)
sumlist[-1] = 0
for i in range(l):
    sumlist[i] = sumlist[i-1] + xs[i]
def get_sum(f, n):
    f = min(f, l)
    t = f+n
    t = min(t, l)
    return sumlist[t-1] - sumlist[f-1]
def get_ans():
    for i in range(l//2+1):
        yield get_sum(i*2, k*2+1)
ans = max(get_ans())
# output
# print(node)
# print(arch)
# print(xs)
# print(sumlist)
# print(get_sum(0, 2))
# print(list(get_ans()))
print(ans)
### BUGGY CODE ###

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

count = 0
memo = []

for i in range(N):
  if A[i] not in memo:
    count += 1
    memo.append(A[i])
if N == count:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))

count = Counter(A)
memo = []

for v in count.values():
  if v >= 2:
    print("NO")
    exit()
else:
  print("YES")
### BUGGY CODE ###

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

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                ans += 1
            if x + y + z > s:
                break

print(ans)


### 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 <= k:
            ans += 1

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

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  a_max = max(a)
for j in range(n):
  if a[j] != a_max:
    print(a_max)
  else:
    a.sort()
    a.reverse()
    print(a[1])

### FIXED CODE ###

n = int(input())
a = [0 for n in range(n)]
for i in range(n):
  a[i] = int(input())
a_max = max(a)
b = sorted(a)
a_second = b[n-2]
for j in range(n):
  if a[j] != a_max:
    print(a_max)
  else:
    print(a_second)
### BUGGY CODE ###

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

X = [i for i in range(N+1)]
Y = [i for i in range(N+1)]
Z = [i for i in range(N+1)]

count = 0
for x in X:
	for y in Y:
		for z in Z:
			if x+y+z == M :
				#print(x,y,z)
				count += 1
print(count)

### FIXED CODE ###

import itertools

N,M = map(int,input().split())
X = [i for i in range(N+1)]

count = 0
for x,y in itertools.product(X,X):
	if 0 <= M - x - y <= N:
		count += 1

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

l = raw_input().split()
N = int(l[0])
K = int(l[1])
Q = int(l[2])


A = []
for i in range(Q):
    A.append(input())

for i in range(N):
    if Q-A.count(i+1) < K:
        print "Yes"
    else:
        print "No"



### FIXED CODE ###

N, K, Q = map(int, raw_input().split())

S = [0 for i in range(N)]

for i in range(Q):
    Ai = int(raw_input()) -1
    S[Ai] = S[Ai] + 1

for i in range(N):
    S[i] = K - (Q - S[i])


#print S                                                                                               
for i in range(N):
    if S[i] > 0:
        print "Yes"
    else:
        print "No"
### BUGGY CODE ###

import math

from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

result = 0
for i in range(1, K + 1):
    for p in range(1, K + 1):
        for q in range(1, K + 1):
            result += gcd(i, p, q)
            
print(result)

### FIXED CODE ###

import math

from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

result = 0
for i in range(1, K + 1):
    for p in range(1, K + 1):
        for q in range(1, K + 1):
            result += gcd(i, p, q)
            
print(result)
### BUGGY CODE ###

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

for i in range(N, M+1):
    if M%i==0:
        print(M//i)
        break

### FIXED CODE ###

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

import math

divisor=[]
for i in range(1, math.ceil(math.sqrt(M))+1):
    if M%i==0:
        divisor.append(i)
#print(divisor)

divisor+=[M//val for val in reversed(divisor)]
#print(divisor)
for val in divisor:
    if val>=N:
        print(M//val)
        break