We need to understand the problem. It says "Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion."
The problem is from an online judge? Possibly Codeforces? The name "The Game" might be Rock-Paper-Scissors like? But the strings contain characters: [], (), 8< (maybe representing shapes?). Actually, the examples show strings like "[]8<" and "8<8<". And the second example: "8<8<()" and "[]8<[]". So the symbols: "[]", "()", "8<". They look like rock-paper-scissors symbols? Possibly each two-character combination is an action? Wait, the strings are of length between 2 and 20 characters inclusive. But the examples show strings of length maybe: "[]8<" - that's 8 characters? Let's count: "[" "]" "(" ")" "[" "]" "8" "<"? That's 8 characters. But "8<" is two characters, but they are separate. Actually, the string may consist of characters that are each a "symbol"? Could be the game is like "rock-paper-scissors-lizard-Spock"? But we have only three distinct tokens: "[]", "()", "8<". Possibly each token is two characters, but the string length is counted in characters, but each action is represented by two characters. However, the input strings are two lines of equal length between 2 and 20 characters. That suggests that each character might be an action? But we have characters like "[", "]", "(", ")", "8", "<". Those are single characters. So maybe each character is an action? But then there are 6 different characters? Or maybe "8<" together forms one action? However, the strings can contain "<" as a character; "8" as a character; etc. But we need to parse the actions.
Maybe the game is "The Game" (as in "The Game" from some contest) is a card game? Or maybe it's a variation of rock-paper-scissors where each string describes a sequence of moves, and we compare them round by round? Because the output is which team wins overall.
Given two strings of equal length, we need to determine who wins based on some rules.
Let's try to derive from examples. Example 1:
String1: "[]8<"
String2: "8<8<"
Output: "TEAM 2 WINS"
Example 2:
String1: "8<8<()"
String2: "[]8<[]"
Output: "TIE"
We need to find a consistent rule.
First, note that in example 2, lengths: "8<8<()" - characters: 8, <, 8, <, (, ) -> length 6. String2: "[]8<[]" - characters: [, ], 8, <, [, ] -> length 6. So equal length.
Maybe each two characters is a move? That would be 3 moves per string in example2: "8<", "8<", "()" vs "[]", "8<", "[]". But then string2's second move is "8<"? Actually "[]8<[]" if grouped in pairs: "[]", "8<", "[]". Yes. And string1: "8<8<()" grouped: "8<", "8<", "()". So both have 3 moves. In example1: "[]8<" -> pairs: "[]", "()", "[]", "8<"? Wait length is 8, so 4 pairs: "[]", "()", "[]", "8<". String2: "8<8<" -> pairs: "8<", "[]", "()", "8<". So 4 moves each.
So it seems each move is exactly two characters, and the allowed moves are: "[]", "()", "8<". Are there any other possible moves? Possibly also "8<" is one move; note that "<" is part of it, but could be other like ">8"? But no. So the set is: "[]" , "()", "8<". These look like rock (rock looks like a rock? Actually "8<" might represent scissors? In rock-paper-scissors, there are three shapes: rock, paper, scissors. Typically, rock is represented by a fist, maybe "()"? No.
Better: In some cultures, the game "rock-paper-scissors" is represented by symbols: rock is a closed fist (maybe represented as "[]"? Actually a rectangle?), paper is an open hand (maybe "()"?), scissors is two fingers (maybe "8<"? Looks like scissors? "8<" looks like two blades? Possibly that's it). Indeed, "8<" could be a pictogram of scissors: the '8' is the pivot, and '<' is the blades. "[]" might be a rock (like a rectangular shape), "()" might be paper (like an open hand). That is plausible.
So the game is essentially rock-paper-scissors: rock ([]) beats scissors (8<); scissors (8<) beats paper (()); paper (()) beats rock ([]). Standard.
Now we have two strings each representing a sequence of moves (each move is two characters). We need to compare them round by round? The output is which team wins overall, i.e., who wins more rounds. If tie, output "TIE". That matches typical: compare each pair of moves, award a point to the winner of each round (or maybe sum points). But we need to confirm with examples.
Example1:
Round1: team1 "[]" vs team2 "8<". According to rock-paper-scissors: [] beats 8<?
Check: If [] is rock, 8< is scissors, rock beats scissors, so team1 wins round1.
Round2: "()" vs "[]". Paper vs rock: paper beats rock, so team1 wins round2? Actually "()" (paper) beats "[]" (rock), so team1 wins.
Round3: "[]" vs "()". Rock vs paper: paper beats rock, so team2 wins round3.
Round4: "8<" vs "8<". Same, tie.
Now tally: team1 wins rounds 1 and 2 (2), team2 wins round3 (1), ties 1. So team1 wins overall? That would be "TEAM 1 WINS". But the output says TEAM 2 WINS. So something's off.
Maybe the interpretation of which beats which is different. Perhaps the game is not rock-paper-scissors as standard. Let's consider alternative: Could "()" be rock? Or "[]" be paper? Need to determine from examples.
Alternative: perhaps it's "The Game" with rules: each action beats the next in some order? Let's test possibilities.
We have three moves: A = "[]", B = "()", C = "8<". We need to find which beats which such that given the sequences, the total score yields TEAM 2 WINS in first example. Let's denote outcome of each round:
Round1: A vs C
Round2: B vs A
Round3: A vs B
Round4: C vs C
Total wins: team1 wins count? Let W1 be number of rounds where team1 wins, W2 for team2. We have ties not counted.
We need to satisfy: In example1, team2 overall wins, so W2 > W1.
Let’s define a relation: for any two distinct moves X,Y, either X beats Y or Y beats X. Unknown.
Let’s denote outcomes:
R1: f(A, C) -> either 1 (A beats C), -1 (C beats A), or 0 (tie). But they are distinct, so not 0.
R2: f(B, A)
R3: f(A, B)
R4: f(C, C) = 0.
We need sum of signs: For team1 wins: if f(team1, team2) = +1 (team1 beats team2) then count for team1. So we can assign variables.
Let’s denote:
x = f(A,C) (team1 beats if positive)
y = f(B,A)
z = f(A,B)
If we assign directions: we need consistent with a tournament relation (maybe transitive? Possibly not necessarily? But typical rock-paper-scissors is cyclic.)
We need W2 > W1. W1 = number of rounds where f(t1,t2)=+1; W2 = number where f(t1,t2)=-1 (i.e., team2 beats team1). So we need sum sign(f) < 0? Actually sum of f (where f=+1 for team1 win, -1 for team2 win, 0 tie) should be negative for team2 win. For example1, compute net = f(A,C) + f(B,A) + f(A,B) + f(C,C) = f(A,C)+f(B,A)+f(A,B). Since f(C,C)=0.
We need net < 0 to have TEAM 2 WINS.
Thus:
f(A,C) + f(B,A) + f(A,B) < 0.
Now note that f(B,A) and f(A,B) are opposites if the relation is antisymmetric: f(A,B) = - f(B,A) because if A beats B then B does not beat A (unless tie). So likely f(A,B) = - f(B,A). So let’s assume that: f(X,Y) = - f(Y,X) for X≠Y.
Then let’s denote the value for (A,B): let u = f(A,B). Then f(B,A) = -u.
Then the net becomes: f(A,C) + (-u) + u = f(A,C). So net = f(A,C). That means net is just the outcome of round1. So for net < 0 we need f(A,C) = -1, i.e., C beats A. So in this scenario, for team2 to win overall, we need C (8<) beats A ([]). So that would imply that scissors beats rock? That's opposite of standard. But that would yield net negative. And then the other rounds cancel because they are opposite.
But wait, we have round2: B vs A, round3: A vs B. If f(A,B)=u, then f(B,A)=-u. So round2: team1 has B, team2 has A => f(B,A) = -u, meaning if u=+1 (A beats B), then f(B,A) = -1 => team2 wins round2. And round3: A vs B => f(A,B)=u => team1 wins if u=+1. So they cancel. So net is f(A,C). So net depends only on round1 (and round4 is tie). So for team2 to win, we need f(A,C) = -1, i.e., C beats A.
Thus according to example1, the relation must satisfy that C beats A. So "8<" beats "[]".
Now example2: strings: "8<8<()" vs "[]8<[]". Group as moves:
Team1: (1) "8<", (2) "8<", (3) "()"
Team2: (1) "[]", (2) "8<", (3) "[]"
Rounds:
1: C vs A (since team1 move C, team2 move A)
2: C vs C (both C)
3: B vs A (team1 B, team2 A)
Ties: round2 tie.
Now net = f(C,A) + f(C,C) + f(B,A) = f(C,A) + 0 + f(B,A).
Again, if we assume antisymmetry, f(C,A) = - f(A,C). And f(B,A) = - f(A,B). But we don't have A,B round directly. However, we can express net = - f(A,C) - f(A,B) (since f(C,A) = -f(A,C) and f(B,A) = -f(A,B)). But we don't have f(A,B) directly; we need to see net.
But we need net = 0 for TIE (since output TIE). So we need - f(A,C) - f(A,B) = 0 => f(A,C) + f(A,B) = 0.
Now from example1 we got that f(A,C) should be -1 (C beats A) so f(A,C) = -1. Then to satisfy f(A,C) + f(A,B) = 0 => -1 + f(A,B) = 0 => f(A,B) = 1. That means A beats B. So then we have: A beats B, C beats A, and by antisymmetry B beats C? Or not necessarily, but we can derive: if A beats B and C beats A, then for consistency with cyclic nature maybe B beats C? But we haven't used any B vs C round. But we can deduce from antisymmetry: if A beats B, then f(A,B)=+1, f(B,A)=-1. If C beats A, then f(C,A)=+1, f(A,C)=-1. For B vs C, unknown. But we need to see if any other constraints exist. The game likely has a fixed ordering.
Thus our derived relation: "[]" (A) beats "()" (B); "8<" (C) beats "[]" (A); and then by cyclic nature, "()" (B) should beat "8<" (C) to have a non-transitive cycle. Does that match typical? Actually standard rock-paper-scissors: rock beats scissors, scissors beats paper, paper beats rock. But here we have A beats B, C beats A, so B beats C would give cycle: A > B, C > A, B > C. That is exactly: rock? Let's map: If A = [] is rock? Then B = () is paper? But rock beats paper? No, rock loses to paper. So that doesn't match. If A = [] is paper? Then paper beats rock? But B is ()? Hard.
Alternatively, could be: A = "[]" is scissors? B = "()" is rock? C = "8<" is paper? Then scissors beats paper? Wait typical: scissors ([]) beats paper (8<); paper (8<) beats rock (()); rock (()) beats scissors ([]). That would be: A beats C, C beats B, B beats A. But we have from constraints: C beats A (so A loses to C) and A beats B. That would be: A beats B, C beats A. So which mapping? Let's list possible assignments:
We have three objects: X, Y, Z with a cycle: X beats Y, Y beats Z, Z beats X.
Our derived: A beats B, C beats A. So if we set A = X, then B = Y (since X beats Y) and C = Z (since Z beats X). Then the remaining relation Y beats Z would be B beats C. So cycle: A beats B, B beats C, C beats A. So this is a standard cycle, but the ordering is A > B > C > A.
Thus the cycle direction is: A beats B, B beats C, C beats A.
Thus the moves: "[]" (A) beats "()" (B); "()" (B) beats "8<" (C); "8<" (C) beats "[]" (A). That's the consistent rule.
Now check: In this cycle, is it plausible that "8<" beats "[]"? That would be scissors beats rock? In some alternative versions, maybe "8<" is rock? No. But maybe the representation: "8<" could be a rock (like a rock with a crack? Eh). "[]" could be paper (like a sheet), "()" could be scissors? Actually scissors often depicted as an open scissor: could be "8<". So that's already guessed.
Maybe there's a known game: "[]" = rock, "()" = paper, "8<" = scissors is standard representation in some ASCII art? Actually many programming contests have a problem where they represent rock-paper-scissors with these symbols. I recall a problem from Codeforces called "Rock-Paper-Scissors" where they use "[]", "8<", "()"? Not sure.
But we have derived the cycle: [] beats (), () beats 8<, 8< beats [].
Let's test with example1 using that rule.
Example1 rounds:
1: [] vs 8< -> According to derived: 8< beats [], so team2 wins.
2: () vs [] -> [] beats ()? Actually derived: [] beats (), so () vs []: since [] beats (), team2 has [], team1 has ()? Wait round2: team1: "()", team2: "[]". So team2's [] beats team1's ()? Actually the rule says [] beats (). So team2 wins. But from earlier we had team1 winning round2? Let's recalc: round2: team1 "()", team2 "[]". According to derived: [] beats (), so team2 wins. So team2 wins round2.
Round3: [] vs () -> team1 [] beats ()? Actually team1 "[]", team2 "()". So team1 wins.
Round4: 8< vs 8< -> tie.
So wins: team1: round3; team2: round1, round2. So team2 wins 2-1 -> TEAM 2 WINS. That matches.
Example2 using derived:
Round1: 8< vs [] -> 8< beats [], so team1 wins (since team1 has 8<, team2 []).
Round2: 8< vs 8< -> tie.
Round3: () vs [] -> [] beats (), so team2 wins.
So wins: team1: round1, team2: round3, tie round2. So 1-1 -> TIE. That matches.
Great! So the rule is confirmed: The three moves are:
- "[]" (rock? maybe it's something else)
- "8<" (scissors? maybe)
- "()" (paper? maybe)
And the winning rule: "[]" beats "()", "()" beats "8<", "8<" beats "[]". That is exactly the cycle: [] > () > 8< > [].
Thus the problem is: given two strings of equal length, each consisting of a sequence of these moves (each move is exactly two characters), compare the moves round by round, award a point to the winner of each round (ignore ties). At the end, the team with more points wins; if equal, tie.
We need to output "TEAM 1 WINS", "TEAM 2 WINS", or "TIE".
Now, note: The strings have length between 2 and 20 inclusive. They are given as two lines. The length is even because each move is two characters? But the problem statement says strings of equal length between 2 and 20 inclusive, but doesn't state they must be even. However, given the moves are two characters each, the length must be even. But the input may contain other characters? The problem statement says "describing the teams' actions". Likely the strings consist only of the characters: '8', '<', '[', ']', '(', ')'. And the length is even. So we can parse them as consecutive pairs.
Edge cases: What if there is an invalid move? Probably not. The input constraints ensure valid.
Implementation: read two strings s1, s2. Check len(s1) == len(s2) and both even? Not necessarily, but we assume.
We need to iterate i from 0 to length-1 step 2. For each i, let move1 = s1[i:i+2], move2 = s2[i:i+2]. Determine winner using the rule:
Define a mapping for winner:
If move1 == move2 -> tie (no point)
Else if (move1 == "[]" and move2 == "()") or (move1 == "()" and move2 == "8<") or (move1 == "8<" and move2 == "[]") then team1 wins.
Else (the opposite) team2 wins.
Alternatively, we can assign numeric values: e.g., 0 for [], 1 for (), 2 for 8<. Then define win: ( (a - b) mod 3 == 1 )? Actually in a cycle where 0 beats 1, 1 beats 2, 2 beats 0. So a beats b if (a, b) in {(0,1), (1,2), (2,0)}. That is ( (a+1) % 3 == b )? Because 0 beats 1 (0+1=1), 1 beats 2 (1+1=2), 2 beats 0 (2+1=3 mod3=0). So a beats b if (a+1)%3 == b. So we can map each move to an integer and then check.
So algorithm:
- Map: "[]" -> 0, "()" -> 1, "8<" -> 2.
- Loop i in range(0, len(s1), 2):
m1 = s1[i:i+2]; m2 = s2[i:i+2];
a = mapping[m1]; b = mapping[m2];
if a == b: continue;
if (a+1)%3 == b: team1 score++ else team2 score++.
- After loop, compare scores.
But ensure that we are mapping correctly: we derived that [] beats (), so if a=0 and b=1, then (0+1)%3=1 -> condition true, team1 wins. That's correct. If a=1 and b=2 -> (1+1)%3=2 -> team1 wins. If a=2 and b=0 -> (2+1)%3=0 -> team1 wins. Otherwise team2 wins.
So that matches.
We need to output the appropriate string.
Now, double-check: In example1, mapping: []->0, ()->1, 8<->2. R1: a=0,b=2 => (0+1)%3=1, not 2, so false -> team2 wins. R2: a=1,b=0 -> (1+1)%3=2 !=0 -> false -> team2 wins? Wait, R2: team1 "()" => 1, team2 "[]" => 0. Condition (a+1)%3 == b? (1+1)%3=2, b=0 => false, so team2 wins. That matches our earlier: team2 wins R2. R3: a=0,b=1 -> (0+1)%3=1==1 true -> team1 wins. Good.
Now example2: R1: a=2,b=0 -> (2+1)%3=0==0 true -> team1 wins. R2: both 2 tie. R3: a=1,b=0 -> (1+1)%3=2 !=0 -> false -> team2 wins. So scores 1-1 tie.
Thus algorithm is correct.
Now, ensure input reading: two lines, maybe they contain spaces? Unlikely. Strings may have trailing newline. Use getline.
Edge Cases: If length is 0? Not possible. If odd length? Problem says strings of equal length between 2 and 20 inclusive, but doesn't guarantee even. However, given the moves are two characters, likely length is even. But could there be moves of length 1? The symbols are two characters each. So length must be even. But to be safe, we could assume that each move is exactly two characters; if length is odd, maybe there's a mis-spec? I'd assume valid input as per problem statement.
Now, implement.
Complexity trivial.
Now, check for potential pitfalls: The characters include '<' which is a special character in HTML? The problem statement shows "8<" which is HTML-escaped for "<". In actual input, the characters are '8' and '<'. So we need to treat them as normal characters.
Thus when reading string, it's a plain string containing '8', '<', etc.
Now, confirm that the mapping keys are strings: "[]", "()", "8<". So when we extract substring of length 2, we get exactly those.
But note: The order of characters: For "8<", the substring will be "8<". Good.
Now, about output: Exactly "TEAM 1 WINS", "TEAM 2 WINS", "TIE". Uppercase with spaces as shown.
Thus solution is straightforward.
Let's write code in Python.
Pseudo:
def solve():
import sys
s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()
# perhaps there might be multiple test cases? Problem seems single test case.
n = len(s1)
mapping = {"[]":0, "()":1, "8<":2}
score1 = 0
score2 = 0
for i in range(0, n, 2):
m1 = s1[i:i+2]
m2 = s2[i:i+2]
a = mapping[m1]
b = mapping[m2]
if a == b:
continue
if (a+1)%3 == b:
score1 += 1
else:
score2 += 1
if score1 > score2:
print("TEAM 1 WINS")
elif score2 > score1:
print("TEAM 2 WINS")
else:
print("TIE")
We need to ensure that the mapping keys exist. We can trust input.
But note: The problem might be from a contest where there could be multiple test cases? The statement doesn't indicate that. It just says input contains two strings. So single case.
We'll implement accordingly.
Now, confirm with examples.
Example1:
s1="[]8<"
s2="8<8<"
n=8
i=0: m1="[]"->0, m2="8<"->2, a!=b, (0+1)%3=1 !=2 -> team2 scores.
i=2: m1="()"->1, m2="[]"->0, (1+1)%3=2 !=0 -> team2 scores.
i=4: m1="[]"->0, m2="()"->1, (0+1)%3=1==1 -> team1 scores.
i=6: m1="8<"->2, m2="8<"->2 tie.
Scores: team1=1, team2=2 -> output "TEAM 2 WINS". OK.
Example2:
s1="8<8<()"
s2="[]8<[]"
n=6
i=0: m1="8<"->2, m2="[]"->0, (2+1)%3=0==0 -> team1 scores.
i=2: m1="8<"->2, m2="8<"->2 tie.
i=4: m1="()"->1, m2="[]"->0, (1+1)%3=2 !=0 -> team2 scores.
Scores: 1-1 tie -> output "TIE". OK.
Thus solution is correct.
Now, we might also consider handling trailing newline and possible empty lines. Use strip() to remove whitespace. But careful: strings might contain spaces? No.
Now, I'll produce final answer in Python.
But note: sometimes the problem may be in C++ etc, but here we are to produce solution.
Thus final code.
Now, let's also discuss potential alternative interpretations: Could there be a case where the string length is not even? Perhaps but we assume it is even; if not, we could handle by reading each character individually? But not needed.
Thus final solution.
Now, I'll write the final answer with explanation and code. ```python
import sys
def main():
# read the two lines, strip newline characters
s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()
# map each move to a number for easy comparison
move_to_int = {"[]": 0, "()": 1, "8<": 2}
score1 = 0
score2 = 0
n = len(s1) # both strings have the same length
for i in range(0, n, 2): # each move consists of 2 characters
m1 = s1[i:i+2]
m2 = s2[i:i+2]
a = move_to_int[m1]
b = move_to_int[m2]
if a == b:
continue # tie, no points
# in our numbering, a beats b exactly when (a+1)%3 == b
if (a + 1) % 3 == b:
score1 += 1
else:
score2 += 1
if score1 > score2:
print("TEAM 1 WINS")
elif score2 > score1:
print("TEAM 2 WINS")
else:
print("TIE")
if name == "main":
main()