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

from collections import deque
n,x,y = map(int,input().split())
cnt = [0]*(n)
path = [(i, i+1) for i in range(n-1)]
path.append((x-1, y-1))
res = []
for i in range(n):
    d = [float('inf')]*n
    que = deque([(i, 0)])
    while que:
        idx, c = que.popleft()
        if d[idx]!=float('inf'):
            continue
        else:
            d[idx] = min(d[idx], c)
            for s,g in path:
                if s==idx:
                    que.append((g, c+1))
                if g==idx:
                    que.append((s, c+1))
    res.append(d)

for r in res:
    for i in range(n-1):
        cnt[i] += r.count(i)
for c in cnt[1:]:
    print(c//2)


### FIXED CODE ###

from collections import deque
n,x,y = map(int,input().split())
x,y = x-1 ,y-1
g = [[float('inf')]*n for _ in range(n)]
for i in range(n):
    que = deque([(i, 0)])
    while que:
        node, cost = que.popleft()
        if g[i][node]!=float('inf'):
            continue
        else:
            g[i][node] = cost
            if node>0:
                que.append((node-1, cost+1))
            if node<n-1:
                que.append((node+1, cost+1))
            if node==x:
                que.append((y, cost+1))
            if node==y:
                que.append((x, cost+1))
cnt = [0]*n
for i in range(n):
    for j in range(i+1, n):
        cnt[g[i][j]] += 1
for c in cnt[1:]:
    print(c)
### BUGGY CODE ###

N_ = int(input())

A_ = input().split()
#print(A_)

U_ = set(A_)
#print(U_)


def xC(num):
    return (num * (num - 1)) //2

num = 0
dict = {}
judge = {}

for u in U_:
    num += xC(A_.count(u))

for u in U_:
    dict[u] = num - xC(A_.count(u)) + xC(A_.count(u) - 1)


for a in A_:
    print(dict[a])

### FIXED CODE ###

N_ = int(input())

A_ = input().split()
#print(A_)

#U_ = set(A_)
#print(U_)


#def xC(num):
#    return (num * (num - 1)) //2
import collections
cnt = collections.Counter(A_)

num = 0
dict = {}
#judge = {}
#for u in U_:
#    judge[u] = False
#    num += xC(A_.count(u))
for v in cnt.values():
    num += v*(v - 1)//2
Re = []
for value in A_:
    Re.append(str(num - (cnt[value] - 1)))
print('\n'.join(Re))
### BUGGY CODE ###

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

import math

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.7)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

for i in range(k):
    print(cnum[i])


### FIXED CODE ###

# -*- coding: utf-8 -*-
x,y,z,k = map(int,input().split())
a,b,c = [],[],[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []

for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])

ab.sort()

abc = []

for i in range(min(len(ab),k)):
    for j in range(min(z,k)):
        abc.append(ab[-(i+1)] + c[j])

abc.sort()

for i in range(k):
    print(abc[-(i+1)])
### BUGGY CODE ###

n=int(input())
k=1
for i in range(1,n+1):
    k*=i
print( k%((10**9)+7) )

### FIXED CODE ###

n=int(input())
k=1
for i in range(1,n+1):
    k=(k*i)%((10**9)+7)
print(k)
### BUGGY CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit, maxsize


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(-maxsize, 0)] * (n//1000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v

        b = a - a % 1000
        index = value = -maxsize
        for i, v in enumerate(base[b:b+1000], b+1):
            if value < v:
                value = v
                index = i
        midway[b//1000] = (value, -index)

        value, index = max(midway)
        print(-index, value)
    exit()


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//100 + 1)
    last = [0] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 100

        index = b
        value = base[b]
        end = b + 100 if b + 100 < n else n
        for i in range(b, end):
            if value < base[i]:
                value = base[i]
                index = i
        midway[b//100] = index

        c = a - a % 10000
        cc = c // 100

        index = c
        value = base[c]
        for i in midway[cc:cc+100]:
            if value < base[i]:
                value = base[i]
                index = i
        last[c//10000] = index

        index = last[0]
        value = base[index]
        for i in last:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


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

def slove(n, k):
    a_list = sorted([(int(x),i) for i,x in enumerate(k.split())], reverse=True)
    dp = [[0]*(n+1) for i in range(n+1)]
    for i in range(n):
        for j in range(n-i):
            dp[i+1][j] = max(dp[i+1][j],
                         dp[i][j]+a_list[i+j][0]*abs(a_list[i+j][1]-i))
            dp[i][j+1] = max(dp[i][j+1],
                         dp[i][j]+a_list[i+j][0]*abs((n-1-j)-a_list[i+j][1]))

    return max([max(i) for i in dp])

if __name__ == "__main__":
    n = int(input())
    k = input()
    print(slove(n, k))

### FIXED CODE ###

def slove(n, a_list):

    dp = [[0]*(n+1) for i in range(n+1)]
    for i in range(n):
        for j in range(n-i):
            dp[i+1][j] = max(dp[i+1][j],
                         dp[i][j]+a_list[i+j][0]*abs(a_list[i+j][1]-i))
            dp[i][j+1] = max(dp[i][j+1],
                         dp[i][j]+a_list[i+j][0]*abs((n-1-j)-a_list[i+j][1]))

    return max([max(i) for i in dp])

if __name__ == "__main__":
    n = int(input())
    k = sorted([(int(x),i) for i,x in enumerate(input().split())], reverse=True)
    print(slove(n, k))
### BUGGY CODE ###

N=int(input())
S=input()
def condition(num):
    if num==0:
        return True
    else:
        flag=0
        data=[]
        for i in range(0,N-num+1):
            data.append(S[i:i+num])
        for i in range(0,len(data)-1):
            for j in range(i+num,N-num+1):
                if data[i]==data[j]:
                    flag=1
        return flag==1

start=0
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test
if condition(end):
    print(end)
else:
    print(start)


### FIXED CODE ###

from itertools import groupby

N=int(input())
S=input()
def condition(num):
    if num==0:
        return True
    else:
        flag=0
        data=[]
        for i in range(0,N-num+1):
            data.append([S[i:i+num],i])
        data.sort()
        partdata=[data[i][0] for i in range(0,len(data))]
        partdata=groupby(partdata)
        subdata=[]
        for key,group in partdata:
            g=len(list(group))
            subdata.append(g)
        s=0
        t=subdata[0]-1
        if len(subdata)==1:
            if data[t][1]-data[s][1]>=num:
                flag=1
        for i in range(0,len(subdata)-1):
            if data[t][1]-data[s][1]>=num:
                flag=1
            s=t+1
            t=t+subdata[i+1]
        if data[t][1]-data[s][1]>=num:
            flag=1
        return flag==1

start=0
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test
if condition(end):
    print(end)
else:
    print(start)
### BUGGY CODE ###

n = int(input())
a = {}
for i in range(n):
    s = int(input())
    if s in a.keys():
        flag = False
    else:
        flag = True
    if flag:
        a[s] = 1
    else:
        if a[s] == 1:
            a[s] = 0
        else:
            a[s] = 1
print(sum(a.values()))


### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 1
    if j >= n:
        cnt += 1 
        break
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)
### BUGGY CODE ###

import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        if len(self.hq) == 0:
            return None
        if self.desc:
            return heapq.heappop(self.hq).val
        else:
            return heapq.heappop(self.hq)

    def push(self, a):
        if self.desc:
            heapq.heappush(self.hq, Reverse(a))
        else:
            heapq.heappush(self.hq, a)

    def top(self):
        if self.desc:
            return self.hq[0].val
        else:
            return self.hq[0]

    def __len__(self):
        return len(self.hq)


n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))

ans = 0
h = Heapq([], desc=True)
for i in range(1, m+1):
    for j in filter(lambda x: x[0] == i, ab):
        h.push(j[1])
    ab = list(filter(lambda x: x[0] != i, ab))
    if len(h) == 0:
        continue
    ans += h.pop()
print(ans)


### FIXED CODE ###

import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        if len(self.hq) == 0:
            return None
        if self.desc:
            return heapq.heappop(self.hq).val
        else:
            return heapq.heappop(self.hq)

    def push(self, a):
        if self.desc:
            heapq.heappush(self.hq, Reverse(a))
        else:
            heapq.heappush(self.hq, a)

    def top(self):
        if self.desc:
            return self.hq[0].val
        else:
            return self.hq[0]

    def __len__(self):
        return len(self.hq)


n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    a, b = map(int, input().split(' '))
    if a > m:
        continue
    ab.append((a, b))
ab.sort(reverse=True)

ans = 0
h = Heapq([], desc=True)
for i in range(1, m+1):
    while ab and ab[-1][0] <= i:
        a, b = ab.pop()
        h.push(b)
    if h:
        ans += h.pop()
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m = map(int,input().split())
a = list(map(int,input().split()))
for k in range(m):
  s, t = map(int,input().split())
  b = [t]*s
  a.extend(b)
ans = 0
a.sort(reverse=True)
for v in range(n):
  ans += a[v]
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))
### BUGGY CODE ###

import sys
from collections import deque
INFTY = 1<<30
a = [None] * 2000001
h = 0
ret = deque([]) 

def maxHeapify(i):
    global a, h
    l = 2 * i
    r = 2 * i + 1
    if l <= h and a[l] > a[i]:
        largest = l
    else:
        largest = i
    if r <= h and a[r] > a[largest]:
        largest = r
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        maxHeapify(largest)

def extract():
    global a, h
    if h < 1:
        return -INFTY
    maxv = a[1]
    a[1] = a[h]
    h -= 1
    maxHeapify(1)
    return maxv
    
def increaseKey(i, k):
    global a
    if k < a[i]:
        return
    a[i] = k
    while i > 1 and a[i//2] < a[i]:
        a[i], a[i//2] = a[i//2], a[i]
        i = i // 2

def insert(k):
    global a, h
    h += 1
    a[h] = -INFTY
    increaseKey(h, k)

for com in sys.stdin.readlines():
    if com[0] == "i":
        insert(int(com[7:]))
    elif com[1] == "x":
        ret.append(extract()) 
    else:
        print("\n".join([str(s) for s in list(ret)]))

### FIXED CODE ###

import heapq
import sys

h = []

for com in sys.stdin.readlines():
    if com[0] == "i":
        heapq.heappush(h, -int(com[7:]))
    elif com[1] == "x":
        print(-heapq.heappop(h))
### BUGGY CODE ###

n = int(input())
s = input()

numpeople = 3 * 10 ** 5 + 1
for leader in range(n):
  left = len([x for x in s[:leader] if x == 'W'])
  right = len([x for x in s[leader+1:] if x == 'E'])
  numpeople = min(numpeople, left + right)

print(numpeople)

### FIXED CODE ###

n = int(input())
s = input()

turn_east = [0 for x in range(n)]
turn_west = [0 for x in range(n)]
total = [0 for x in range(n)]

for i in range(n):
  if i > 0:
    if s[i-1] == 'W':
      turn_east[i] = turn_east[i-1]+1
    else:
      turn_east[i] = turn_east[i-1]

    if s[n-i] == 'E':
      turn_west[n-1-i] = turn_west[n-i]+1
    else:
      turn_west[n-1-i] = turn_west[n-i]

for j in range(n):
  total[j] = turn_east[j] + turn_west[j]

print(min(total))
### BUGGY CODE ###

n = int(input())
s = [input() for _ in range(n)]

ans = 0
a = 0
for b in range(n):
    flag = 0
    for i in range(n):
        if flag == 1:
            break
        for j in range(n):
            if s[(i+a)%n][(j+b)%n] != s[(j+a)%n][(i+b)%n]:
                flag = 1
                break
    else:
        ans += n

print(ans)

### FIXED CODE ###

n = int(input())
s = [input() for _ in range(n)]

ans = 0
a = 0
for b in range(n):
    flag = 0
    for i in range(n):
        if flag == 1:
            break
        for j in range(n):
            if s[(i+a)%n][(j+b)%n] != s[(j+a)%n][(i+b)%n]:
                flag = 1
                break
    else:
        ans += n

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

#Sum of Divisors
import numpy as np
N = int(input())

def divisor(X):
    W1 = np.full(X,X)
    W2 = np.arange(1,X+1)
    return X-np.count_nonzero(W1%W2)

ans = 0
for i in range(1,N+1):
    ans += i*divisor(i)
    # print(ans,divisor(i))

print(ans)

### FIXED CODE ###

#Sum of Divisors
import numpy as np
N = int(input())

ans = 0
for i in range(1,N+1):
    ans += (N//i)*((N//i)+1)*i/2

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

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

k = 1
s = 0
count = 0


for i in range(n):
    if k in a:
        s = a.index(k)
        a = a[s:]
        k += 1

if 1 in m:
    print(n-(k-1))
else:
    print(-1)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
 
j=1
for i in range(N):
    if j==A[i]:
        j+=1
 
if j==1:
  print(-1)
else:
  print(N-j+1)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
    ans*=i

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


### FIXED CODE ###

n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]*a[1]>10**18 and a[-1]!=0:
    print(-1)
    exit()
if a[-1]==0:
    print(0)
    exit()
    
ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

n = int(input())
a = []
c = []
for _ in range(n):
  s, t = map(int, input().split())
  a.append((s, t))
  c.append(s + t)

taka = 0
aoki = 0
for i in range(n):
  p = c.index(max(c))
  x = a.pop(p)
  c.pop(p)
  
  if i % 2 == 0:
    taka += x[0]
  else:
    aoki += x[1]

print(taka - aoki)

### FIXED CODE ###

n = int(input())
a = []
for _ in range(n):
  s, t = map(int, input().split())
  a.append([s+t, s, t])

a = sorted(a, key=lambda x: -x[0])
taka = 0
aoki = 0
for i in range(n):
  if i % 2 == 0:
    taka += a[i][1]
  else:
    aoki += a[i][2]

print(taka - aoki)
### BUGGY CODE ###

MOD = 998244353
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

S = list()
for lr in LR:
    for i in range(lr[0], lr[1]+1):
        S.append(i)

dp = [0]*(N+1) # dp[i] : iに行く方法
dp[1] = 1

memo = list()

for i in range(1, N+1):
    # for s in S:
    #     if i + s <= N:
    #         dp[i + s] += dp[i]
    #         dp[i + s] %= MOD
    for m in memo:
        # l = m[1]
        # r = m[2]
        if m[1] <= i and i <= m[2]:
            dp[i] += m[0]
            dp[i] %= MOD
    
    for lr in LR:
        memo.append([dp[i], lr[0] + i, lr[1] + i])
    
print(dp[N])

### FIXED CODE ###

MOD = 998244353
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

dp = [0]*(N+1)
acc = [0]*(N+1) # acc[i] = dp[1] + ... dp[i]

dp[1] = 1
acc[1] = 1
for i in range(2, N+1):
    for lr in LR:
        l = lr[0]
        r = lr[1]

        dp[i] += (acc[max(0, i - l)] - acc[max(0, i - r - 1)] + MOD)
        dp[i] %= MOD
    acc[i] = (acc[i-1] + dp[i]) % MOD
    
    

print(dp[N])
# print(acc)
# print(dp[N])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:43:20 2019

@author: fumito
"""

def create_sub(lr,S):
    sub = S[int(lr[0])-1:int(lr[1])]
    list = [i for i in sub]
    return list

def A_index(sub):
    A_index = [i for i,x in enumerate(sub) if x == 'A']
    return A_index

def count(sub,index):
    count = 0
    for i in index:
        if i == len(sub)-1:
            pass
        elif sub[i+1] == 'C':
            count += 1
        else:
            pass
    return count

if __name__ == "__main__":
    N,Q = map(int,input().split())
    S = str(input())
    lr = [input().split() for i in range(Q)]
    
    ans = []
    for i in range(Q):
        Sub = create_sub(lr[i],S)
        Index = A_index(Sub)
        Count = count(Sub,Index)
        ans.append(Count)
    for j in ans:
        print(j)

### FIXED CODE ###

N,Q = map(int,input().split())
S = str(input())
l,r = [0]*Q,[0]*Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())
    
count_list = []
count = 0
count_list.append(0)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        count += 1
        count_list.append(count)
    else:
        count_list.append(count)
    
for j in range(Q):
    print(count_list[r[j]-1]-count_list[l[j]-1])
### BUGGY CODE ###

N, M = map(int, input().split())
a,b = [],[]
for i in range(M):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)
for i in range(M):
    if b[i] == N:
        for j in range(M):
            if a[j] == 1 and b[j] == a[i]:
                print("POSSIBLE")
                exit(0)
print("IMPOSSIBLE")

### FIXED CODE ###

N, M = map(int, input().split())
cnt = [0]*N
for i in range(M):
    A, B = map(int, input().split())
    if A == 1:
        cnt[B] += 1
    elif B == N:
        cnt[A] += 1

if 2 in cnt:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

N=int(input())
A = list(map(int,input().split()))
mod = 10**9+7
Ans = 0
for i in range(60+1):
  Po=0
  Ne=0
  for j in A:
    if j>>i & 1:
      Po+=1
    else:
      Ne+=1
  Ans += Po*Ne*(2**i)
  Ans = Ans % mod
print(Ans)

### FIXED CODE ###

N=int(input())
A = list(map(int,input().split()))
mod = 10**9+7
Ans = 0
for i in range(60):
  Po=sum([1 for j in A if j>>i & 1])
  Ans += Po*(N-Po)*(2**i)
  Ans = Ans % mod
print(Ans)
### BUGGY CODE ###

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

key = len(A) % 2
ans = []
for i in range(N):
    if i % 2 == key:
        ans.append(A[i])
    else:
        ans. insert(0, A[i])

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


### FIXED CODE ###

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

key = len(A) % 2
ans = [0]*N
mid = (len(A)) // 2
for i in range(N):
    ans[mid + ((-1)**(i+key))*((i+1)//2)] = A[i]
for i in range(N):
    print(ans[i], end = " ")
print("")
### BUGGY CODE ###

X,K,D=map(int,input().split())

def valid(value1, value2, diff):
    if diff%2==0:
        return value1
    else:
        return value2

tmp = [X]
min_score = abs(X)
for i in range(K):
    if abs(X-D)>abs(X+D):
        X = X+D
    else:
        X = X-D
    if min_score > abs(X):
        min_score=abs(X)
    else:
        a = min([abs(X-D), abs(X+D)])
        min_score = valid(a, abs(X), K-i)
        break

    if X in tmp:
        a = min([abs(X-D), abs(X+D)])
        min_score = valid(a, min_score, K-i)
        break
    tmp.append(X)
print(min_score)


### FIXED CODE ###

X,K,D=map(int,input().split())

def valid(value1, value2, diff):
    if diff%2==0:
        return value1
    else:
        return value2

if abs(X)>K:
    tmp = abs(X)//D
    if tmp>K:
        tmp=K
    if X < 0:
        X += tmp*D
    else:
        X -= tmp*D
    K -= tmp

min_score = abs(X)
for i in range(K):
    if abs(X-D)>abs(X+D):
        X = X+D
    else:
        X = X-D
    if min_score > abs(X):
        min_score=abs(X)
    else:
        a = min([abs(X-D), abs(X+D)])
        min_score = valid(a, abs(X), K-i)
        break
print(min_score)
### BUGGY CODE ###

X, K, D = map(int, input().split())
if X == D:
    if K % 2 != 0:
        print('0')
    else:
        print(D)
else:
    for i in range(K):
        if X >= 0:
            X = X - D
        else:
            X = X + D
    print(abs(X))

### FIXED CODE ###

X, K, D = map(int, input().split())
X = abs(X)
if X == D:
    if K % 2 != 0:
        print('0')
    else:
        print(D)
else:
    span = X // D
    if span < K:
        if (K - span) % 2 == 0:
            print(X % D)
        else:
            print(abs(X % D - D))
    else:
        print(X - K * D)
### BUGGY CODE ###

k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i+j+l==s:
                ans+=1
print(ans)


### FIXED CODE ###

K,S=map(int,input().split())
if S<=K:
    print((S+2)*(S+1)//2)
elif S<=2*K:
    m=0
    for i in range(K+1):
        s=S-i
        if s<=K:
            m+=s+1
            
        else:
            c=s-K
            a=s-2*c
            m+=a+1         
    print(m)

else:
    s=3*K-S
    print((s+2)*(s+1)//2)
### BUGGY CODE ###

a = input().split()
a = [int(i) for i in a]
drink_nume = []
drink_price = []

for i in range(a[0]):
    b = input().split()
    b = [int(i) for i in b]
    drink_nume.append(b[1])
    drink_price.append(b[0])

count = 0

while (a[1] > 0):
    min_index = drink_price.index(min(drink_price))
    if drink_nume[min_index] > a[1]:
        count += drink_price[min_index] * a[1]
        a[1] = 0
    else:
        count += drink_price[min_index] * drink_nume[min_index]
        a[1] -= drink_nume[min_index]
    drink_nume.pop(min_index)
    drink_price.pop(min_index)

print(count)

### FIXED CODE ###

import sys
a = input().split()
a = [int(i) for i in a]
drink = []


for i in range(a[0]):
    b = input().split()
    b = [int(i) for i in b]
    drink.append(b)

count = 0
drink = sorted(drink, key=lambda x: x[0])

while (a[1] > 0):
    if drink[0][1] > a[1]:
        count += drink[0][0] * a[1]
        a[1] = 0
    else:
        count += drink[0][0] * drink[0][1]
        a[1] -= drink[0][1]
    drink.pop(0)

print(count)