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: Wrong Answer)

fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    use std::collections::HashMap;
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: i64 = scan(tokens);
    let x: i64 = scan(tokens);
    let d: i64 = scan(tokens);
    if d == 0 {
        if x == 0 {
            println!("{}", 0);
        } else {
            println!("{}", n + 1);
        }
        return;
    }
    let (x, d) = if d < 0 { (-x, -d) } else { (x, d) };
    let mut intervals = HashMap::new();
    for k in 0..n + 1 {
        let a = k * x + k * (k - 1) / 2 * d;
        let b = k * x + (n * (n - 1) / 2 - (n - k) * (n - k - 1) / 2 + 1) * d;
        let mut m = k * x % d;
        if m < 0 {
            m += d;
        }
        intervals.entry(m).or_insert_with(Vec::new).push((a, b));
    }
    let mut ans = 0;
    for v in intervals.values_mut() {
        v.sort();
        let mut x = std::i64::MIN;
        let mut y = std::i64::MIN;
        for &(a, b) in v.iter() {
            if y < a {
                ans += (y - x) / d;
                x = a;
                y = b;
            } else {
                x = std::cmp::min(x, a);
                y = std::cmp::max(y, b);
            }
        }
        ans += (y - x) / d;
    }
    println!("{}", ans);
}