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 <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<ll, ll>;
const int mod = 1000000007;
const ll INF = 1001001001001;


int main(){
    ll n, x, d;
    cin >> n >> x >> d;
    
    if (d==0) {
        if (x==0) {
            cout << "1" << endl;
        }
        else {
            cout << n+1 << endl;
        }
        return 0;
    }
    
    if (d<0) {
        x = -x;
        d = -d;
    }

    map<ll, vector<P>> mp;
    for (ll i=0; i<=n; i++) {
        ll s = x * i;
        ll l = d*(i*(i-1)/2);
        ll r = d*((n*(n-1))/2-(n-i)*(n-i-1)/2);
        mp[s%d].emplace_back(s+l, s+r+d);
    }

    ll ans = 0;
    for (auto m: mp) {
        vector<P> ev;
        for (auto e: m.second) {
            ev.emplace_back(e.first, 1);
            ev.emplace_back(e.second, -1);
        }
        sort(ev.begin(), ev.end());
        ll cnt = 0;
        ll pre = -INF;
        for (auto p: ev) {
            if (cnt) ans += (p.first-pre)/d;
            cnt += p.second;
            pre = p.first;
        }
    }
    cout << ans << endl;
    
    /*
    vector<pair<ll, ll>> data(n+1);
    rep(i, n+1) {
        data[i].first = (i*x)%d;
        data[i].second = i*x;
    }
    sort(data.begin(), data.end());
    
    ll max = -INF;
    ll min = INF;
    
    rep(i, n+1) {
        ll v1 = (i*(i-1))/2;
        ll v2 = ((n-1)*n)/2 - ((n-i)*(n-i-1))/2;
        ll w1 = i*x + v1*d;
        ll w2 = i*x + v2*d;
        cout << w1 << " " << w2 << endl;
        if (i==0 || data[i].first!=data[i-1].first) {
            ans += v2 - v1 + 1;
            max = -INF;
            min = INF;
        }
        else {
            if (w1>max || w2<min) {
                ans += v2 - v1 + 1;
            }
            else {
                if (w2>max) {
                    ans += (w2-max)/d;
                }
            }
        }
        if (w1<min) w1 = min;
        if (w2>max) w2 = max;
    }
    
    cout << ans << endl;
    */
    return 0;
}