Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

Voting

Since we were not able to prevent the cyber attack, and the bots were able to access our data, the attackers decided that they want to "get physical" and perform a full-scale military attack against us to try and kidnap the best player in each team. However the AI bots were not able to find these kind of information among the stolen logs, so they entrust you to create an algorithm which is able to decide the best player in your team by the following voting algorithm:

  • Each voter creates a ranking from best candidate towards the worst. (Note: it is possible that there are more candidates than voters.)
  • In a group of n candidates, in each of the rankings the best candidate gets a score of n-1, the second best n-2,...etc. and the worst gets a score of 0.
  • We summarize the ranks for each candidate among the rankings (so if the scores for John are 3,4,0,0,1, then the final score is 8).
  • We calculate the average of these final scores.
  • We remove every candidate from the list whose final score is below this average.
  • We continue the procedure with the remaining candidates until either only candidate is left, or until every remaining candidate has the same final ranking.
Note: after each deletion we do not create a new ranking, we simply update the scores of the remaining elements. See the below example for a detailed explanation.

Input

The input consists of two units (each line is terminated with an end of line character):

  • The first line contains two positive integers n and m, separated by a single space character. Each of these numbers are at most 255.
  • Each of the following n lines contain exactly m words, separated by a single space character. Each line represents a personal ranking of a team member in descending order from left to right.

Output

The output is a string, which is the name of the last element after performing the above algorithm (so the "name of the best group member"). If there is a tie at the end, then list each elements in alphabetically descending order, each separated by a single space character.

Example

Input:
  1. 3 4
  2. John Bob Alice Lucy
  3. Lucy Bob John Alice
  4. Alice John Bob Lucy
download as text file Output:
  1. John
download as text file

Explanation

LIST: John Bob Alice Lucy Lucy Bob John Alice Alice John Bob Lucy Alice: 1+0+3 = 4 Bob: 2+2+1 = 5 John: 3+1+2 = 6 Lucy: 0+3+0 = 3 AVG: (4+5+6+3)/4 = 4.5 DEL: Alice, Lucy LIST: John Bob Bob John John Bob Bob: 0+1+0 = 1 John: 1+0+1 = 2 AVG: (1+2)/2 = 1.5 DEL: Bob LIST: John
University of Debrecen; Faculty of Informatics; v. 09/30/2024