Orig Description
Frequency of appearance operation
There is a transformation operation for a finite sequence called a frequency of appearance operation. The result of transforming the sequence S = {s1, s2, ..., sn} is a sequence of the same length. If we define the result as C = {c1, c2, ..., cn}, then ci represents the number of times si appears in the sequence S.
For example, if S = {3, 4, 1, 5, 9, 2, 6, 5, 3}, then C = {2, 1, 1, 2, 1, 1, 1, 2, 2}. Performing a frequency of appearance operation on this sequence C gives us P = {4, 5, 5, 4, 5, 5, 5, 4, 4}. This sequence does not change with frequency of appearance operations. Such a sequence P is called a fixed point of the sequence S. It is known that for any sequence, the fixed point can be obtained by repeating the frequency of appearance operation.
The example below shows the procedure for the frequency of appearance operation. The first line represents the sequence S, the second line represents the sequence C, and the last line represents the sequence P. We count the number of occurrences and find ci by listing the number of times the first element (s1=2) in the sequence S appears in the same way as the second element (s2=7) with two elements.
Write a program that takes the length of the sequence n and the sequence S as input and outputs the fixed-point sequence P and the minimum number of frequency of appearance operations required to obtain P.
Input
Multiple datasets are given. Each dataset is given in the following format.
n
s1 s2 ... sn
The first line contains an integer n (n ≤ 12) representing the length of the sequence. The second line contains integers si (1 ≤ si ≤ 100) representing the elements of the sequence S separated by spaces.
The input ends with a line containing a single 0. There are no more than 200 datasets.
Output
For each dataset, output the minimum number of times the frequency of appearance operation is performed (an integer) on the first line and the elements p1, p2, ..., pn of the corresponding fixed-point sequence P on the second line, separated by spaces.
Sample Input
10
4 5 1 1 4 5 12 3 5 4
0
Output for the Sample Input
3
6 6 4 4 6 6 4 4 6 6
Extracted Specification
An integer n (1 ≤ n ≤ 12), representing some quantity or size.
A list of integers s of size n, where each integer is between 1 and 100.
Multiple datasets are given, each ending with a line containing a single 0. There are no more than 200 datasets.
### Example Input:
```
10
4 5 1 1 4 5 12 3 5 4
0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, List[int]]]):
'''
inputs: a list of tuples, each containing:
- an integer
- a list of integers
'''
```
Test Case Generator
Sure! Here's the test case generator for the given problem statement "Frequency of appearance operation". The test case generator will create random test cases adhering to the constraints specified in the problem statement.
```python
import random
def generate_test_case():
n = random.randint(1, 12)
s = [random.randint(1, 100) for _ in range(n)]
return n, s
def tcgen():
test_cases = []
num_datasets = random.randint(1, 200) # Maximum 200 datasets
for _ in range(num_datasets):
n, s = generate_test_case()
test_cases.append((n, s))
test_cases.append((0, [])) # End with 0 as per the input format
return test_cases
# Example Usage:
if __name__ == "__main__":
test_cases = tcgen()
for n, s in test_cases:
if n == 0:
print(n)
else:
print(n)
print(' '.join(map(str, s)))
```
This script generates a set of test cases for the problem "Frequency of appearance operation". The function `generate_test_case()` creates a random sequence of length `n` with values between 1 and 100. The function `tcgen()` then collects up to 200 such datasets and appends a terminating dataset with `n = 0`.
You can run this script to generate random test cases in the format specified by the problem statement. Here is how the script works:
1. `generate_test_case()` method:
- Randomly selects the length of the sequence `n` between 1 and 12.
- Generates a list `s` of `n` random integers between 1 and 100.
2. `tcgen()` method:
- Randomly decides the number of datasets (up to 200).
- Calls `generate_test_case()` to create each dataset and appends it to the list of test cases.
- Adds the terminating dataset `(0, [])`.
3. The script prints the generated test cases in the required format.
Feel free to adjust the random seed or extend the script to save the test cases to a file if needed.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
n = int(fh.readline().strip())
if n == 0:
break
s = list(map(int, fh.readline().strip().split()))
datasets.append((n, s))
return datasets