Given are integers N and K.
How many quadruples of integers (a,b,c,d) satisfy both of the following conditions?
 - 1 \leq a,b,c,d \leq N
 - a+b-c-d=K

-----Constraints-----
 - 1 \leq N \leq 10^5
 - -2(N-1) \leq K \leq 2(N-1)
 - All numbers in input are integers.

-----Input-----
Input is given from standard input in the following format:
N K

-----Output-----
Print the answer.

-----Sample Input-----
2 1

-----Sample Output-----
4

Four quadruples below satisfy the conditions:
 - (a,b,c,d)=(2,1,1,1)
 - (a,b,c,d)=(1,2,1,1)
 - (a,b,c,d)=(2,2,2,1)
 - (a,b,c,d)=(2,2,1,2)

Difficulty: MEDIUM_HARD

Solutions:
(N, K) = map(int, input().split())

def num_pair(m):
	if m <= N:
		return m - 1
	return 2 * N - m + 1
K = abs(K)
ans = 0
for i in range(K + 2, 2 * N + 1):
	ans += num_pair(i) * num_pair(i - K)
print(ans)


(n, k) = map(int, input().split())
ans = 0
for cd in range(2, 2 * n + 1):
	if 2 <= k + cd and k + cd <= 2 * n:
		ans += (n - abs(cd - (n + 1))) * (n - abs(k + cd - (n + 1)))
print(ans)


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

def cnt(n):
	if n < 2:
		return 0
	if n > 2 * N:
		return 0
	return n - 2 * max(n - N, 1) + 1
ans = 0
for ab in range(2, 2 * N + 1):
	cd = ab - K
	ans += cnt(ab) * cnt(cd)
print(ans)


(N, K) = map(int, input().split())
ans = 0
for x in range(2, 2 * N + 1):
	y = x - K
	if y < 2 or y > 2 * N:
		continue
	cnt_x = min(x - 1, 2 * N + 1 - x)
	cnt_y = min(y - 1, 2 * N + 1 - y)
	ans += cnt_x * cnt_y
print(ans)


(N, K) = map(int, input().split())
(tmp1, tmp2, ans) = (0, 0, 0)
for i in range(2, 2 * N + 1):
	tmp1 = min(i - 1, 2 * N + 1 - i)
	tmp2 = min(i - K - 1, 2 * N + 1 - i + K)
	if tmp1 >= 0 and tmp2 >= 0:
		ans += tmp1 * tmp2
print(ans)


(N, K) = map(int, input().split())
ans = 0

def func(k):
	return min(k - 1, 2 * N + 1 - k)
for i in range(2, 2 * N + 1):
	ab = i
	cd = ab - K
	if cd < 2 or cd > 2 * N:
		continue
	ans += func(ab) * func(cd)
print(ans)


mod = 998244353
(n, k) = map(int, input().split())
k = abs(k)

def count(num):
	if num <= n:
		return num - 1
	else:
		return num - 1 - (num - n - 1) * 2

def main():
	ans = 0
	for i in range(k + 2, 2 * n + 1):
		j = i - k
		ans += count(i) * count(j)
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
ans = 0
for i in range(2, 2 * n + 1):
	if 2 <= i - k <= 2 * n:
		ans += min(2 * n + 1 - i, i - 1) * min(2 * n + 1 - i + k, i - k - 1)
print(ans)


(N, K) = map(int, input().split())
cnt = [0] * (2 * N + 1)
for i in range(0, 2 * N + 1):
	if i > 1 and i < N + 2:
		cnt[i] = cnt[i - 1] + 1
	elif i >= N + 2:
		cnt[i] = cnt[i - 1] - 1
ans = 0
for i in range(K + 2, 2 * N + 1):
	if i < 2:
		continue
	if 2 * N >= i - K >= 1:
		ans += cnt[i] * cnt[i - K]
print(ans)


(N, K) = map(int, input().split())
l = max(2, 2 + K)
r = min(2 * N, 2 * N + K)
ans = 0
for i in range(l, r + 1):
	la = max(1, i - N)
	ra = min(i - 1, N)
	lc = max(i - K - N, 1)
	rc = min(i - K - 1, N)
	ans += (ra - la + 1) * (rc - lc + 1)
print(ans)


from math import gcd
from itertools import combinations, permutations, accumulate, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())

def f(n):
	return int(math.ceil(n - 0.5))
from math import gcd
from itertools import combinations, permutations, accumulate, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())

def f(n):
	return int(math.ceil(n - 0.5))
(N, K) = readInts()

def calc(n):
	if n <= 0:
		return 0
	elif n > 2 * N:
		return 0
	else:
		return min(2 * N - n + 1, n - 1)
ans = 0
for i in range(1, 2 * N + 1):
	ans += calc(i) * calc(i - K)
print(ans)


(n, k) = map(int, input().split(' '))
k = abs(k)
ans = 0

def f(x):
	low = max(1, x - n)
	high = min(n, x - 1)
	return max(high - low + 1, 0)
for i in range(k + 2, k + n + n + 1):
	ans += f(i) * f(i - k)
print(ans)


def f(a, b):
	return min(2 * a - b + 1, b - 1)
(n, k) = map(int, input().split())
ans = 0
for i in range(2, 2 * n + 1):
	if not 2 <= i - k <= 2 * n:
		continue
	ans += f(n, i) * f(n, i - k)
print(ans)


(n, k) = map(int, input().split())
k = abs(k)
ans = 0
for i in range(k + 2, 2 * n + 1):
	x = min(i - 1, 2 * n - i + 1)
	y = min(i - 1 - k, 2 * n + 1 - (i - k))
	ans += x * y
print(ans)


import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect

def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)

def solve(N, K):
	s = 0
	for Y in range(2, 2 * N + 1):
		X = Y + K
		if 2 <= X <= 2 * N:
			a_min = max(X - N, 1)
			a_max = min(X - 1, N)
			c_min = max(Y - N, 1)
			c_max = min(Y - 1, N)
			if a_min <= a_max or c_min <= c_max:
				s += (a_max - a_min + 1) * (c_max - c_min + 1)
	return s

def main():
	(N, K) = list(map(int, input().split()))
	a = solve(N, K)
	print(a)

def __starting_point():
	main()
__starting_point()


def solve(N, K):
	tmp = 0
	for ab in range(2, 2 * N + 1):
		cd = ab - K
		tmp += sub(N, ab) * sub(N, cd)
	return tmp

def sub(N, K):
	if K - 1 < 0:
		return 0
	elif 0 <= K - 1 <= N:
		return K - 1
	elif N < K - 1:
		return max(0, K - 1 - 2 * (K - 1 - N))

def main():
	(N, K) = list(map(int, input().split()))
	a = solve(N, K)
	print(a)

def __starting_point():
	main()
__starting_point()


from math import comb
(N, K) = list(map(int, input().split()))
ans = comb(K + 2 * N + 1, 3)
for i in range(1, 5):
	if K + 2 * N + 1 - i * N >= 0:
		ans += (-1) ** i * comb(K + 2 * N + 1 - i * N, 3) * comb(4, i)
print(ans)


(N, K) = list(map(int, input().split()))
count = 0
for x in range(2, min(2 * N + 1, K + 2 * N + 1)):
	x_way = min(N, x - 1) - max(1, x - N) + 1
	y = x - K
	if 2 <= y <= 2 * N:
		y_way = min(N, y - 1) - max(1, y - N) + 1
		count += x_way * y_way
print(count)


(n, k) = map(int, input().split())
cnt = 0
for x in range(2, 2 * n + 1):
	if 2 <= x - k <= 2 * n:
		y = x - k
		if x - 1 >= n:
			c1 = max(x - 1 - 2 * (x - 1 - n), 0)
		else:
			c1 = x - 1
		if y - 1 >= n:
			c2 = max(y - 1 - 2 * (y - 1 - n), 0)
		else:
			c2 = y - 1
		cnt += c1 * c2
print(cnt)


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

def count(s):
	return min(s - 1, 2 * n + 1 - s)
ans = 0
for i in range(2, 2 * n + 1):
	if 2 <= i - k <= 2 * n:
		ans += count(i) * count(i - k)
print(ans)


import sys

def LI():
	return list(map(int, input().split()))
(N, K) = LI()
K = abs(K)
ans = 0
for i in range(2 + K, 2 * N + 1):
	i -= 1
	L = max(0, (i - N) * 2)
	R = max(0, (i - K - N) * 2)
	ans += (i - L) * (i - K - R)
print(ans)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
(n, k) = nii()
ans = 0
for i in range(2, 2 * n + 1):
	j = i - k
	if not 2 <= j <= 2 * n:
		continue
	num1 = 2 * min(i - 1, n) - i + 1
	num2 = 2 * min(j - 1, n) - j + 1
	ans += num1 * num2
print(ans)


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

def count(x):
	if x <= N + 1:
		return x - 1
	else:
		return x - 1 - 2 * (x - 1 - N)
ans = 0
for x in range(2, 2 * N + 1):
	y = x - K
	if not 2 <= y <= 2 * N:
		continue
	ans += count(x) * count(y)
print(ans)


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

def f(x):
	mi = max(1, x - n)
	ma = min(n, x - 1)
	return ma - mi + 1
ans = 0
for p in range(2, 2 * n + 1):
	q = p - k
	if q < 1 or q > 2 * n:
		continue
	ans += f(p) * f(q)
print(ans)


(n, k) = map(int, input().split())
ans = 0
for A in range(2, 2 * n + 1):
	B = A - k
	if 2 <= B <= 2 * n:
		ans += min(A - 1, 2 * n + 1 - A) * min(B - 1, 2 * n + 1 - B)
print(ans)


def main():
	(n, k) = list(map(int, input().split()))
	k = abs(k)
	c = 0
	for y in range(2, 2 * n - k + 1):
		x = y + k
		c += counter(x, n) * counter(y, n)
	print(c)
	return

def counter(value, n):
	ins = value - 2
	return min(ins, 2 * (n - 1) - ins) + 1

def __starting_point():
	main()
__starting_point()


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

def f(a, b):
	return max(min(b - 1, 2 * a + 1 - b), 0)
ans = 0
for i in range(2, 2 * n + 1):
	ans += f(n, i) * f(n, i - k)
print(ans)


(n, k) = map(int, input().split())
k = abs(k)
x = 0
for i in range(2 + k, 2 * n + 1):
	y = i - 1 if i <= n + 1 else 2 * n - i + 1
	z = i - k - 1 if i <= n + k + 1 else 2 * n - i + k + 1
	x += y * z
print(x)


(N, K) = list(map(int, input().split()))
K = abs(K)
num = [0] * (2 * N + 1)
for v in range(2, 2 * N + 1):
	num[v] = min(v - 1, 2 * N + 1 - v)
res = 0
for v in range(2 + K, 2 * N + 1):
	res += num[v] * num[v - K]
print(res)


(N, K) = map(int, input().split())
ans = 0
for i in range(2, 2 * N + 1):
	j = i - K
	if not 2 <= j <= 2 * N:
		continue
	A = min(i - 1, i - 1 - (i - 1 - N) * 2)
	C = min(j - 1, j - 1 - (j - 1 - N) * 2)
	ans += A * C
print(ans)


(N, K) = map(int, input().split())
ans = 0
for AB in range(max(2, K + 2), min(2 * N, K + 2 * N) + 1):
	ans += (min(AB - 1, N) - max(1, AB - N) + 1) * (min(AB - K - 1, N) - max(1, AB - K - N) + 1)
print(ans)


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

def f(N, K):
	ans = max(0, min(K - 1, 2 * N + 1 - K))
	return ans
ans = 0
for x in range(2, 2 * N + 1):
	ans += f(N, x) * f(N, x - K)
print(ans)


(N, K) = map(int, input().split())
cnt = 0
for x in range(2, 2 * N + 1):
	if 2 <= x - K <= 2 * N:
		y = x - K
		if x - 1 >= N:
			c1 = max(x - 1 - 2 * (x - 1 - N), 0)
		else:
			c1 = x - 1
		if y - 1 >= N:
			c2 = max(y - 1 - 2 * (y - 1 - N), 0)
		else:
			c2 = y - 1
		cnt += c1 * c2
print(cnt)


(N, K) = map(int, input().split())
cnt = 0
for X in range(2, 2 * N + 1):
	if X <= N + 1:
		cx = X - 1
	else:
		cx = 2 * N + 1 - X
	Y = X - K
	if 2 <= Y <= 2 * N:
		if Y <= N + 1:
			cy = Y - 1
		else:
			cy = 2 * N + 1 - Y
		cnt += cx * cy
print(cnt)


(N, K) = map(int, input().split())
K = abs(K)
print(sum(((N - abs(N - n)) * (N - abs(N - n + K)) for n in range(K + 1, 2 * N))))


(N, K) = [int(x) for x in input().split()]
minA = 2
maxA = 2 * N
minC = 2
maxC = 2 * N
minA = max(minA, K + minC)
maxA = min(maxA, K + maxC)
ans = 0
for i in range(minA, maxA + 1):
	C = i - K
	mina = i - N
	maxa = i - 1
	if mina < 1:
		mina = 1
	if maxa > N:
		maxa = N
	cntA = maxa - mina + 1
	minc = C - N
	maxc = C - 1
	if minc < 1:
		minc = 1
	if maxc > N:
		maxc = N
	cntC = maxc - minc + 1
	ans += cntA * cntC
print(ans)


(n, k) = map(int, input().split())
from math import ceil
ans = 0
for x in range(2, 2 * n + 1):
	cd = x - k
	if cd < 2 or cd > 2 * n:
		continue
	p = min(x - 1, 2 * n - x + 1)
	q = min(cd - 1, 2 * n - cd + 1)
	ans = ans + p * q
print(ans)


(n, k) = map(int, input().split())
ans = 0
for i in range(2, 2 * n + 1):
	if i > n:
		ab = 2 * n - i + 1
	else:
		ab = i - 1
	r = i - k
	if r <= 1 or r >= 2 * n + 1:
		cd = 0
	elif r > n:
		cd = 2 * n - r + 1
	else:
		cd = r - 1
	ans += ab * cd
print(ans)


(n, k) = list(map(int, input().split()))
k = abs(k)
result = 0
for p in range(k + 2, 2 * n + 1):
	if p <= n + 1:
		result = result + (p - 1) * (p - k - 1)
	elif n + 2 <= p <= n + k + 1:
		result = result + (2 * n - p + 1) * (p - k - 1)
	else:
		result = result + (2 * n - p + 1) * (2 * n - p + k + 1)
print(result)


(n, k) = list(map(int, input().split()))
cnt = 0
for y in range(2, 2 * n + 1):
	if y <= n:
		q = y - 1
	else:
		q = 2 * n - y + 1
	x = k + y
	if 2 <= x <= 2 * n:
		if x <= n:
			p = x - 1
		else:
			p = 2 * n - x + 1
		cnt += p * q
print(cnt)


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

def g(t):
	if t < 2 or 2 * n < t:
		return 0
	if dp[t] > -1:
		return dp[t]
	if t - 1 <= n:
		dp[t] = t - 1
		return dp[t]
	if t - 1 > n:
		dp[t] = 2 * n + 1 - t
		return dp[t]
dp = [-1] * (2 * n + 1)
ans = 0
for i in range(2, 2 * n + 1):
	ans += g(i) * g(i + k)
print(ans)


(n, k) = map(int, input().split())
k = abs(k)
A = B = ans = 0
value = [False] * (2 * n + 1)
for i in range(k + 2, 2 * n + 1):
	A = i
	B = A - k
	if n + 1 >= A:
		C = A - 1
	else:
		AA = abs(A - 2 * n - 2)
		C = AA - 1
	if n + 1 >= B:
		D = B - 1
	else:
		BB = abs(B - 2 * n - 2)
		D = BB - 1
	ans += C * D
print(ans)


(N, K) = map(int, input().split())
P = []
for i in range(2 * N + 1):
	P.append(min(i - 1, 2 * N + 1 - i))
ans = 0
for i in range(2, 2 * N + 1):
	if 2 <= i - K <= 2 * N:
		ans += P[i] * P[i - K]
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
read = lambda : sys.stdin.readline()

def read_ints():
	return list(map(int, read().split()))

def read_intgrid(h):
	return list((list(map(int, read().split())) for i in range(h)))

def read_strgrid(h):
	return list((list(read()) for i in range(h)))

def main():
	(n, k) = map(int, read().split())
	k = abs(k)
	combs = [0] * (n * 2 + 1)
	for i in range(1, n * 2 + 1):
		if i == n + 1:
			combs[i] = n
		elif i < n + 1:
			combs[i] = i - 1
		elif i > n + 1:
			combs[i] = 2 * n - i + 1
	cnt = 0
	for i in range(1, n * 2 + 1):
		cnt += combs[i] * combs[max(0, i - k)]
	print(cnt)
	return None

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
DN = 2 * N
ans = 0
for ab in range(2, DN + 1):
	cd = ab - K
	if cd < 2 or cd > DN:
		continue
	ans += min(DN - ab + 1, ab - 1) * min(DN - cd + 1, cd - 1)
print(ans)


(N, K) = list(map(int, input().split()))
ans = 0
for ab in range(2, 2 * N + 1):
	cd = ab - K
	if not 2 <= cd <= 2 * N:
		continue
	ans += min(ab - 1, 2 * N - ab + 1) * min(cd - 1, 2 * N - cd + 1)
print(ans)


(N, K) = map(int, input().split())
alpha = 2
sum = 0
while alpha <= 2 * N:
	beta = alpha - K
	if 2 <= beta and beta <= 2 * N:
		if alpha <= N + 1:
			if beta <= N + 1:
				sum += (alpha - 1) * (beta - 1)
			else:
				sum += (alpha - 1) * (2 * N - beta + 1)
		elif beta <= N + 1:
			sum += (2 * N - alpha + 1) * (beta - 1)
		else:
			sum += (2 * N - alpha + 1) * (2 * N - beta + 1)
	alpha += 1
print(sum)


def MII():
	return map(int, input().split())
(n, k) = MII()
count = 0
for x in range(2, 2 * n + 1):
	y = x - k
	if 2 <= y <= 2 * n:
		abmax = min(x - 1, n)
		abmin = x - abmax
		cdmax = min(y - 1, n)
		cdmin = y - cdmax
		count += (abmax - abmin + 1) * (cdmax - cdmin + 1)
print(count)


(N, K) = list(map(int, input().split()))
K = abs(K)
ans = 0
for i in range(K + 2, 2 * N + 1):
	Big = i
	Small = i - K
	if Big <= N + 1:
		pattern_of_big = Big - 1
	else:
		tmp = Big - N
		pattern_of_big = N - tmp + 1
	if Small <= N + 1:
		patter_of_small = Small - 1
	else:
		tmp = Small - N
		patter_of_small = N - tmp + 1
	ans += pattern_of_big * patter_of_small
print(ans)


(N, K) = [int(x) for x in input().split()]

def conb(x):
	if x > N:
		return max(2 * N - x + 1, 0)
	else:
		return max(x - 1, 0)
ans = 0
for i in range(1, 2 * N + 1):
	ans += conb(i + K) * conb(i)
print(ans)


(N, K) = list(map(int, input().split()))
ans = 0
for i in range(2, 2 * N + 1):
	ab = min(i - 1, 2 * N - i + 1)
	cd = min(i - K - 1, 2 * N - i + K + 1)
	if 1 <= ab <= N and 1 <= cd <= N:
		ans += ab * cd
print(ans)


(N, K) = list(map(int, input().split(' ')))
K = abs(K)
result = 0
for i in range(K + 2, 2 * N + 1):
	AB = i
	CD = AB - K
	AB -= max(0, (AB - (N + 1)) * 2)
	CD -= max(0, (CD - (N + 1)) * 2)
	result += (AB - 1) * (CD - 1)
print(result)


(N, K) = map(int, input().split())
table = [0] * (2 * N + 1)
for i in range(N):
	table[N + i] = table[N - i] = N - i
ans = 0
for i in range(2 * N + 1):
	if 0 <= (j := (K - (i - N) + N)) < 2 * N + 1:
		ans += table[i] * table[j]
print(ans)


(n, k) = map(int, input().split())
k = abs(k)
print(sum((min(i - 1, 2 * n - i + 1) * min(j - 1, 2 * n - j + 1) for (i, j) in zip(range(2 + k, n * 2 + 1), range(2, n * 2 + 1 - k)))))


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

def f(y):
	if 1 <= y <= n + 1:
		return y - 1
	else:
		return 2 * (n + 1) - y - 1
for A in range(2, 2 * n + 1):
	B = A - k
	if 2 <= B <= 2 * n:
		ans += f(A) * f(B)
print(ans)


import bisect
(N, K) = map(int, input().split())
ans = 0
for i in range(2, 2 * N + 1):
	if 2 <= i - K <= 2 * N:
		ans = min(i - K - 1, 2 * N - (i - K) + 1) * min(i - 1, 2 * N - i + 1) + ans
print(ans)


import sys
(N, K) = map(int, input().split())
cnt = 0
for q in range(max(2 - K, 2), min(2 * N - K + 1, 2 * N + 1)):
	p = K + q
	if p - 1 > N and q - 1 > N:
		cnt = cnt + (abs(2 * N - p) + 1) * (abs(2 * N - q) + 1)
	elif q - 1 > N:
		cnt = cnt + (abs(2 * N - q) + 1) * (p - 1)
	elif p - 1 > N:
		cnt = cnt + (abs(2 * N - p) + 1) * (q - 1)
	else:
		cnt = cnt + (q - 1) * (p - 1)
print(cnt)


(N, K) = map(int, input().split())
pattern = lambda x, K: max(0, min(K - 1, 2 * x + 1 - K))
res = 0
for x in range(2, 2 * N + 1):
	res += pattern(N, x) * pattern(N, x - K)
print(res)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inps():
	return input().rstrip()

def inpl():
	return list(map(int, input().split()))

def inpls():
	return list(map(str, input().split()))
from math import gcd, floor, ceil, factorial
import itertools as it
from collections import deque, defaultdict
from collections import Counter

def lcd(a, b):
	return a * b // gcd(a, b)

def chmin(dp, i, x):
	if x < dp[i]:
		dp[i] = x
		return True
	return False

def chmax(dp, i, x):
	if x > dp[i]:
		dp[i] = x
		return True
	return False
(N, K) = inpl()
mn = 1 * 2
mx = N * 2
mid = (mx - mn) // 2 + mn
dp = [0] * (mx + 1)
for i in range(mn, mx + 1):
	dp[i] = mid - abs(i - mid) - 1
ans = 0
for i in range(mn, mx + 1):
	j = i - K
	if mn <= j <= mx:
		ans += dp[i] * dp[j]
print(ans)


(N, K) = list(map(int, input().split()))
K = abs(K)
ans = 0
ab = 2 * N
pat = 1
while ab - K >= 2:
	if ab - K >= (2 + 2 * N) // 2:
		ans += (pat + K) * pat
	else:
		ans += (ab - K - 2 + 1) * pat
	ab -= 1
	if ab >= (2 + 2 * N) // 2:
		pat += 1
	else:
		pat -= 1
print(ans)


(N, K) = map(int, input().split())
ans = 0
for B in range(2, 2 * N + 1):
	A = K + B
	if A < 2 or A > 2 * N:
		continue
	a_n = min(A - 1, 2 * N + 1 - A)
	b_n = min(B - 1, 2 * N + 1 - B)
	ans += a_n * b_n
print(ans)


(N, K) = list(map(int, input().split()))
ans = 0
for i in range(2, 2 * N + 1):
	A = i
	B = i - K
	if 2 * N >= B >= 2:
		X = min(N, A - 1) - max(1, A - N) + 1
		Y = min(N, B - 1) - max(1, B - N) + 1
		ans += X * Y
print(ans)


(N, K) = list(map(int, input().split()))
ans = 0
for ac in range(1 - N, N):
	db = ac - K
	if db < 1 - N or N - 1 < db:
		continue
	ans += (N - abs(ac)) * (N - abs(db))
print(ans)


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

def f(t):
	if 2 <= t <= N + 1:
		return t - 1
	elif N + 1 <= t <= 2 * N:
		return 2 * N + 1 - t
	else:
		return 0
s = 0
for y in range(2, 2 * N + 1):
	s += f(y) * f(y + K)
print(s)


def f(x):
	return min(x - 1, 2 * N - x + 1)
(N, K) = map(int, input().split())
ans = 0
for ab in range(2, 2 * N + 1):
	cd = ab - K
	if cd < 2 or 2 * N + 1 < cd:
		continue
	ans += f(ab) * f(cd)
print(ans)


(N, K) = list(map(int, input().split()))
ans = 0
for i in range(2, 2 * N + 1):
	ans += min(i - 1, 2 * N - i + 1) * max(0, min(i - K - 1, 2 * N - i + K + 1))
print(ans)


(n, k) = list(map(int, input().split()))
ans = 0
for x in range(2, 2 * n + 1):
	if 1 < x - k <= 2 * n:
		ans += min(x - 1, 2 * n + 1 - x) * min(x - k - 1, 2 * n + 1 - x + k)
print(ans)


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

def half(v):
	if 2 <= v <= n + 1:
		return v - 1
	elif n + 2 <= v <= 2 * n:
		return 2 * n + 1 - v
	else:
		return 0
ans = 0
for i in range(2, 2 * n + 1):
	ans += half(i) * half(i - k)
print(ans)


(n, k) = map(int, input().split())
cnt = 0
for ab in range(1 - n, n):
	cd = k - ab
	if 1 - n <= cd <= n - 1:
		cnt += (n - abs(ab)) * (n - abs(cd))
print(cnt)


import sys
from math import gcd, factorial, ceil, floor, sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
from heapq import heapify, heappop, heappush
from itertools import permutations, combinations, product, accumulate
from collections import defaultdict, deque, Counter
from functools import lru_cache
sys.setrecursionlimit(10 ** 8)
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))
(N, K) = mi()
ans = 0
ls = []
for i in range(-N + 1, N):
	if K - i < N and K - i >= -N + 1:
		A = i
		B = K - A
		ans += (N - abs(B)) * (N - abs(A))
print(ans)


(n, k) = list(map(int, input().split()))
kazu = [0] + [i for i in range(n + 1)]
rev_kazu = sorted(kazu[:n + 1], reverse=True)
kazu += rev_kazu
ans = 0
for A in range(2, 2 * n + 1):
	B = A - k
	if B >= 2 and B <= 2 * n:
		ans += kazu[A] * kazu[B]
print(ans)


import sys
try:
	import os
	f = open('input.txt', 'r')
	sys.stdin = f
except FileNotFoundError:
	None
from math import sqrt, ceil, floor
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP, Decimal
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright, insort
from itertools import combinations as com, permutations as per
from fractions import Fraction as frac
(n, k) = list(map(int, input().split()))
ans = 0

def num(j):
	if 2 > j:
		return 0
	if j > 2 * n:
		return 0
	if j < n + 1:
		return j - 1
	sa = 2 * (j - n - 1)
	return j - 1 - sa
for i in range(2, 2 * n - k + 1):
	a = num(i + k)
	b = num(i)
	ans += a * b
print(ans)


(n, k) = map(int, input().split())
k = abs(k)
ans = 0
for x in range(k + 2, 2 * n + 1):
	b = min(n, x - 1)
	a = x - b
	res1 = b - a + 1
	c = min(n, x - k - 1)
	d = x - k - c
	res2 = c - d + 1
	ans += res1 * res2
print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()

def main():
	(N, K) = list(map(int, input().split()))
	N = 2 * (N - 1)
	K = abs(K)
	ans = sum(((1 + min(i + K, N - i - K)) * (1 + min(i, N - i)) for i in range(N - K + 1)))
	print(ans)

def __starting_point():
	main()
__starting_point()


import numpy as np
(N, K) = map(int, input().split())
K = abs(K)
C = np.array([*range(-1, N), *range(N, 0, -1)], dtype=np.int64)
C[0] = 0
print(C[:-K] @ C[K:] if K else C @ C)


(n, k) = map(int, input().split())
cnt = 0
for ac in range(1 - n, n):
	bd = k - ac
	if 1 - n <= bd <= n - 1:
		cnt += (n - abs(ac)) * (n - abs(bd))
print(cnt)


(n, k) = list(map(int, input().split()))
dp = [0] * (2 * n + 1)
for ii in range(1, n + 1):
	dp[ii + 1] = ii
	dp[ii + n] = n - ii + 1
r = 0
for ab in range(2, 2 * n + 1):
	cd = ab - k
	if cd > 1 and cd <= 2 * n:
		r += dp[ab] * dp[cd]
print(r)


def f(n, x):
	if x < 2 or 2 * n < x:
		return 0
	return abs(x - 2 * min(x - 1, n)) + 1
(n, k) = list(map(int, input().split()))
print(sum((f(n, x) * f(n, x + k) for x in range(2, 2 * n - k + 1))))


import sys
sys.setrecursionlimit(10 ** 7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor

def cmb(n, r, mod):
	bunshi = 1
	bunbo = 1
	for i in range(r):
		bunbo = bunbo * (i + 1) % mod
		bunshi = bunshi * (n - i) % mod
	return bunshi * pow(bunbo, mod - 2, mod) % mod
mod = 998244353

def I():
	return int(input())

def LI():
	return list(map(int, input().split()))

def MI():
	return list(map(int, input().split()))

def LLI(n):
	return [list(map(int, input().split())) for _ in range(n)]

def func(n, k):
	return min(k - 1, 2 * n + 1 - k)
(n, k) = MI()
A = max(2, 2 + k)
B = min(2 * n, 2 * n + k)
ans = 0
for x in range(A, B + 1):
	ans += func(n, x) * func(n, x - k)
print(ans)