Problem:
Score : 600 points

Problem Statement

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 1

3 4 2

Sample Output 1

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.

Sample Input 2

2 3 -3

Sample Output 2

2

A is (3, 0). There are two possible values of S - T: -3 and 3.

Sample Input 3

100 14 20

Sample Output 3

49805

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
const int N=2e5+10;
struct node{
	ll l,r;
	bool operator < (const node &x)const{
		return l<x.l;
	}
	node(ll a=0,ll b=0){l=a,r=b;}
};
map<ll,vector<node> >s;
ll n,x,d;
ll f(ll l,ll r){
	if(l>r)return 0;
	return (l+r)*(r-l+1)/2;
}
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%lld%lld%lld",&n,&x,&d);
	if(x==0&&d==0){
		puts("1");return 0;
	}
	if(x==0&&d!=0){
		printf("%lld\n",n*(n-1)/2+1);return 0;
	}
	if(x!=0&&d==0){
		printf("%lld\n",n);return 0;
	}
	if(d<0)d*=-1,x*=-1;
	ll L=0,R=0;
	for(ll i=0;i<=n;i++){
		ll t=i*x;
		L=f(1,i-1);
		R=f(n-i,n-1);
		L+=t/d,R+=t/d;
		t%=d;
		if(t<0)t+=d,L--,R--;
		s[t].push_back(node(L,R));
	}
	ll ans=0;
	for(ll i=0;i<d;i++){
		if(s[i].size()==0)continue;
		sort(s[i].begin(),s[i].end());
		L=s[i][0].l,R=s[i][0].r;
		for(node v:s[i]){
			if(v.l>R){
				ans+=R-L+1;
				L=v.l,R=v.r;
			}
			else{
				R=max(v.r,R);
			}	
		}
		ans+=R-L+1;
	}
	printf("%lld\n",ans);
	return 0;
}