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 (q, x) of size N, where each tuple consists of:
- an integer q (1 ≤ q ≤ 3), representing a type of operation.
- an integer x (1 ≤ x ≤ 10), representing an operand for the operation.
### Example Input:
```
3
1 2
2 10
3 8
```
### Function Signature:
Write a function f(N, queries) that takes in the input.
def f(N: int, queries: List[Tuple[int, int]]):
'''
N: an integer
queries: a list of tuples, each containing two integers
'''
Test Case Generator
Sure, I can help you create a test case generator for the problem statement "How old are you". Below is a Python function that generates random test cases based on the provided constraints:
```python
import random
def generate_test_case():
# Number of queries N (1 ≤ N ≤ 15)
N = random.randint(1, 15)
queries = []
for _ in range(N):
# Type of query q (1 ≤ q ≤ 3)
q = random.randint(1, 3)
# Value of x (1 ≤ x ≤ 10)
x = random.randint(1, 10)
queries.append((q, x))
# Format the test case as expected
test_case = f"{N}\n"
for query in queries:
test_case += f"{query[0]} {query[1]}\n"
return test_case.strip()
# Example usage
if __name__ == "__main__":
print(generate_test_case())
```
This function generates a random number of queries (`N`) between 1 and 15. Each query consists of a type (`q`), which is randomly chosen between 1 and 3, and a value (`x`), which is randomly chosen between 1 and 10. The function then formats these queries into the appropriate input format suitable for the problem.
You can call the `generate_test_case()` function to generate a random test case and print it out, similar to what is shown in the example usage section.
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
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, queries = extract_arguments(fh)
# f(N, queries)