A Voting Protocol

Time limit1sMemory limit128 MB

Summary
Simulate ranked-ballot rounds where each voter backs the top unpicked candidate and the top vote getters fill k seats with alphabetical tie breaks.
Level

Medium4 of 10

Topics
Simulation, Sorting
Solved
No attempts yet

Problem

An election fills several positions at once. Suppose there are kk positions to fill. Each voter hands in a ranked list of the kk candidates they prefer most. A candidate is identified by a single lowercase letter, the first choice sits at position 1, the second choice at position 2, and so on.

The winners are picked over a series of rounds. In each round every voter votes for the first candidate on their list who has not been selected yet. The candidate with the most votes joins the selected list. When several candidates tie for the most votes, all of them are selected, unless that would push the total past kk. In that case the tie is broken by alphabetical order: if two more candidates are needed and 'a', 'x' and 'z' all have equally many votes, then 'a' and 'x' are selected. The election ends once kk candidates have been selected.

Input

The input holds several elections. The first line of an election contains two integers: the number of positions to fill, kk (1≤k≤261 \le k \le 26), and the number of voters, nn (1≤n≤10001 \le n \le 1000). Then come nn lines, each a sequence of kk lowercase letters with no repetition, since nobody can vote for the same person twice. The input ends with a line containing two zeros.

Output

Print one line per election. Each line contains the word Election, a space, the number of the election (a running count starting at 1), a colon and a space, then the selected candidates written in the order they were selected. Candidates selected in the same round are listed alphabetically.

Examples1

  1. Example 1

    Input
    2 3
    gm
    mg
    mv
    4 4
    kqxj
    qxjk
    xjkq
    jkqx
    0 0
    
    Expected output
    Election 1: mg
    Election 2: jkqx