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)

/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<ll, ll> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
ll x, d;
map<ll, vector<II> > ma;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> x >> d;
    if (d == 0) {
        if (x == 0) cout << 1;
        else cout << n+1;
        return 0;
    }
    if (d < 0) {
        x = -x;
        d = -d;
    }
    ll l = 0, r = 0;
    ma[0].push_back(II(0,0));

    FOR(k,1,n) {
        ll p = x * k % d;
        ll w = x * k / d;
        l += k-1;
        r += n-k;
        // cout << p << ' ' << l << ' ' << r << endl;
        if (l > r) continue;
        ma[p].push_back(II(l + w, r + w));
    }
    ll res = 0;
    FORALL(it, ma) {
        sort(ALL(it->SE));
        ll l = -1, r = -1;
        FOR(i,0,SZ(it->SE)-1) {
            if (r < it->SE[i].FI) {
                if (r != -1) res += (r - l + 1);
                l = it->SE[i].FI;
            }
            r = max(r, it->SE[i].SE);
        }
        if (r != -1) res += (r - l + 1);
    }
    cout << res;
    return 0;
}