eolymp
bolt
Try our new interface for solving problems
Problems

Party Games

Party Games

You've been invited to a party. The host wants to divide the guests into \textbf{2} teams for party games, with exactly the same number of guests on each team. She wants to be able to tell which guest is on which team as she greets them as they arrive, and as easily as possible, without having to take the time to look up each guest's name on a list. Being a good computer scientist, you have an idea: give her a single string, and all she has to do is determine whether the guest's name is alphabetically less than or greater than that string. Given the unique names of \textbf{n} party guests (\textbf{n} is even), find the shortest possible string \textbf{S} such that exactly half the names are less than or equal to \textbf{S}, and exactly half are greater than \textbf{S}. If there's more than one string of the shortest length, output the one that comes first alphabetically. \InputFile There will be multiple test cases in the input. Each test case will begin with an even integer \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{1000}) on its own line. On the next \textbf{n} lines will be names, one per line. Each name will be a single word consisting only of capital letters, and will be at least one letter and no longer than \textbf{30} letters. All of the names in a test case will be unique. The input will end with a \textbf{0} on its own line. \OutputFile For each case, output the alphabetically first of all of the shortest possible strings that your host could use to separate her guests. Output this string using all upper case letters. Do not output any spaces. Do not put a blank line between outputs.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
FRED
SAM
JOE
MARGARET
2
FRED
FREDDIE
2
JOSEPHINE
JERRY
0
Output example #1
K
FRED
JF