An amateur astronomy club runs several open stargazing sessions during the month, and members register in advance for whichever sessions they plan to attend. The club's organizers want to flag every session whose turnout was neither unusually small nor unusually large -- precisely, every session whose number of registered members is strictly greater than the smallest per-session registration count and strictly less than the largest per-session registration count observed that month. Given every registration, report the qualifying sessions.
n, the number of registration records.n lines contains two tokens session participant, meaning participant registered for session. Every (session, participant) pair appears at most once in the input.Print, in ascending alphabetical order, the name of every session whose registration count is strictly between the minimum and the maximum registration count across all sessions, one name per line. If every session's count equals the minimum or the maximum -- including when all sessions tie, or when only one or two distinct sessions appear at all -- print nothing.
Example 1
Input
6 alpha p1 alpha p2 beta p1 beta p2 beta p3 gamma p1
Expected
alpha
Explanation
alpha has 2 registrants, beta has 3, gamma has 1. The minimum count is 1 (gamma) and the maximum is 3 (beta). Only alpha's count (2) is strictly between them, so it is the only session printed.
Example 2
Input
4 solo x teamA y teamA z teamB w
Expected
(empty)Explanation
solo has 1 registrant, teamA has 2, teamB has 1. The minimum count is 1 and the maximum is 2. Every session's count equals one of these two extremes (solo and teamB tie at the minimum, teamA is the maximum), so nothing is printed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →