#P2987. Predicting Battle Outcomes

    ID: 16245 Type: Default 1000ms 256MiB

Predicting Battle Outcomes

Predicting Battle Outcomes

The beta version of StarCowraft II is here! Farmer John and Bessie have played several test battles. Each battle’s outcome was recorded based solely on the hidden strengths of three unit types: cattlebruisers with strength \(S_1\), cow templars with strength \(S_2\), and ultracows with strength \(S_3\). The only guarantee is that no unit’s strength exceeds another by a factor of 100.

The total strength of an army is given by:

(\text{Strength} = (\text{# cattlebruisers})\cdot S_1 + (\text{# cow templars})\cdot S_2 + (\text{# ultracows})\cdot S_3)

In a battle the army with the higher total strength wins; if both are equal then the winner is chosen at random. Based solely on the outcomes of \(N\) (where \(0 \le N \le 300\)) test battles (each test battle lists the counts of the three unit types for Farmer John and Bessie and a victory letter: 'J' indicating a win for Farmer John, and 'B' for Bessie), your task is to decide the winner for \(M\) (where \(1 \le M \le 2000\)) new battles.

For each new battle, if under every possible set of unit strengths consistent with the test battle results the outcome is the same, output that winning letter ('J' or 'B'). Otherwise, output '?' to indicate uncertainty.

inputFormat

The first line contains two integers \(N\) and \(M\).

The next \(N\) lines each contain 7 items: \(J1_\text{i}\), \(J2_\text{i}\), \(J3_\text{i}\), \(B1_\text{i}\), \(B2_\text{i}\), \(B3_\text{i}\) and a character \(V_\text{i}\) ('J' or 'B').

The following \(M\) lines each contain 6 integers representing the counts of the units for Farmer John (\(J1, J2, J3\)) and Bessie (\(B1, B2, B3\)) in a new battle.

outputFormat

Output \(M\) lines. Each line should contain a single character: 'J' if Farmer John is guaranteed to win, 'B' if Bessie is guaranteed to win, or '?' if the outcome is indeterminate.

sample

3 3
6 5 4 5 4 7 J
5 4 2 3 5 5 B
9 0 10 8 2 7 J
6 6 4 5 4 7
9 0 10 8 2 6
8 5 3 7 4 5
J

J ?

</p>