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 <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsinged long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
const int inf=1039074182;
using namespace std;
int x,d;
int n;
ll l[200005];
ll r[200005];

ll sumrange(int l,int r)
{
	return 1LL*(l+r)*(r-l+1)/2;
}

ll same(ll l1,ll r1,ll l2,ll r2,ll k)
{
	l1+=k;
	r1+=k;
	l1=max(l1,l2);
	r1=min(r1,r2);
	if(l1>r1) return 0;
	return (r1-l1+1);
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>x>>d;
	ll res=0;
	for(int i=0;i<=n;i++)
	{
		l[i]=sumrange(0,0+i-1);
		r[i]=sumrange(n-1-i+1,n-1);
		if(x==0) l[i]=r[i]=0;
		res+=r[i]-l[i]+1;
	}
	int bx,bd;
	if(x==0)
	{
		bx=1;
		bd=0;
	}
	else
	{
		int g=__gcd(x,d);
		bx=d/g;
		bd=x/g;
	}
	
	if(bx<0)
	{
		bx=-bx;
		bd=-bd;
	}
	bd=-bd;
	for(int i=0;i<=n;i++)
	{
		if(i+bx>n) break;
		res-=same(l[i],r[i],l[i+bx],r[i+bx],bd);
	}
	cout<<res<<endl;
	return 0;
}