You are tracking the results of a soccer tournament. For each match that has been played so far, you have written down the names of the two opposing teams, along with the number of goals scored by each team. However, you suspect that for one of the matches, you may have written down the wrong number of goals scored by one of the teams.
Fortunately, you know which team is the current tournament leader. The tournament is scored as follows. For each game, the winning team (the team that scored more goals) gets 3 points and the losing team gets 0 points. If there is no winner (both teams scored the same number of goals), each team gets 1 point. The tournament leader is the team that has strictly more points than any other team.
You are given a String[] results, where the i-th element is what you have written down as the result of the i-th match. Each element is formatted as "team1 team2 a:b" (quotes for clarity), where team1 is the name of the first team, team2 is the name of the second team, a is the number of goals scored by the first team, and b is the number of goals scored by the second team. You are also given a String winner, the name of the current tournament leader according to the real results.
If, according to your written results, the tournament leader is winner, return -2. Otherwise, if there exists exactly one match in your written results where you can change the number of goals scored by one of the teams, and the tournament leader would then be winner according to the changed written results, return the index of that match. If there exist several such matches, return the index of the earliest of those matches. If no such match exists, return -1. All indices are 0-based.
|