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 tuples where each tuple consists of two integers. The first integer \(q\) (1 ≤ q ≤ 3), representing a type of operation, and the second integer \(x\) (1 ≤ x ≤ 10), representing a value associated with the operation.
### 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 where each tuple consists of two integers
'''
```
Test Case Generator
Sure! Here is a test case generator for the problem "How old are you":
```python
import random
def tcgen():
# Define the constraints
N = random.randint(1, 15) # 1 ≤ N ≤ 15
queries = []
for _ in range(N):
q = random.randint(1, 3) # 1 ≤ q ≤ 3
x = random.randint(1, 10) # 1 ≤ x ≤ 10
queries.append((q, x))
return N, queries
# Example usage:
N, queries = tcgen()
print(N)
for q, x in queries:
print(q, x)
```
This function generates a random test case for the problem. It creates a random number of queries \(N\) between 1 and 15, and then for each query, it generates a random type \(q\) (either 1, 2, or 3) and a random integer \(x\) between 1 and 10. The output is formatted as specified in the problem statement.
You can use this generator to create multiple test cases to test your solution. Here is an example of how the output might look:
```
7
3 5
1 3
2 8
1 6
1 10
3 2
2 7
```
This represents a test case with 7 queries, where each query modifies the number you're thinking of by either multiplying, adding, or subtracting a specified value.
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