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>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (s).begin(), (s).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<=(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define vi vector<int>
#define vvi vector<vector<int> >
#define vb vector<bool>
using namespace std;
typedef unsigned long long int ll;
const int Mod = 1e9 + 7;
const int max_n = 3 * 1e5 + 1;
const ll INF = 1e9;
long double INFD = 100100100;
const int half = INF / 2;

//______ templates
inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

//___________following sorce code______________________
int N,X,D;
void input(){
  IN(N, X, D);
}

int abs (int a){
  return a < 0 ? -a : a;
}

int getsum(void){
  int a = X + X + D*(N-1);
  a /= 2;
  int sum = a*N;
  return sum;
}
void solve(){
  input();
  if(D==0)
  {
    OUT(N+1);
    return;
  }
  if(D < 0)
  {
    D = abs(D);
    X = - X;
  }
  int sum = getsum();
  //dump(sum);
  vb v(INF,0);
  rep(i, N+1){
    int l = i*(i-1)/2;
    int r = (2*N - i - 1)*i / 2;
    int x = i*X;
    //dump(i);dump(l);dump(r);dump(x);
    repk(j, l, r){
      v[half+x+j*D] = 1;
      //cout << j<< "a" << " ";
    }
    //cout << endl;
  }
  int ans = 0;
  for(auto c : v){
    if(c){
      ans++;
    }
  } 
  OUT(ans);
}
int main (){
    solve();
    return 0;
}