cho.sh
Notes
Loading...

Tennis Match

Time limit

2s

Memory limit

128 MB

Problem

There are N players, where 1 <= N <= 26, playing a tennis match. A normal tennis game has two players, but in this problem the rules are changed so that all N players play together on one court.

A match consists of several sets. Each set consists of several games, and each game consists of several turns. To win a game, a player first wins turns, then wins the game, then uses game wins to win sets.

Serving is assigned in order on every turn. In each game, the first server is the player after the first server of the previous game. In the first turn of the first game of each set, the server is the player after the first server of the first game of the previous set. Players are written as uppercase letters starting from A. When N = 3, the serving order is as follows.

  • [Set 1]

    • Game 1: A, B, C, A, ...
    • Game 2: B, C, A, ...
    • Game 3: C, A, B, ...
    • Game 4: A, B, C, ...
    • ...
  • [Set 2]

    • Game 1: B, C, A, B, ...
    • Game 2: C, A, B, ...
    • Game 3: A, B, C, A, ...
    • ...
  • ...

The winner of a game is determined by the following rules. Every player starts each game with 0 points. If player x wins a turn, the score change and game-ending rules are checked in the priority order (1) > (2) > (3) > (4).

  1. If x currently has 3 points and every other player has at most 2 points, x wins the game.
  2. If x currently has 4 points, x wins the game.
  3. If a player other than x currently has 4 points, that player loses 1 point.
  4. Otherwise, x simply gains 1 point.

A set is won by a player who has won at least 6 games in the set and has won at least two more games than every other player. The match is won by a player who has won at least 3 sets. However, if one player wins every game in a set, that set counts as two set wins for that player.

Given the winner of each game in order during the match, write a program that prints the final winner.

Input

The first line contains an integer N and a string S. The string S lists the winners of the games in order. Because only the game winners are listed, you must analyze the string according to the rules above to determine where each set ends. The length of S is at most 100,000. The input is guaranteed to be valid.

Output

Print the winner on the first line.