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)

use std::cmp::{max, min};
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: i64, mut x: i64, mut d: i64);
    if d == 0 {
        if x == 0 {
            println!("{}", 1);
        } else {
            println!("{}", n);
        }
    } else {
        if d < 0 {
            x = -x;
            d = -d;
        }
        let mut ranges = std::collections::HashMap::<i64, Vec<std::ops::Range<i64>>>::new();
        for k in 0..(n + 1) {
            let r = k * x % d;
            let low = k * x / d + k * (k - 1) / 2;
            let high = k * x / d + (n * k - k * (k + 1) / 2) + 1;
            // println!("{:?}", (low, high)); // DEBUG
            ranges.entry(r).or_insert(Vec::new()).push(low..high);
        }
        for v in ranges.values_mut() {
            v.sort_by(|x, y| x.start.cmp(&y.start));
            let mut newv: Vec<std::ops::Range<i64>> = vec![];
            for vi in v.iter() {
                if newv.len() > 0 {
                    let last = newv.last_mut().unwrap().clone();
                    if last.end < vi.start {
                        newv.push(vi.clone());
                    } else {
                        newv.pop();
                        newv.push(last.start..vi.end);
                    }
                } else {
                    newv.push(vi.clone());
                }
            }
            std::mem::swap(v, &mut newv);
        }

        let mut ret = 0;
        for v in ranges.values() {
            for range in v {
                ret += range.end - range.start;
            }
        }
        println!("{}", ret);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}