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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: i64,
        mut x: i64, mut d: i64,
    }
    if d == 0 {
        if x == 0 {
            println!("0");
        } else {
            println!("{}", n + 1);
        }
        return;
    }
    if d < 0 {
        d = -d;
        x = -x;
    }
    let m = |x| (x % d + d) % d;
    let div = |x| if x >= 0 { x / d } else { (x - 1) / d };

    let mut map = std::collections::BTreeMap::new();
    let mut insert = |x, c| {
        let r = map.entry(m(x)).or_insert(std::collections::BTreeMap::new());
        *r.entry(div(x)).or_insert(0) += 1;
        *r.entry(div(x) + c).or_insert(0) -= 1;
    };
    insert(0, 1);

    let mut s = 0;
    let mut s_bk = 0;
    for k in 1..=n {
        s += k - 1;
        s_bk += n - k;
        let c = k * x + d * s;
        let r = s_bk - s;
        insert(c, r + 1);
    }

    let mut res = 0;
    for (_, m) in map {
        let mut l = 0;
        let mut c = 0;
        for (i, j) in &m {
            if c == 0 {
                l = *i;
                c += *j;
            } else {
                c += *j;
                if c == 0 {
                    res += i - l;
                }
            }
        }
    }
    println!("{}", res);
}
*/

fn main() {
    let exe = "/tmp/bin1956A957";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";