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: Accepted)

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll N,X,D;
	scan(N>>X>>D);
	ll ans=0;
	map<ll,vpll> kXkukan;
	if(D==0){
		if(X==0) prin(1);
		else prin(N+1);
	}
	else{
		if(D<0){
			X=-X;
			D=-D;
		}
		rep(k,N+1){
			ll mini=k*X+(ll)k*(k-1)*D/2;
			ll maxi=k*X+(ll)k*(2*N-k-1)*D/2;
			kXkukan[((k*X)%D+D)%D].push_back({mini,maxi});
		}
		for(auto K:kXkukan){
			vpll V=K.second;
			ll nowmax=-INFl;
			sort(ALL(V));
			rep(j,V.size()){
				if(V[j].first>nowmax){
					ans+=(V[j].second-V[j].first)/D+1;
					nowmax=V[j].second;
				}
				else if(V[j].second>nowmax){
					ans+=(V[j].second-nowmax)/D;
					nowmax=V[j].second;
				}
				//printf("amari:%lld f:%lld s:%lld ans:%lld\n",K.first,V[j].first,V[j].second,ans);

			}
		}
		prin(ans);
	}
	return 0;
}