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: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e8;
typedef long long ll;
ll mod = 1e9+7;
long long fast_exp(long long a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
    }
}
const ll N = 1e6;


int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll n,x,d;
	cin>>n>>x>>d;
	ll g = __gcd(x,d);
	x = x/g , d = d/g;
	if(x == 0  && d == 0)
	{
		cout<<1<<endl;
		return 0;
	}
	if(d == 0)
	{
		cout<<n+1<<endl;
		return 0;
	}
	if(d < 0)
	{
		d = -d;
		x = -x;
	}
	map<ll,vector<pair<ll,ll>>> range;
	set <ll> modulos;
	modulos.insert(0);
	range[0].pb(mp(0,0));
	for(ll i = 0; i<n ; i++)
	{
		pair<ll,ll> p;
		ll beg = (i+1)*x + ((i*(i+1))/2)*d;
		ll shift = (i+1)*(n-(i+1))*d;
		p = mp(beg,beg+shift);
		range[beg%d].pb(p);
		modulos.insert(beg%d);
	}

	ll cnt = 0;
	for(auto itr : modulos)
	{
		//cout<<"itr: "<<itr<<endl;
		//cout<<"range[itr] : \n";
		sort(range[itr].begin(),range[itr].end());
		// for(auto e: range[itr])
		// {	
		// 	cout<<"hey\n";
		// 	cout<<e.ff<<' '<<e.ss<<"     ";	
		// }
		ll curl = range[itr][0].ff , curr = range[itr][0].ss;
		for(ll i = 0; i<range[itr].size(); i++)
		{
			ll l = range[itr][i].ff , r = range[itr][i].ss;
			if(l<=curr)
			{
				curr = max(r,curr);
			}
			else
			{
				//cout<<"mooo\n";
				cnt+= abs((curr-curl)/d) + 1;
				curr = r;
				curl = l;

			}

			if(i == range[itr].size()-1)
			{
				//cout<<"here\n";
				cnt+= abs((curr-curl)/d) + 1;
			}
		}
	}

	cout<<cnt<<endl;
	return 0;
	
}