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<map>
using namespace std;


long long myMod(long long v, long long mod) {
    if (v < 0) {
        return (mod - llabs(v) % mod) % mod;
    } else {
        return v % mod;
    }
}


long long N, X, D;

void read() {
    cin >> N >> X >> D;
}


void work() {
    if (D == 0) {
        cout << (X == 0 ? 1 : N + 1) << endl;
        return;
    }
    
    if (D < 0) {
        X += (N - 1) * D;
        D *= -1;
    }

    
    long long ans = 1;
    // long long preMinV = N * X + N * (N - 1) / 2 * D;
    //long long preMaxV = N * X + N * (N - 1) / 2 * D;

    long long curMinV = N * X + N * (N - 1) / 2 * D;
    long long curMaxV = N * X + N * (N - 1) / 2 * D;
    long long subtMinD = X + (N - 1) * D;
    long long subtMaxD = X;
    
    long long fstMinV = N * X + N * (N - 1) / 2 * D;
    map<long long, long long> mod2minV;
    mod2minV[myMod(fstMinV, 2 * D)] = fstMinV;
    
    for (int i = 0; i < N; ++i) {
        curMinV -= subtMinD * 2;
        curMaxV -= subtMaxD * 2;

        // cout << curMinV << " - " << curMaxV << ' ' << subtMinD << ' ' << subtMaxD << endl;
        if (mod2minV.count(myMod(curMinV, 2 * D)) && mod2minV[myMod(curMinV, 2 * D)] <= curMaxV) {
            long long preMinV = mod2minV[myMod(curMinV, 2 * D)];
            ans += (preMinV - curMinV) / (2 * D);
        } else {
            ans += (curMaxV - curMinV) / (2 * D) + 1;
        }
        mod2minV[myMod(curMinV, 2 * D)] = curMinV;
        
        subtMinD -= D;
        subtMaxD += D;

        //preMinV = curMinV;
        //preMaxV = curMaxV;
    }

    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}