Problem p02840 - Generation 2

Orig Description

Score : 600 points
Problem StatementWe 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.
InputInput is given from Standard Input in the following format:
N X D
OutputPrint the number of possible values of S - T.
Sample Input 13 4 2
Sample Output 18
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 22 3 -3
Sample Output 22
A is (3, 0). There are two possible values of S - T: -3 and 3.
Sample Input 3100 14 20
Sample Output 349805

Extracted Specification

An integer N (1 ≤ N ≤ 2 × 10^5), representing some quantity or size.
An integer X (-10^8 ≤ X ≤ 10^8), representing a value.
An integer D (-10^8 ≤ D ≤ 10^8), representing a difference.

### Example Input:

```
3
4
2
```

### Function Signature:
Write a function f(N, X, D) that takes in the input. 
def f(N: int, X: int, D: int): 
    ''' 
    N: an integer 
    X: an integer
    D: an integer
    '''

Test Case Generator

Certainly! Here is a test case generator for the given problem statement:

```python
import random

def tcgen():
    # Generate values for N, X, D with the given constraints
    N = random.randint(1, 2 * 10**5)
    X = random.randint(-10**8, 10**8)
    D = random.randint(-10**8, 10**8)
    
    return N, X, D

# Generate a test case and print it
N, X, D = tcgen()
print(N, X, D)
```

This function generates random values for \(N\), \(X\), and \(D\) within the specified constraints of the problem. Each time you run it, you will get a new test case with different values of \(N\), \(X\), and \(D\).

For example, if you want to generate and display test cases, you can simply call this function multiple times:

```python
for _ in range(5):  # Generate 5 test cases
    N, X, D = tcgen()
    print(f'Test Case - N: {N}, X: {X}, D: {D}')
```

This will give you different test cases each time you run it.

Extract Arguments

def extract_arguments(fh):
    N, X, D = map(int, fh.readline().strip().split())
    return N, X, D