# Microorganism Simulation and Dominant Family Detection
## Problem Statement
On a microscopic scale, a line of $n$ microorganisms exists, each belonging to a specific family and possessing a certain size. These microorganisms engage in a dynamic simulation where they can eat their adjacent neighbors based on a set of rules. The simulation proceeds in discrete rounds until an equilibrium is reached, meaning no further eating is possible. Your task is to simulate this process and report the family and final size of the largest remaining microorganism.
Each microorganism $M_i$ is characterized by its family $F_i$ (a single uppercase English letter) and its size $S_i$ (a positive integer).
The rules governing the simulation are as follows:
1. **Eating Conditions**: A microorganism $M_i$ can eat an adjacent neighbor $M_j$ if and only if:
* Their families are different: $F_i \ne F_j$.
* $M_i$ is strictly larger than $M_j$: $S_i > S_j$.
2. **Simulation Rounds**: The simulation unfolds in discrete rounds. In each round:
* All potential eating actions for the current state are identified. An organism can only participate in one action (either eat or be eaten) per round.
* **Resolution from Left to Right**: Organisms are evaluated from left to right. When considering an organism $M_i$ at its current position:
* If $M_i$ can eat its left neighbor $M_{i-1}$ and $M_{i-1}$ has not yet been designated to act (either eat or be eaten) in this round, $M_i$ will eat $M_{i-1}$. $M_i$ and $M_{i-1}$ are then marked as having acted this round, and $M_i$ cannot perform any other action in this round.
* Otherwise, if $M_i$ can eat its right neighbor $M_{i+1}$ and $M_{i+1}$ has not yet been designated to act in this round, $M_i$ will eat $M_{i+1}$. $M_i$ and $M_{i+1}$ are then marked as having acted this round, and $M_i$ cannot perform any other action in this round.
* After all organisms have been evaluated for potential actions in the current round, all determined eating actions are applied simultaneously. This means that if $M_i$ eats $M_j$:
* $M_i$'s size increases by $M_j$'s size: $S_i \leftarrow S_i + S_j$.
* $M_j$ is removed from the line of microorganisms.
3. **Simulation Halt**: The simulation halts when an entire round passes with no microorganism performing any eating action.
4. **Final Result**: After the simulation reaches equilibrium, you must find the microorganism with the largest final size. It is guaranteed that there will always be exactly one such microorganism.
## Input Format
The input consists of three lines:
- The first line contains a single integer $n$ ($1 \le n \le 20$), representing the initial number of microorganisms.
- The second line contains $n$ space-separated uppercase English letters $F_1, F_2, \dots, F_n$, representing the families of the microorganisms.
- The third line contains $n$ space-separated integers $S_1, S_2, \dots, S_n$, representing the initial sizes of the microorganisms.
## Output Format
A single string of the form `"FAMILY SIZE"`, where `FAMILY` is the family letter and `SIZE` is the final size of the largest microorganism after the simulation reaches equilibrium. For example, `"A 39"`.
## Sample Test Cases
### Sample Input 1
```
7
A B C B B A C
5 5 2 10 4 6 7
```
### Sample Output 1
```
"A 39"
```
### Sample Input 2
```
20
C C C C C C C C B B A A A A A A A A A A
200 128 64 32 16 8 4 2 1 2 200 200 200 200 200 200 200 200 200 200
```
### Sample Output 2
```
"B 2257"
```
## Constraints
- $1 \le n \le 20$, where $n$ is the initial number of microorganisms.
- Each family letter $F_i$ is a single uppercase English letter (i.e., from `'A'` to `'Z'`).
- Each initial size $S_i$ is a positive integer, $1 \le S_i \le 10^9$.
- The total size of any microorganism will not exceed $2 \cdot 10^9$ at any point during the simulation.
- There will always be exactly one microorganism with the maximum size at the end of the simulation.
- Time limit: 1 second
- Memory limit: 256 MB
## Explanation
Let's trace Sample Input 1:
Initial state (represented as a list of `(Family, Size)` tuples):
`[(A, 5), (B, 5), (C, 2), (B, 10), (B, 4), (A, 6), (C, 7)]`
**Round 1:**
We iterate through the microorganisms from left to right, identifying actions. `acted_this_round` set tracks organisms that have already participated in an action.
* $M_0=(A,5)$: Cannot eat $M_1=(B,5)$ ($5 \not> 5$).
* $M_1=(B,5)$: Can eat $M_2=(C,2)$ ($B \ne C$, $5 > 2$). Action: $M_1$ eats $M_2$. $M_1, M_2$ marked `acted_this_round`.
* $M_2=(C,2)$: Marked `acted_this_round`. Skipped.
* $M_3=(B,10)$: $M_2$ is marked `acted_this_round`. Cannot eat $M_4=(B,4)$ ($B=B$).
* $M_4=(B,4)$: Cannot eat $M_3=(B,10)$ ($B=B$). Cannot eat $M_5=(A,6)$ ($4 \not> 6$).
* $M_5=(A,6)$: Can eat $M_4=(B,4)$ ($A \ne B$, $6 > 4$). Action: $M_5$ eats $M_4$. $M_5, M_4$ marked `acted_this_round`.
* $M_6=(C,7)$: $M_5$ is marked `acted_this_round`.
Applying actions simultaneously:
* $M_1=(B,5)$ eats $M_2=(C,2)$, resulting in $(B, 5+2=7)$.
* $M_5=(A,6)$ eats $M_4=(B,4)$, resulting in $(A, 6+4=10)$.
State after Round 1: `[(A, 5), (B, 7), (B, 10), (A, 10), (C, 7)]`
**Round 2:**
* $M_0=(A,5)$: Cannot eat $M_1=(B,7)$ ($5 \not> 7$).
* $M_1=(B,7)$: Can eat $M_0=(A,5)$ ($B \ne A$, $7 > 5$). Action: $M_1$ eats $M_0$. $M_1, M_0$ marked `acted_this_round`.
* $M_2=(B,10)$: $M_1$ is marked `acted_this_round` for its left neighbor. Cannot eat $M_3=(A,10)$ ($10 \not> 10$).
* $M_3=(A,10)$: Cannot eat $M_2=(B,10)$ ($10 \not> 10$). Can eat $M_4=(C,7)$ ($A \ne C$, $10 > 7$). Action: $M_3$ eats $M_4$. $M_3, M_4$ marked `acted_this_round`.
* $M_4=(C,7)$: Marked `acted_this_round`. Skipped.
Applying actions simultaneously:
* $M_1=(B,7)$ eats $M_0=(A,5)$, resulting in $(B, 7+5=12)$.
* $M_3=(A,10)$ eats $M_4=(C,7)$, resulting in $(A, 10+7=17)$.
State after Round 2: `[(B, 12), (B, 10), (A, 17)]`
**Round 3:**
* $M_0=(B,12)$: Cannot eat $M_1=(B,10)$ ($B=B$).
* $M_1=(B,10)$: Cannot eat $M_0=(B,12)$ ($B=B$). Cannot eat $M_2=(A,17)$ ($10 \not> 17$).
* $M_2=(A,17)$: Can eat $M_1=(B,10)$ ($A \ne B$, $17 > 10$). Action: $M_2$ eats $M_1$. $M_2, M_1$ marked `acted_this_round`.
Applying actions simultaneously:
* $M_2=(A,17)$ eats $M_1=(B,10)$, resulting in $(A, 17+10=27)$.
State after Round 3: `[(B, 12), (A, 27)]`
**Round 4:**
* $M_0=(B,12)$: Cannot eat $M_1=(A,27)$ ($12 \not> 27$).
* $M_1=(A,27)$: Can eat $M_0=(B,12)$ ($A \ne B$, $27 > 12$). Action: $M_1$ eats $M_0$. $M_1, M_0$ marked `acted_this_round`.
Applying actions simultaneously:
* $M_1=(A,27)$ eats $M_0=(B,12)$, resulting in $(A, 27+12=39)$.
State after Round 4: `[(A, 39)]`
**Round 5:**
* $M_0=(A,39)$: Has no neighbors. No actions possible.
Simulation halts. The largest (and only) microorganism is $(A, 39)$.
Output: `"A 39"`
Loading problem statement...