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>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  long long x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[200101];
int l[631010];
int j[200102];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[1];
queue<int> q;

//stack<int> s;
set<int> s;
map<int,int> p;
vector<P> v[200101];

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

long long f(long long n,long long m)
{
  if(m<n) return 0;
  long long x=(n+m)*(m-n+1)/2;
  return x*c;
}

int main()
{
  scanf("%d %d %d",&a,&b,&c);
  d=abs(2*c);
  for(int t=0;t<=a;t++)
  {
    y=t*b-(a-t)*b;
    int i;
    if(p[(y%d+d)%d]) i=p[(y%d+d)%d];
    else e++,p[(y%d+d)%d]=i=e;
    v[i].push_back({y-f(t,a-1)+f(0,t-1),y+f(a-t,a-1)-f(0,a-t-1)});
    if(v[i].back().x>v[i].back().y) swap(v[i][v[i].size()-1].x,v[i][v[i].size()-1].y);
    //printf("%lld %lld\n",v[i].back().x,v[i].back().y);
  }
  for(int t=1;t<=e;t++)
  {
    sort(v[t].begin(),v[t].end(),as);
    z=v[t][0].x-1;
    //x++;
    for(int i=0;i<v[t].size();i++)
    if(z<v[t][i].y)
    {
      if(z>=v[t][i].x)x+=abs((v[t][i].y-z)/(2*c));
      else x+=abs((v[t][i].y-v[t][i].x)/(2*c))+1;
      z=v[t][i].y;
    }
  }
  printf("%lld",x);
}