Problem p02163 - Generation 2

Orig Description

Problem B: How old are you
Problem
A suspicious magician seems to be performing magic.
"Now, please think of your favorite integer."
You decided to think of your age in your head.
The magician throws a query $N$ times.
Each query is one of the following.
"Please multiply the number you are thinking of now by $x$."
"Please add $x$ to the number you are thinking of now."
"Please subtract $x$ from the number you are thinking of now."
For each query, process the query for the number you are thinking of, and think of the resulting value in your head.
"Now, let me guess the number you first thought of." 
The magician is trying to say something.
However, he seems to have forgotten what to say.
The suspicious magician is staring at you with sweat.
There's no way around it, so let's tell him what to say.
The magician was planning to say the following at the end.
"If you add $A$ to the integer you are thinking of now, and divide it by $B$, it will be the integer you first thought of."
By constraint, there is only one set of integers $(A,B)$ that satisfies the above condition, regardless of the number of integers thought of.
Find the set of integers $(A,B)$.
However, $B$ must not be $0$.
Input
The input is given in the following format.
$N$
$q_1$ $x_1$
$\vdots$
$q_n$ $x_n$
The number of queries $N$ to be performed is given on the first line.
From the second line, information about the query is given for each $N$ lines.
$q$ represents the type of query and corresponds to the numbers in the list in the problem statement.
Constraints
The input satisfies the following conditions.
$1 \leq N \leq 15 $
$1 \leq q \leq 3 $
$1 \leq x \leq 10 $
All input values are integers.
Output
Output the integers $A$ and $B$ that satisfy the condition on a single line separated by a space.
Sample Input 1
3
1 2
2 10
3 8
Sample Output 1
-2 2
Sample Input 2
10
1 10
1 10
1 10
1 10
1 10
1 10
1 10
1 10
1 10
1 10
Sample Output 2
0 10000000000
Note that the answer may not fit in a 32-bit integer type.

Extracted Specification

An integer N (1 ≤ N ≤ 15), representing some quantity or size.
A list of N pairs of integers. Each pair consists of an integer q (1 ≤ q ≤ 3) and an integer x (1 ≤ x ≤ 10).

### Example Input:

```
3
1 2
2 10
3 8
```

### Function Signature:
Write a function f(N, queries) that takes in the input.
```python
def f(N: int, queries: List[Tuple[int, int]]):
    '''
    N: an integer
    queries: a list of tuples, each containing two integers
    '''
```

Test Case Generator

To generate test cases for the problem "How old are you," we need to create various combinations of the magician's queries and the values involved in those queries. Below is a test case generator in Python for this problem:

```python
import random

def tcgen():
    # Number of queries - N
    N = random.randint(1, 15)
    
    # List to store queries
    queries = []
    
    for _ in range(N):
        # Randomly choose a query type (1, 2, or 3)
        q = random.randint(1, 3)
        # Randomly choose a value for x (1 to 10)
        x = random.randint(1, 10)
        # Append the query in the form of (q, x)
        queries.append((q, x))
    
    # Return N and the list of queries
    return N, queries

# Example usage:
N, queries = tcgen()
print(N)
for query in queries:
    print(query[0], query[1])
```

This test case generator creates:
1. A random number of queries \( N \) between 1 and 15.
2. Each query is randomly chosen from the set {1, 2, 3} (representing multiplication, addition, and subtraction operations respectively).
3. Each query value \( x \) is randomly chosen between 1 and 10.

Here is an example of how the output might look when you run the generator:

```plaintext
7
3 6
2 7
2 4
3 9
1 2
1 5
2 4
```

This represents 7 queries where:
- The first query is "subtract 6".
- The second query is "add 7".
- The third query is "add 4".
- The fourth query is "subtract 9".
- The fifth query is "multiply by 2".
- The sixth query is "multiply by 5".
- The seventh query is "add 4".

You can run the test case generator multiple times to get different sets of test cases for comprehensive testing.

Extract Arguments

def extract_arguments(fh):
    N = int(fh.readline().strip())
    queries = []
    for _ in range(N):
        q, x = map(int, fh.readline().strip().split())
        queries.append((q, x))
    return N, queries