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;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, X, D;
    cin >> N >> X >> D;

    if(X == 0){
    	cout << (N-1)*N/2 + 1 << endl;
    }
    if(D<0){
    	X = X + (N-1)*D;
    	D = -D;
    }
   	vector<pll> ps[202020];
    map<ll, ll> mp;
    ll idx = 0;
    ll lb = 0, ub = 0;
    REP(k, N+1){
    	ll L = k*X + lb*D;
    	ll R = k*X + ub*D;
    	if(mp.find((k*X)%D) == mp.end()){
    		mp[(k*X)%D] = idx;
  			ps[idx].push_back({L, R});
    		idx++;
    	}else{
    		ps[mp[(k*X)%D]].push_back({L, R});
    	}
    	lb += k;
    	ub += (N-1-k);
    }

    //cout << ps[0] << endl;

    ll res = 0;
    REP(i, idx){
    	sort(ps[i].begin(), ps[i].end());
    	ll left = -(1ll<<60);
    	ll right = -(1ll<<60);
    	REP(j, ps[i].size()){
    		if(ps[i][j].first>right){
    			if(j>0) res += ((right-left)/D + 1);
    			left = ps[i][j].first;
    			right = ps[i][j].second;
    		}else{
    			right = max(right, ps[i][j].second);
    		}
    		//dump(res)
    	}
    	res += ((right-left)/D + 1);
    }

    cout << res << endl;
    return 0;
}