We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq  i < N ) holds.
Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.
Let S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there?

-----Constraints-----
 - -10^8 \leq X, D \leq 10^8
 - 1 \leq N \leq 2 \times 10^5
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N X D

-----Output-----
Print the number of possible values of S - T.

-----Sample Input-----
3 4 2

-----Sample Output-----
8

A is (4, 6, 8).
There are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4))), and ((4, 6, 8), ()).
The values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18, respectively, so there are eight possible values of S - T.

Difficulty: MEDIUM_HARD

Solutions:
from operator import itemgetter
(n, x, d) = map(int, input().split())
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit()
if d < 0:
	x *= -1
	d *= -1
p = dict()
q = dict()
for k in range(n + 1):
	temp = k * x % d
	if temp in p.keys():
		a = (k - p[temp]) * x // d
		L = (k - 1) * k // 2 + a
		H = (2 * n - k - 1) * k // 2 + a
		q[temp].append([L, H])
	else:
		p[temp] = k
		L = (k - 1) * k // 2
		H = (2 * n - k - 1) * k // 2
		q[temp] = [[L, H]]
ans = 0
for z in q.values():
	c = -float('inf')
	for (a, b) in sorted(z):
		if a > c:
			ans += b - a + 1
		elif b > c:
			ans += b - c
		else:
			continue
		c = b
print(ans)


(n, x, d) = map(int, input().split())
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit(0)
ranges = {}
for k in range(n + 1):
	mod = k * x % d
	l = k * x // d + k * (k - 1) // 2
	r = k * x // d + k * (2 * n - k - 1) // 2
	if mod not in ranges:
		ranges[mod] = []
	ranges[mod].append((l, -1))
	ranges[mod].append((r + 1, 1))
ans = 0
for mod in ranges:
	lrs = ranges[mod]
	lrs.sort()
	cnt = 0
	last = -1
	for (x, y) in lrs:
		if cnt == 0:
			last = x
		cnt += y
		if cnt == 0:
			ans += x - last
print(ans)


import math
(n, X, D) = map(int, input().split())
if D == 0:
	if X == 0:
		print(1)
	else:
		print(n + 1)
	exit()
Y = dict()
for i in range(n + 1):
	b = -2 * i * X
	r = (n - 1 + n - i) * i // 2
	l = (0 + i - 1) * i // 2
	off = b % (-2 * D)
	l += (b - off) // (-2 * D)
	r += (b - off) // (-2 * D)
	if off in Y:
		Y[off].append((l, r))
	else:
		Y[off] = [(l, r)]

def calc(u):
	pt = dict()
	for (l, r) in u:
		if l in pt:
			pt[l] += 1
		else:
			pt[l] = 1
		if r + 1 in pt:
			pt[r + 1] -= 1
		else:
			pt[r + 1] = -1
	(cur, v) = (-10 ** 100, 0)
	ans = 0
	for k in sorted(pt.keys()):
		if v:
			ans += k - cur
		v += pt[k]
		cur = k
	return ans
print(sum(map(calc, Y.values())))


(N, X, D) = map(int, input().split())
if D == 0:
	print(1 if X == 0 else N + 1)
	exit()
if D < 0:
	D *= -1
	X -= D * (N - 1)
from collections import defaultdict
arrs = defaultdict(lambda : defaultdict(lambda : 0))
mni = mxi = 0
for k in range(N + 1):
	(d, m) = divmod(k * X + D * mni, D)
	l = mxi - mni + 1
	arrs[m][d] += 1
	arrs[m][d + l] -= 1
	mni += k
	mxi += N - k - 1
ans = 0
for arr in arrs.values():
	p = None
	c = 0
	for (x, v) in sorted(arr.items()):
		if c > 0:
			ans += x - p
		c += v
		p = x
print(ans)


(n, x, d) = map(int, input().split())
if d == 0:
	if x == 0:
		print(1)
		exit()
	else:
		print(n + 1)
		exit()
if d < 0:
	y = x
	x = x + d * (n - 1)
	d = -d
else:
	y = x + d * (n - 1)
U = {}
ans = 0
has0 = 0
for k in range(1, n + 1):
	r = x * k % d
	s = k * d * (k - 1) // 2
	v1 = k * x + s
	v2 = k * y - s
	if r in U:
		u = U[r]
		if v1 > u[1] or v2 < u[0]:
			ans += (u[1] - u[0]) // d + 1
		else:
			v1 = min(v1, U[r][0])
			v2 = max(v2, U[r][1])
	U[r] = (v1, v2)
	if r == 0 and v1 <= 0 and (v2 >= 0):
		has0 = 1
for (r, u) in U.items():
	ans += (u[1] - u[0]) // d + 1
if not has0:
	ans += 1
print(ans)


(N, X, D) = map(int, input().split())
r = N * (X != 0) + 1
if D:
	(f, c, r) = ({}, [0] * abs(D), 0)
	for (x, y, z) in sorted((((N - k) * k * j + ~-k * k // 2 + k * X // D, j, k * X % D) for k in range(N + 1) for j in [0, 1])):
		if c[z] < 2 * y:
			r += (x - f[z] + 1) * (c[z] < 2) * y
		if c[z] + y < 1:
			f[z] = x
		c[z] -= 2 * y - 1
print(r)


import sys

def main():
	(n, x, d) = map(int, input().split())
	events_map = {}
	if d == 0:
		if x == 0:
			print(1)
		else:
			print(n + 1)
		return
	for k in range(n + 1):
		l = (k * x if d > 0 else -k * x) + (k - 1) * k // 2 * abs(d)
		r = (k * x if d > 0 else -k * x) + (n - k + n - 1) * k // 2 * abs(d)
		row = l % abs(d)
		if row not in events_map:
			events_map[row] = []
		events_map[row].append((l, -1))
		events_map[row].append((r, 1))
	ans = 0
	for q in events_map.items():
		events = q[1]
		events.sort()
		bal = 0
		total = 0
		curL = -1
		for event in events:
			if bal == 0 and event[1] == -1:
				curL = event[0]
			if bal == 1 and event[1] == 1:
				curr = event[0]
				total += (curr - curL) // abs(d) + 1
			bal -= event[1]
		ans += total
	print(ans)
main()


(n, a, d) = map(int, input().split())
dic = {}
ans = 0
if d == 0:
	if a == 0:
		print(1)
	else:
		print(n + 1)
else:
	for k in range(n + 1):
		l = k * a + k * (k - 1) * d // 2
		r = l + k * (n - k) * d
		idx = l % d
		l //= d
		r //= d
		if idx in dic:
			(prel, prer) = dic[idx]
			if prer < l or prel > r:
				dic[idx] = (l, r)
				ans += r - l + 1
			else:
				nl = min(prel, l)
				nr = max(prer, r)
				ans += prel - nl + nr - prer
				dic[idx] = (nl, nr)
		else:
			ans += r - l + 1
			dic[idx] = (l, r)
	print(ans)


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 13

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def I():
	return int(sys.stdin.buffer.readline())

def LS():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
(n, x, d) = LI()
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit()
D = defaultdict(list)
for i in range(n + 1):
	a = i * x
	L = i * (i - 1) // 2
	R = (2 * n - i - 1) * i // 2
	D[a % d] += [(a // d + L, a // d + R)]
ans = 0
for L in D.values():
	L.sort()
	now = -INF
	for (l, r) in L:
		if r <= now:
			continue
		elif l > now:
			ans += r - l + 1
		else:
			ans += r - now
		now = r
print(ans)


from collections import defaultdict
from operator import itemgetter

def solve(N, X, D):
	if D < 0:
		D = -D
		X = -X
	elif D == 0:
		if X == 0:
			return 1
		return N + 1
	s = defaultdict(list)
	for k in range(N + 1):
		p = k * X % D
		q = k * X // D
		a = k * (k - 1) // 2
		b = (N - 1) * k - a + 1
		s[p].append((a + q, b + q))
	ans = 0
	for v in s.values():
		if not v:
			continue
		v.sort()
		(a, b) = v[0]
		for (x, y) in v[1:]:
			if b < x:
				ans += b - a
				(a, b) = (x, y)
			else:
				b = max(b, y)
		ans += b - a
	return ans
(N, X, D) = map(int, input().split())
print(solve(N, X, D))


import sys
from collections import defaultdict
(N, X, D) = map(int, input().split())
if D == 0:
	print(1 if X == 0 else N + 1)
	sys.exit()
if D < 0:
	X *= -1
	D *= -1
dic = defaultdict(list)
for i in range(N + 1):
	l = X * i + i * (i - 1) // 2 * D
	r = X * i + (N - 1 + N - 1 - (i - 1)) * i // 2 * D
	dic[l % D].append((l // D, r // D + 1))
ans = 0
for v in dic.values():
	v.sort()
	ima = -10 ** 100
	for (l, r) in v:
		if ima < l:
			ans += r - l
			ima = r
		elif r > ima:
			ans += r - ima
			ima = r
print(ans)


INF = 10 ** 30

def solve(n, x, d):
	if d == 0:
		if x == 0:
			return 1
		else:
			return n + 1
	D = {}
	for k in range(n + 1):
		l = k * x + (k - 1) * k // 2 * d
		r = k * x + (n * k - k * (k + 1) // 2) * d
		c = k * x % d
		if not c in D:
			D[c] = []
		l = (l - c) // d
		r = (r - c) // d
		if l > r:
			(l, r) = (r, l)
		D[c].append((l, r))
	res = 0
	for v in D.values():
		threshold = -INF
		for (l, r) in sorted(v):
			l = max(l, threshold)
			res += max(0, r - l + 1)
			threshold = max(threshold, r + 1)
	return res
(n, x, d) = map(int, input().split())
print(solve(n, x, d))


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
(n, x, d) = list(map(int, input().split()))
if d == 0:
	if x == 0:
		ans = 1
	else:
		ans = n + 1
else:
	if d < 0:
		x *= -1
		d *= -1
	D = {}
	for i in range(n + 1):
		if x != 0:
			ii = i * x % d
			jj = (i * x - ii) // d
		else:
			ii = 0
			jj = 0
		if ii not in D:
			D[ii] = []
		D[ii].append((i * (i - 1) // 2 + jj, (2 * n - 1 - i) * i // 2 + jj))
	ans = 0
	for (k, v) in D.items():
		v.sort()
		m = -float('inf')
		val = 0
		for (l, r) in v:
			val += max(r - max(l - 1, m), 0)
			m = max(m, r)
		ans += val
print(ans)


(n, x, d) = map(int, input().split())
mp = {}
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit()
for i in range(n + 1):
	a = i * x
	L = i * (i - 1) // 2
	R = i * (2 * n - i - 1) // 2
	C = a // d
	if mp.get(a % d):
		mp[a % d].append([C + L, C + R])
	else:
		mp[a % d] = [[C + L, C + R]]
inf = float('inf')
ans = 0
for j in mp:
	now = mp[j]
	now.sort()
	pl = -inf
	for (l, r) in now:
		if r <= pl:
			continue
		if l > pl:
			ans += r - l + 1
		else:
			ans += r - pl
		pl = r
print(ans)


import numpy as np
(N, X, D) = map(int, input().split())
if not D:
	if not X:
		print(1)
	else:
		print(N + 1)
else:
	num_dict = dict()
	ans = 0
	for i in range(N + 1):
		left_num = int(i * X / D) + int(i * (i - 1) / 2)
		right_num = int(i * X / D) + int(i * (2 * N - 1 - i) / 2)
		judge_num = i * X % D
		if not judge_num in num_dict:
			num_dict[judge_num] = [(left_num, right_num)]
		else:
			num_dict[judge_num].append((left_num, right_num))
	for (j, k) in num_dict.items():
		new_k = sorted(k)
		L = new_k[0][0]
		R = new_k[0][1]
		for l in new_k:
			if l[0] <= R <= l[1]:
				R = l[1]
			elif R < l[0] and R < l[1]:
				ans += R - L + 1
				(L, R) = (l[0], l[1])
		ans += R - L + 1
	print(ans)


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()
from itertools import groupby

def resolve():
	(n, a, d) = map(int, input().split())
	if d == 0:
		if a == 0:
			print(1)
		else:
			print(n + 1)
		return
	if d < 0:
		(a, d) = (-a, -d)
	A = [None] * (2 * n + 2)
	for k in range(n + 1):
		L = k * a + k * (k - 1) * d // 2
		R = k * a + k * (2 * n - k - 1) * d // 2
		r = L % d
		A[2 * k] = (r, L // d, 0)
		A[2 * k + 1] = (r, R // d, 1)
	A.sort()
	ans = 0
	for (key, iter) in groupby(A, lambda x: x[0]):
		now = 0
		over = 0
		for (r, v, q) in iter:
			if q == 0:
				if not over:
					now = v
				over += 1
			else:
				over -= 1
				if not over:
					ans += v - now + 1
	print(ans)
resolve()


from sys import stdin
input = stdin.buffer.readline
(n, x, d) = map(int, input().split())
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit(0)
m = {}
for i in range(n + 1):
	t = i * x % d
	start = i * x // d
	l = (i - 1) * i // 2
	r = (2 * n - i - 1) * i // 2
	if m.get(t):
		m[t].append([start + l, start + r])
	else:
		m[t] = [[start + l, start + r]]
inf = float('inf')
ans = 0
for x in m:
	now = m[x]
	now.sort()
	pl = -inf
	for (l, r) in now:
		if r <= pl:
			continue
		if l > pl:
			ans += r - l + 1
		else:
			ans += r - pl
		pl = r
print(ans)


from heapq import heappush, heappop
from collections import defaultdict
(N, X, D) = map(int, input().split())
if D == 0:
	if X == 0:
		print(1)
	else:
		print(N + 1)
else:
	s = X * N + D * N * (N - 1) // 2
	h = defaultdict(lambda : [])
	for i in range(N + 1):
		a = X * i + D * i * (i - 1) // 2
		b = X * i + D * i * (2 * N - i - 1) // 2
		m = 2 * a - s
		M = 2 * b - s
		if M < m:
			(m, M) = (M, m)
		heappush(h[m % (abs(D) * 2)], (m, M))
	D = abs(D)
	ret = 0
	for heap in h.values():
		(u, v) = heappop(heap)
		while heap:
			if heap[0][0] <= v:
				v = max(v, heap[0][1])
				heappop(heap)
			else:
				ret += (v - u) // (2 * D) + 1
				(u, v) = heappop(heap)
		ret += (v - u) // (2 * D) + 1
	print(ret)


(N, X, D) = list(map(int, input().split()))
if D == 0:
	if X == 0:
		print(1)
	else:
		print(N + 1)
	exit()
if D < 0:
	D *= -1
	X *= -1
R = {}
R[0] = [[0, 0]]
(d, m, l, r) = (0, 0, 0, 0)
for i in range(N):
	d += (m + X) // D
	m = (m + X) % D
	l += i
	r += N - i - 1
	if m not in R:
		R[m] = [[d + l, d + r]]
	else:
		R[m].append([d + l, d + r])
ans = 0
for i in R:
	t = R[i]
	t.sort()
	(l, r) = t[0]
	for j in range(1, len(t)):
		if r < t[j][0]:
			ans += abs(r - l) + 1
			(l, r) = t[j]
		else:
			r = max(r, t[j][1])
	ans += abs(r - l) + 1
print(ans)


from collections import defaultdict
(n, x, d) = map(int, input().split())
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit()
L = []
C = defaultdict(int)
D = defaultdict(int)
for i in range(n + 1):
	(q, r) = divmod(x * i, d)
	a = i * (i - 1) // 2
	b = i * (2 * n - i - 1) // 2
	a += q
	b += q
	L.append((a, r, 1))
	L.append((b + 1, r, -1))
L.sort()
ans = 0
for (p, idx, b) in L:
	if C[idx] > 0:
		ans += p - D[idx]
	C[idx] += b
	D[idx] = p
print(ans)


def examE():
	(H, W) = LI()
	A = [LI() for _ in range(H)]
	B = [LI() for _ in range(H)]
	dp = [0] * (H * W)
	cur = abs(A[0][0] - B[0][0])
	dp[0] |= 1 << cur
	for i in range(H):
		for j in range(W):
			now = dp[i * W + j]
			if i < H - 1:
				cur = abs(A[i + 1][j] - B[i + 1][j])
				ni = now << cur | now >> cur
				ex = 0
				for k in range(1, cur + 1):
					if now >> k & 1:
						ex |= 1 << cur - k
				dp[(i + 1) * W + j] |= ni | ex
			if j < W - 1:
				cur = abs(A[i][j + 1] - B[i][j + 1])
				ni = now << cur | now >> cur
				ex = 0
				for k in range(1, cur + 1):
					if now >> k & 1:
						ex |= 1 << cur - k
				dp[i * W + j + 1] |= ni | ex
	ans = inf
	for (i, f) in enumerate(str(bin(dp[-1]))[::-1]):
		if f == '1':
			ans = i
			break
	print(ans)
	return

def examF():
	(N, X, D) = LI()
	if D == 0:
		ans = N + 1
		if X == 0:
			ans = 1
		print(ans)
		return
	if D < 0:
		(X, D) = (-X, -D)
	S = defaultdict(list)
	for i in range(N + 1):
		base = X * i % D
		start = X * i // D + i * (i - 1) // 2
		end = X * i // D + i * (N - 1 + N - i) // 2
		S[base].append([start, end])
	ans = 0
	for d in S.values():
		d.sort()
		(L, R) = d[0]
		if len(d) == 1:
			ans += R - L + 1
			continue
		for (l, r) in d[1:]:
			if r <= R:
				continue
			if R < l:
				ans += R - L + 1
				(L, R) = (l, r)
			elif R < r:
				R = r
		ans += R - L + 1
	print(ans)
	return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
alphabet = [chr(ord('a') + i) for i in range(26)]
examF()


import sys
from collections import defaultdict
INF = float('inf')

def solve(N: int, X: int, D: int):
	if D == 0:
		if X == 0:
			print(1)
		else:
			print(N + 1)
		return
	if D < 0:
		X = X + (N - 1) * D
		D = abs(D)
	segs = defaultdict(list)
	for k in range(N + 1):
		L = k * (k - 1) // 2
		R = k * N - k * (k + 1) // 2
		Ck = k * X + D * L
		Rk = R - L
		seg = (Ck // D, Ck // D + Rk + 1)
		s = Ck % D
		segs[s].append(seg)
	tot = 0
	for k in segs:
		event = defaultdict(int)
		for (l, r) in segs[k]:
			event[l] += 1
			event[r] -= 1
		curr = 0
		pre = -1
		for k in sorted(event.keys()):
			if curr > 0:
				tot += k - pre
			curr += event[k]
			pre = k
	print(tot)
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	X = int(next(tokens))
	D = int(next(tokens))
	solve(N, X, D)

def __starting_point():
	main()
__starting_point()


def main():
	import sys
	from collections import defaultdict
	input = sys.stdin.readline
	(N, x, d) = map(int, input().split())
	if d == 0:
		if x:
			print(N + 1)
		else:
			print(1)
		exit()
	if d < 0:
		x = x + d * (N - 1)
		d *= -1
	dic = defaultdict(list)
	for i in range(N + 1):
		mod = x * i % d
		st = i * (i + 1) // 2
		ed = i * (N + N - i + 1) // 2
		st = st * d + (x - d) * i
		ed = ed * d + (x - d) * i
		dic[mod].append((st, ed))
	ans = 0
	for mod in dic:
		L = dic[mod]
		L.sort(key=lambda t: t[0])
		ed_prev = L[0][0] - 1
		for (st, ed) in L:
			if st > ed_prev:
				ans += (ed - st) // d + 1
				ed_prev = ed
			elif ed > ed_prev:
				ans += (ed - ed_prev) // d
				ed_prev = ed
	print(ans)
main()


(n, x, d) = map(int, input().split())
if d == 0:
	if x == 0:
		print(1)
	else:
		print(n + 1)
	exit()
node = []
for i in range(n + 1):
	j = n - i
	base = x * (i - j)
	base += 2 * d * (i - 1) * i // 2
	right = (n - i) * i
	if d < 0:
		base += 2 * d * right
	node.append((base, right))
node.sort()
d = abs(d)
di = {}
mod = 2 * d
ans = 0
for (base, r) in node:
	i = base % mod
	if i in di:
		right_most = di[i]
		if right_most < base:
			ans += r + 1
			di[i] = base + 2 * d * r
		elif base + 2 * d * r <= right_most:
			continue
		else:
			nxt = base + 2 * d * r
			ans += (nxt - right_most) // mod
			di[i] = nxt
	else:
		ans += r + 1
		di[i] = base + 2 * d * r
print(ans)


from operator import itemgetter
(n, x, d) = map(int, input().split())
a = [0] * n
for i in range(n - 1):
	a[i + 1] = a[i] + 1
ruiseki1 = [0] * (n + 1)
ruiseki2 = [0] * (n + 1)
for i in range(n):
	ruiseki1[i + 1] += ruiseki1[i] + a[i]
for i in range(n):
	ruiseki2[i + 1] += ruiseki2[i] + a[n - i - 1]
if d == 0 and x == 0:
	print(1)
	exit()
elif d == 0:
	print(n + 1)
	exit()
memo = {}
for i in range(n + 1):
	s_cnt = i
	geta = i * x
	div = geta // d
	mod = geta % d
	min_ = ruiseki1[i]
	max_ = ruiseki2[i]
	if mod not in memo:
		memo[mod] = []
	memo[mod].append((min_ + div, max_ + div + 1))
ans = 0
for i in memo:
	memo[i] = sorted(memo[i])
	r_max = -10 ** 18
	for j in memo[i]:
		(l, r) = j
		if r - r_max < 0:
			continue
		ans += min(r - l, r - r_max)
		r_max = r
print(ans)


from collections import defaultdict
(N, X, D) = map(int, input().split())
d = defaultdict(list)
if D < 0:
	D *= -1
	X *= -1
if D != 0:
	for m in range(N + 1):
		a = X * m + m * (m - 1) * D // 2
		b = X * m + m * (2 * N - m - 1) * D // 2
		d[a % D].append([a, b])
	ans = 0
	for k in d:
		q = d[k]
		q.sort()
		(l, r) = q[0]
		for i in range(len(q)):
			(a, b) = q[i]
			if a <= r:
				r = max(r, b)
			else:
				ans += (r - l) // D + 1
				l = a
				r = b
		ans += (r - l) // D + 1
if D == 0:
	ans = N + 1
	if X == 0:
		ans = 1
print(ans)