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 Rust (1.15.1) (judge verdict: Runtime Error)

#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:usize = sc.read();
    let mut X:i64 = sc.read();
    let mut D:i64 = sc.read();
    if D == 0{
        if X == 0{
            println!("1");
        }else{
            println!("{}", N+1);
        }
    }
    if D < 0{
        X = -X;
        D = -D;
    }
    let mut map = std::collections::BTreeMap::<i64, Vec<(i64, i64)>>::new();
    for k in 0..(N+1){
        let t = k as i64;
        let tX = X*t;
        let minimum = tX/D + t*(t-1)/2;
        let maximum = tX/D + ((N as i64)*t - t*(t+1)/2);
//        println!("{} {} tX{} {} {}",N ,t ,tX/D,t*(t+1)/2 , ((N as i64)*t - t*(t+1)/2));
        let corresponding_vector = map.entry(tX%D).or_insert(vec![]);
        corresponding_vector.push((minimum, maximum));
    }

    let mut ans = 0;
    for (_,a) in map{
        let mut a = a;
        a.sort();
        let mut first = a[0].0;
        let mut second = a[0].1;
        for i in 1..a.len(){
//            println!("{} {}", a[i].0, a[i].1);
            if second < a[i].0{
                ans += second - first + 1;
                first = a[i].0;
                second = a[i].1;
            }else{
                second = a[i].1;
            }
        }
        ans += second - first + 1;
    }

    println!("{}", ans);

}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}