P16194 [ROIR 2014 Day 1] Schools

Description

When registering for the Internet Olympiad, all participants fill in an application form, which requires them to write the name of their school. Different participants may write the school name in different ways, such as “Physics and Mathematics School No. $18$”, “Phys-Math School No. $18$”, and so on. The organizers have already collected all the school names filled in by the participants. It is known that the digits in a school name appear only in the school number, and the digits appear exactly once in the school name. This number uniquely determines the school’s ID. The school ID is a positive integer and does not start with zero. Please write a program for the Olympiad website to help the organizers count the following information: how many schools have at most five participants, and output the IDs of these schools.

Input Format

The first line contains an integer $n\ (1 \le n \le 1000)$, representing the number of school names filled in by all participants. Each of the next $n$ lines contains one school name. A school name contains only uppercase and lowercase English letters, digits, and spaces, and its length does not exceed $100$ characters.

Output Format

Output an integer $m$ in the first line, representing the number of schools whose number of participants is between $1$ and $5$ (inclusive). Then output $m$ lines, each containing one qualifying school ID, in any order.

Explanation/Hint

In the example, students from three schools registered for the Internet Olympiad: school ID $18$ has two students, ID $42$ has one student, and ID $9$ has six students. Therefore, the school IDs whose number of participants is between $1$ and $5$ are $18$ and $42$. ### Scoring For the testdata worth $30$ points, each school ID is a single digit. For the testdata worth $50$ points, each school ID is strictly less than $1000$. For the testdata worth $80$ points, each school ID is strictly less than $10^9$. Translation source: GPT 4.1 mini. Translated by ChatGPT 5