Open Problem
To help HKOI 2010 finalists get familiar with the input and output requirements of the final event, an "open question" is listed here. This question will reappear in HKOI 2010 Final Event with slight modifications.
Contestants are advised to practise the problem before the competition so as to understand how to read from standard input and write to standard output in Pascal, C or C++. Please pay particular attention to the strict requirements in output format in the competition.
Outputs of ALL HKOI Final questions should comply with the following rules:
- Output data should be formatted EXACTLY as described in the question.
- Each line, including the last output line, must be ended with a new-line character.
- Characters immediately preceding a new-line character must not be white spaces (i.e. no trailing spaces in a line).
- There should not be any additional line(s) (including but not limited to empty line with just a new-line character) after the last output line (i.e. no trailing lines in the output).
Problem Description
Sample Solution
Examples of incorrect solutions
- Incorrect solution 1 (0 marks)
- Incorrect solution 2 (0 marks)
- Incorrect solution 3 (0 marks)
- Incorrect solution 4 (45 marks)
Advice for C++ users
This year all input and output are done via standard input and standard output. Note that using cin and cout in <iostream> for reading input and writing output are very slow, especially when the program needs to accept a large amount of input or write a large amount of output. The program may even not have enough time to read all input within the runtime limit. Therefore C++ users are advised NOT to use cin for input and cout for output. Those users may use C-style scanf and printf in <cstdio> instead, as illustrated below:

