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

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

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

### FIXED CODE ###

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

dp = [0] * n
for i in range(1, n):
  start = max(0, i - k)
  dp[i] = dp[start] + abs(h[start] - h[i])
  for j in range(start+1, i + 1):
    dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]))
  
print(dp[n-1])
### BUGGY CODE ###

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for j in range(1, k+1):
    if( i-j >= 0):
      dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]))

print(dp[-1])


### FIXED CODE ###

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for j in range(1, k+1):
    if(i-j < 0):
      break
    dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]))

print(dp[-1])
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                count += b - 1
            else:
                count += b
        else:
            count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                count += g - 1
            else:
                count += g
        else:
            count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                count += r - 1
            else:
                count += r
        else:
            count += r
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

### FIXED CODE ###

N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)
### BUGGY CODE ###

from heapq import heappush, heappop, merge
from collections import defaultdict, deque

N, Q = map(int, input().split())
events = []
for _ in range(N):
    s, t, x = map(int, input().split())
    events.append((s-x, 1, x))
    events.append((t-x, -1, x))
events = deque(sorted(events))
D = []
for _ in range(Q):
    D.append(int(input()))

constructions = []
under_construction = defaultdict(bool)
i = 0
for d in D:
    while events:
        if events[0][0] > d:
            break
        _, flag, coord = events.popleft()            
        if flag > 0:
            heappush(constructions, coord)
            under_construction[coord] = True
        else:
            under_construction[coord] = False
    while constructions:
        x = heappop(constructions)
        if under_construction[x]: # x is the minimum coordinate under construction
            heappush(constructions, x)
            print(x)
            break
    else: # no constructions
        print(-1)

### FIXED CODE ###

from heapq import heappush, heappop, merge
from collections import defaultdict
import sys
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    N, Q = map(int, line_input())
    events = []
    for _ in range(N):
        s, t, x = map(int, line_input())
        events.append((s-x, 1, x))
        events.append((t-x, -1, x))
    for _ in range(Q):
        d = int(single_input())
        events.append((d, 2, d))
    events = sorted(events)

    constructions = []
    under_construction = defaultdict(bool)
    ans = ''
    for _, flag, coord in events:
        if flag == 1:
            heappush(constructions, coord)
            under_construction[coord] = True
        elif flag == -1:
            under_construction[coord] = False
        else:
            while constructions:
                x = heappop(constructions)
                if under_construction[x]: # x is the minimum coordinate under construction
                    heappush(constructions, x)
                    ans += str(x) + '\n'
                    break
            else: # no constructions
                ans += '-1\n'
    print(ans)
    
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

"""
D - String Formation
"""
s = input()
q = int(input())
string = []
for i in range(q):
    string.append(input())
i = 0
while i < len(string):
    emir = string[i]
    if i+1 == len(string):
        if emir[0] == '1':
            s = s[::-1]
            i += 1
        elif emir[0] == '2':
            if emir[2] == '1':
                s = emir[4] + s
                i += 1
            elif emir[2] == '2':
                s += emir[4]
                i += 1
    else:
        sonraki = string[i+1]
        if emir[0] == sonraki[0] == '1':
            i = i + 2
        elif emir[0] == '1':
            s = s[::-1]
            i += 1
        elif emir[0] == '2':
            if emir[2] == '1':
                s = emir[4] + s
                i += 1
            elif emir[2] == '2':
                s += emir[4]
                i += 1
print(s)

### FIXED CODE ###

s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)
### BUGGY CODE ###


import heapq
dif = 10 ** 6
initial = 10 ** 15

def di(links, s):
    costs = [initial] * n
    costs[s] = 0
    node_list = []
    serched_node = set()
    heapq.heappush(node_list, s)
    while(node_list != []):
        index = heapq.heappop(node_list) % dif
        if index in serched_node:
            continue
        serched_node.add(index)
        link = links[index]
        for j in range(n):
            if j in serched_node or link[j] == -1:
                continue
        
            cost = link[j]
            newcost =  costs[index] + cost
            if newcost < costs[j]:
                costs[j] = newcost
                heapq.heappush(node_list, newcost * dif + j)
    return costs
    
n, m, s, t  = list(map(int, input().split()))
s -= 1
t -= 1
links_en = [[-1 for j in range(n)] for i in range(n)]
links_sn = [[-1 for j in range(n)] for i in range(n)]

for i in range(m):
    u, v, a, b  = list(map(int, input().split()))
    links_en[u - 1][v - 1] = a
    links_en[v - 1][u - 1] = a
    links_sn[v - 1][u - 1] = b
    links_sn[u - 1][v - 1] = b

cost_en_from_s = di(links_en, s)
cost_sn_to_t = di(links_sn, t)

trans = n - 1
costs = [0] * n
for i in range(n - 1, -1, -1):
    if i == n - 1:
        costs[n-1] = cost_en_from_s[n-1] + cost_sn_to_t[n-1]
        continue
    
    newcost = cost_en_from_s[i] + cost_sn_to_t[i]
    if newcost < costs[trans]:
        trans = i
        costs[i] = newcost
        continue
    
    costs[i] = costs[trans]
    
for cost in costs:
    print(initial - cost)

### FIXED CODE ###

import heapq
initial_cost = 10 ** 9
initial = 10 ** 15

def di(link_costs, s):
    costs = [initial] * n
    costs[s] = 0
    q = []
    heapq.heappush(q, (0, s))
    
    while(len(q) != 0):
        index_cost, index = heapq.heappop(q)
        if costs[index] < index_cost:
            continue

        for j in link_costs[index]:
            newcost = costs[index] + link_costs[index][j]
            if newcost < costs[j]:
                costs[j] = newcost
                heapq.heappush(q, (newcost, j))
    return costs
    
n, m, s, t  = list(map(int, input().split()))
s -= 1
t -= 1
links_cost_en = [{} for _ in range(n)]
links_cost_sn = [{} for _ in range(n)]

for _ in range(m):
    u, v, a, b  = list(map(int, input().split()))
    u -= 1
    v -= 1
    links_cost_en[u][v] = a
    links_cost_en[v][u] = a
    links_cost_sn[u][v] = b
    links_cost_sn[v][u] = b

cost_en_from_s = di(links_cost_en, s)
cost_sn_to_t = di(links_cost_sn, t)
cost_list = [cost_en_from_s[i] + cost_sn_to_t[i] for i in range(n)]

ans = [initial] * n
ans[-1] = cost_list[-1]
for i in list(range(n - 1))[::-1]:
    ans[i] = min(ans[i + 1], cost_list[i])
for i in range(n):
    print(initial - ans[i])
### BUGGY CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))

_x = x 
x_ = x
while True:
  if _x not in p:
    print(_x)
    break
    if x_ not in p:
      print(x_)
      break
      _x -= 1
      x_ += 1

### FIXED CODE ###

X, N = map(int, input().split())
p = list(map(int, input().split()))

p = set(p)
for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
### BUGGY CODE ###

import fractions

def div(n):
  l =[]
  for i in range(1,n+1):
    if n%i ==0:
      l.append(i)
  return l

A,B = list(map(int,input().split()))
maxy = fractions.gcd(A,B)
ly = div(maxy)
l = [1]

for i in ly[1:]:
  flg = 1
  for e in l:
    if fractions.gcd(i,e) > 1:
      flg = 0
  if i not in l and flg == 1:
    l.append(i)
print(len(l))


### FIXED CODE ###

import fractions

def div(n):
  l =[]
  for i in range(1,n+1):
    if n%i ==0:
      l.append(i)
  return l

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i not in table:
        table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

A,B = list(map(int,input().split()))
maxy = fractions.gcd(A,B)

l2 = prime_decomposition(maxy)
print(len(l2) + 1)
### BUGGY CODE ###

s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(1,len_s-i+1):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
            break
print(sum(list))
            

        

### FIXED CODE ###

s=list(input())
s.reverse()
s_len = len(s)

list = [0 for _ in range(2019)]
ans = 0
mod = 2019
li = [0]
digit = 0
for i in range(s_len):
    li.append((li[i] + int(s[i])*pow(10,digit,mod))%mod)
    digit+=1
for i in range(s_len+1):
    list[li[i]]+=1
for i in range(2019):
    x = list[i]
    ans += x*(x-1)/2
print(int(ans))
### BUGGY CODE ###

import sys

x, y = map(int, input().split())
cnt = 0
if abs(x) == abs(y):
    print(1)
elif abs(x) < abs(y):
    while x <= 0:
        x *= -1
        cnt += 1
    while abs(x) != abs(y):
        cnt += abs(y) - abs(x)
        x += abs(y) - abs(x)
    if x == y:
        print(cnt)
    else:
        print(cnt+1)
else:
    while x >= 0:
        x *= -1
        cnt += 1
    while abs(x) != abs(y):
        cnt += abs(x) - abs(y)
        x += abs(x) - abs(y)
    if x == y:
        print(cnt)
    else:
        print(cnt+1)

### FIXED CODE ###

import sys

x, y = map(int, input().split())
cnt = 0
if abs(x) == abs(y):
    print(1)
elif abs(x) < abs(y):
    while x < 0:
        x *= -1
        cnt += 1
    while abs(x) != abs(y):
        cnt += abs(y) - abs(x)
        x += abs(y) - abs(x)
    if x == y:
        print(cnt)
    else:
        print(cnt+1)
else:
    while x > 0:
        x *= -1
        cnt += 1
    while abs(x) != abs(y):
        cnt += abs(x) - abs(y)
        x += abs(x) - abs(y)
    if x == y:
        print(cnt)
    else:
        print(cnt+1)
### BUGGY CODE ###

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

for i in range(A, B + 1):
    if (i < A + K) or (i > B - K):
        print(i)

### FIXED CODE ###

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

x = []

for i in range(A, A + K):
    if (i <= B):
        x.append(i)

for i in range(B - K + 1, B + 1):
    if (i >= A):
        x.append(i)

y = set(x)

for i in range(len(y)):
    print(sorted(list(y))[i])
### BUGGY CODE ###

def main():
    from collections import namedtuple
    from operator import attrgetter

    Dish = namedtuple('Dish', 'time deliciousness')

    N, T = map(int, input().split())
    dishes = []
    for _ in range(N):
        a, b = map(int, input().split())
        d = Dish(time=a, deliciousness=b)
        dishes.append(d)

    dishes.sort(key=attrgetter('time'))

    dp = [0] * T
    ma = 0
    ret = 0
    for d in dishes:
        ret = max(ret, ma + d.deliciousness)
        for t in range(T - 1, d.time - 1, -1):
            dp[t] = max(dp[t], dp[t - d.time] + d.deliciousness)
            ma = max(ma, dp[t])
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


### FIXED CODE ###

def solve():
    from collections import namedtuple
    import sys

    input = sys.stdin.readline
    Dish = namedtuple('Dish', 'idx cost pt')

    n, t = map(int, input().split())
    dishes = []
    for idx in range(1, n + 1):
        cost, pt = map(int, input().split())
        dishes.append(Dish(idx=idx, cost=cost, pt=pt))

    dp_ht = [[0] * t for _ in range(n + 2)]  # head->tail
    dp_th = [[0] * t for _ in range(n + 2)]  # tail->head
    # dp[注文可能な範囲の端][完食にかかる総時間]:= 美味しさの最大値

    for dish in dishes:
        for cost_ in range(t):
            if cost_ >= dish.cost:
                dp_ht[dish.idx][cost_] = max(dp_ht[dish.idx - 1][cost_],
                                             dp_ht[dish.idx - 1][cost_ - dish.cost] + dish.pt)
            else:
                dp_ht[dish.idx][cost_] = dp_ht[dish.idx - 1][cost_]

    for dish in reversed(dishes):
        for cost_ in range(t):
            if cost_ >= dish.cost:
                dp_th[dish.idx][cost_] = max(dp_th[dish.idx + 1][cost_],
                                             dp_th[dish.idx + 1][cost_ - dish.cost] + dish.pt)
            else:
                dp_th[dish.idx][cost_] = dp_th[dish.idx + 1][cost_]

    ret = 0
    for last_dish in dishes:
        for cost_ in range(t):
            ret = max(ret, dp_ht[last_dish.idx - 1][cost_] + dp_th[last_dish.idx + 1][t - 1 - cost_] + last_dish.pt)
    return ret


print(solve())
### BUGGY CODE ###

def main():
  n,q=map(int,input().split())
  a=[[i] for i in range(n+1)]
  b=[0 for i in range(n+1)]
  
  for i in range(n-1):
    x,y=map(int,input().split())
    a[x].append(y)
#    print(a)
  
  for i in range(n):
    for j in range(i+1,n):
      if a[j][0] in a[i]:
        for k in a[j]:
          if k not in a[i]:
            a[i].append(k)
#  print("aaa",a)
  for i in range(q):
    x,y=map(int,input().split())
#    print("c,y",x,y)
#    print("ax",a[x])
#    print("B",b)
    for j in a[x]:
#      print("j",j)
      b[j-1]+=y
#      print(b)

       
  print(*b[:n])

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
  n,q=map(int,input().split())
  a=[0]*(n-1)
  c=[0 for i in range(n)]
  for i in range(n-1):
    a[i]=list(map(int,input().split()))

  a.sort()

  for i in range(q):
    x,y=map(int,input().split())
    c[x-1]+=y
  for i in range(n-1):
    c[a[i][1]-1]+=c[a[i][0]-1]
  print(*c)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())

l = [0]*N
for i in range(N):
    for j in range(N):
        for k in range(N):
            a = (i+1)**2 + (j+1)**2 + (k+1)**2 + (i+1)*(j+1) + (j+1)*(k+1) + (k+1)*(i+1)
            if a > N:
                break
            l[a-1] = l[a-1] + 1

for c in range(N):
    print(l[c])

### FIXED CODE ###

N = int(input())

l = [0]*N
for i in range(int(N**(1/2))):
    for j in range(int(N**(1/2))):
        for k in range(int(N**(1/2))):
            a = (i+1)**2 + (j+1)**2 + (k+1)**2 + (i+1)*(j+1) + (j+1)*(k+1) + (k+1)*(i+1)
            if a > N:
                break
            l[a-1] = l[a-1] + 1

for c in range(N):
    print(l[c])
### BUGGY CODE ###

from sys import stdin

def main():
	N = int(stdin.readline().strip())
	value = [int(x) for x in range(N)]
	i,card = 0,[-1 for x in range(N)]
	while i < N:
		x = int(stdin.readline().strip())
		card[i] = x
		i+=1
	i,ans = 0,0
	while i < N:
		if card[i]>=2:
			ans+=1
			card[i]-=2
		elif  i+1 < N:
			if card[i] == 1 and card[i+1]>=1:
				ans+=1
				card[i]-=1
				card[i+1]-=1
			else:
				i+=1
		else:
			i+=1
	print(ans)
main()

### FIXED CODE ###

from sys import stdin

def main():
	N = int(stdin.readline().strip())
	i,card = 0,[-1 for x in range(N)]
	while i < N:
		x = int(stdin.readline().strip())
		card[i] = x
		i+=1
	i,ans = 0,0
	while i < N:
		if card[i]%2==0:
			ans+= card[i]//2
			card[i] = 0
		else:
			ans+=(card[i]-1)//2
			card[i] = 1
			if i+1 < N and card[i+1] >=1:
				ans+=1
				card[i],card[i+1] = 0, card[i+1]-1
		i+=1
	print(ans)
main()
### BUGGY CODE ###

from collections import deque

def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        if now == goal or goal in connection[now]:
            connection[start].add(goal)
            connection[goal].add(start)
            return "yes"
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = map(int, input().split())
g = [set() for i in range(n)]
c = [set() for i in range(n)]

for i in range(m):
    inp = list(map(int, input().split()))
    g[inp[0]].add(inp[1])
    g[inp[1]].add(inp[0])
    c[inp[0]].add(inp[1])
    c[inp[1]].add(inp[0])

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    print(bfs(g, s, t, c))

### FIXED CODE ###

from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return visited

n, m = map(int, input().split())
g = [set() for i in range(n)]
group = []

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    for j in range(len(group)):
        if s in group[j] and t in group[j]:
            print("yes")
            break
        elif s in group[j]:
            print("no")
            break
    else:
        group_tmp = set(bfs(g, s).keys())
        if t in group_tmp:
            print("yes")
        else:
            print("no")
        group.append(group_tmp)
### BUGGY CODE ###

import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N,P = map(int,input().split())
    s = input()
    l = len(s)
    ans = 0
    if 10%P == 0:
        for i,st in enumerate(s[::-1]):
            num = int(st)
            if num%P == 0:
                ans += l-i
    else:
        d = defaultdict(int)
        d[0] = 1
        now = ""
        for st in s[::-1]:
            now = st+now
            num = int(now)
            ans += d[num%P]
            d[num%P] += 1
    
    print(ans)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    N,P = map(int,input().split())
    s = input()
    l = len(s)
    ans = 0
    if 10%P == 0:
        for i,st in enumerate(s[::-1]):
            num = int(st)
            if num%P == 0:
                ans += l-i
    else:
        rest = [0]
        t = 1
        for st in s[::-1]:
            num = int(st)%P
            rest.append(num*t%P)
            t = t*10%P
            
        for i in range(l):
            rest[i+1] += rest[i]

        for i in range(l):
            rest[i+1] %= P
            
        c = Counter(rest)
        c = list(c.values())
        for num in c:
            ans += num*(num-1)//2
    
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
 
#ab = [list(map(int, input().split())) for _ in range(M)]
#cd = [list(map(int, input().split())) for _ in range(K)]
 
lstab = [[] for _ in range(N)]
lstcd = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    lstab[a-1].append(b-1)
    lstab[b-1].append(a-1)

for _ in range(K):
    c, d = map(int, input().split())
    lstcd[c-1].append(d-1)
    lstcd[d-1].append(c-1)
    
groups = []
visiteds = [0] * N

for i in range(N):
    if visiteds[i] == 1: continue
    temp = [i]
    visited = [i]
    visiteds[i] = 1
 
    while temp:
        x = temp.pop()
        for y in lstab[x]:
            if visiteds[y] == 1:continue
            temp.append(y)
            visited.append(y)
            visiteds[y] = 1
    groups.append(visited)
 
ans = [0] * N
for grp in groups:
    setgrp = set(grp)
    for j in grp:
        ans[j] = len(setgrp - set(lstcd[j])) - 1 - len(lstab[j])
 
print(*ans)

### FIXED CODE ###

import sys
from collections import Counter
input = sys.stdin.readline

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

for _ in range(M):
    a, b = map(int, input().split())
    lstab[a-1].append(b-1)
    lstab[b-1].append(a-1)

visited = [0] * N
cnt = 0

for i in range(N):
    if visited[i] != 0: continue
    temp = [i]
    cnt += 1
    visited[i] = cnt
 
    while temp:
        x = temp.pop()
        for y in lstab[x]:
            if visited[y] != 0:continue
            temp.append(y)
            visited[y] = cnt

numcd = [ 0 ] * N
for _ in range(K):
    c, d = map(int, input().split())
    if visited[c-1] == visited[d-1]:
        numcd[c-1] += 1
        numcd[d-1] += 1    
    
ans = [0] * N
cnt = Counter(visited)

for i in range(N):
    ans[i] = cnt[visited[i]] - 1 - len(lstab[i]) - numcd[i]
 
print(*ans)
### BUGGY CODE ###

def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

    K, S = map(int, input().split())

    memo = [[-1] * (S + 1) for _ in range(4)]

    def dfs(cur, s=0):
        if ~memo[cur][s]:
            return memo[cur][s]

        if cur == 3:
            ret = int(s == S)
            memo[cur][s] = ret
            return ret

        ret = 0
        for r in range(min(K, S - s) + 1):
            ret += dfs(cur + 1, s + r)
        memo[cur][s] = ret
        return ret

    ans = dfs(0)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

k, s = map(int, input().split())
cnt = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - (x + y)
        if (0 <= z) and (z <= k):
            cnt += 1
print(cnt)
### BUGGY CODE ###

n = int(input())

for i in range(1,n+1):
    cnt = 0
    for x in range(1,101):
        if x*x<= i:
            for y in range(1,101):
                if x*x + y*y + x*y <= i:
                    for z in range(1,101):
                        if x*x + y*y + z*z + x*y + x*z + y*z == i:
                            cnt += 1
    print(cnt)

### FIXED CODE ###

n = int(input())

ans = [0 for i in range(10001)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            v = x*x+y*y+z*z+x*y+y*z+z*x
            if v < 10001:
                ans[v] += 1

for i in range(n):
    print(ans[i+1])
### BUGGY CODE ###

n = input()
ss = [raw_input() for _ in range(n)]
ss = map(sorted, ss)

print sum(1 for i in xrange(n) for j in xrange(i + 1, n) if ss[i] == ss[j])


### FIXED CODE ###

n = input()
d = {}
x = 0
for _ in xrange(n):
	ls = ''.join(sorted(raw_input()))
	if ls in d:
		x += d[ls]
		d[ls] += 1
	else:
		d[ls] = 1
print x