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: Memory Limit Exceeded)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        x: isize,
        d: isize,
    }

    if d == 0 {
        println!("{}", if x == 0 { 1 } else { n + 1 });
        return;
    }

    let (x, d): (isize, usize) = if d < 0 {
        (-x, (-d) as usize)
    } else {
        (x, d as usize)
    };
    let xm = ((x % (d as isize) + d as isize) as usize) % d;
    let mut ds = vec![vec![]; d as usize];
    let lef: Vec<i64> = vec![0]
        .into_iter()
        .chain((0..n).scan(0i64, |s, x| {
            *s += x as i64;
            Some(*s)
        }))
        .collect();
    let rig: Vec<i64> = vec![0]
        .into_iter()
        .chain((0..n).scan(0i64, |s, x| {
            *s += (n - x - 1) as i64;
            Some(*s)
        }))
        .collect();
    let mo: Vec<usize> = (0..n + 1)
        .scan(0, |s, _| {
            *s = (*s + xm) % d;
            Some(*s)
        })
        .collect();
    for k in 0..n + 1 {
        let z = (k as i64) * (x as i64) / (d as i64);
        ds[mo[k]].push((z + lef[k], z + rig[k]));
    }

    let mut res = 0i64;
    for k in 0..d {
        ds[k].sort();
        if ds[k].len() > 0 {
            let mut r = ds[k][0].1;
            res += ds[k][0].1 - ds[k][0].0 + 1;
            for (lf, rg) in ds[k][1..].iter() {
                if r < *lf {
                    r = *rg;
                    res += *rg - *lf + 1;
                } else if r < *rg {
                    res += *rg - r;
                    r = *rg;
                }
            }
        }
    }

    println!("{}", res);
}

*/

fn main() {
    let exe = "./binXXXXXX";
    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>";