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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static class Range implements Comparable<Range>{
		long low;
		long high;
		public Range(long l , long h) {
			low =  Math.min(l, h);
			high = Math.max(l, h);
		}
		@Override
		public String toString() {
			return low + ":" + high;
		}
		@Override
		public int compareTo(Range o) {
			int c = Long.compare(low, o.low);
			if(c == 0) {
				return Long.compare(high, o.high);
			}
			return c;
		}
	}
	static long solve(int N , long X , long D) {
		if(D == 0) {
			return X != 0 ? N + 1: 0;
		}
		if(D < 0) {
			return solve(N , - X , - D);
		}
		Map<Long, List<Range>> ranges = new HashMap<Long, List<Range>>();
		for(long k = 0 ; k <= N ; ++k) {
			long low = (k - 1) * k / 2;
			long high = k * (- 1 + 2 * N - k) / 2;
			long m = (k * X) % D;
			if(!ranges.containsKey(m)) {
				List<Range> lst = new ArrayList<Range>();
				ranges.put(m, lst);
			}
			List<Range> lst = ranges.get(m);
			lst.add(new Range(low * D + k * X, high * D + k * X));
		}
		long S = 0;
		for(long k : ranges.keySet()) {
			List<Range> lst = ranges.get(k);
			Collections.sort(lst);
			Range cur = lst.get(0);
			for(int i = 1 ; i < lst.size() ; ++i) {
				Range li = lst.get(i);
				if(cur.high < li.low) {
					S += (cur.high - cur.low + D) / D;
					cur = li;
				}else {
					cur.high = li.high;
				}
			}
			S += (cur.high - cur.low + D) / D;
		}
		return S;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long X = sc.nextLong();
		long D = sc.nextLong();
		System.out.println(solve(N , X , D));
	}
}