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: Runtime Error)

// Java program to print distinct 
// subset sums of a given array. 
import java.io.*; 
import java.util.*; 

public class Main{ 

	// Uses Dynamic Programming to 
	// find distinct subset sums 
	static int printDistSum(int arr[], int n) 
	{ 
		int sum = 0; 
		for (int i = 0; i < n; i++) 
			sum += arr[i]; 

		// dp[i][j] would be true if arr[0..i-1] 
		// has a subset with sum equal to j. 
		boolean[][] dp = new boolean[n + 1][sum + 1]; 

		// There is always a subset with 0 sum 
		for (int i = 0; i <= n; i++) 
			dp[i][0] = true; 

		// Fill dp[][] in bottom up manner 
		for (int i = 1; i <= n; i++) 
		{ 
			dp[i][arr[i - 1]] = true; 
			for (int j = 1; j <= sum; j++) 
			{ 
				// Sums that were achievable 
				// without current array element 
				if (dp[i - 1][j] == true) 
				{ 
					dp[i][j] = true; 
					dp[i][j + arr[i - 1]] = true; 
				} 
			} 
		} 
		int c=0;
		// Print last row elements 
		for (int j = 0; j <= sum; j++) 
			if (dp[n][j] == true) 
				c++;
      
      return c;
	} 

		// Driver code 
	public static void main(String[] args) 
	{ 
      Scanner s=new Scanner(System.in);
      	int n=s.nextInt();
      int x=s.nextInt();
      int d=s.nextInt();
		int arr[] = new int[n]; 
		//int n = arr.length; 
			
      
      arr[0]=x;
      for(int i=1;i<n;i++)
        arr[i]=arr[i-1]+d;
      
      System.out.println(printDistSum(arr, n)); 
	} 
}