In the event of technical difficulties with Szkopuł, please contact us via email at email@example.com.
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
A genetic code of the abstract primitivus (Primitivus recurencis) is a series of natural numbers . A feature of primitivus we call each ordered pair of numbers , which appears successively in the genetic code, i.e. there exists such that , . There are no features in a primitivus' genetic code.
Write a program which:
In the first line of the standard input one positive integer number is written. It is the number of different features of the primitivus. In each of the following lines there is a pair of natural numbers and separated by a single space, , . A pair is one of the primitivus' features. The features do not repeat in the input file.
Your program should write, in the first and only line of the standard output, exactly one integer number equal to the length of the shortest genetic code of the primitivus, comprising the features from the input.
For the input data:
12 2 3 3 9 9 6 8 5 5 7 7 6 4 5 5 1 1 4 4 2 2 8 8 6
the correct result is:
All the features from the sample input are written in the following genetic code: (8, 5, 1, 4, 2, 3, 9, 6, 4, 5, 7, 6, 2, 8, 6).
Task author: Wojciech Rytter.