Consider strings with rings at both ends. An integer is attached to each ring such that the
integers, say
and
which we denote by
, attached to the both ends of a string are different.
These pairs of integers identify the strings.
Two strings and
can be connected if one of
is equal to one of
, by tieing
them together at the rings with the same number. The result is called a chain. For example, a
chain
is obtained by connecting two strings
and
.
Similarly, a string and a chain, or two chains can be connected together at the rings with
the same integer. For example, a chain and a string
can be connected to produce
a chain
. From two chains
and
, a form looking like a cross (call it
for
later reference) can be obtained by tieing them at the center of each string. A form looking like
a ring (call it
) can be obtained from two strings
and
by connecting them at
both ends. In this way various forms can be obtained.
A part of such a form is called chain if it is a sequence of strings connected at their ends
with the property that no two rings with the same integer appear on it. For example,
contains
chains
, etc. of length 3, and
contains chains of length
4 such as
, where the length of a chain is the number of integers
on it.
Your task is to write a program to find the maximum length of possible chains.
Input
The first line of which contains an integer
, followed
by
lines containing two integers separated by a single space character. The
-st line
containing integers
and
represents a string whose ends are
rings with integers
and
.
Output
The output file should contain the maximum length.
Sample Input 1
7
1 3
3 4
1 4
2 7
5 7
6 7
1 7
Sample Output 1
5
Sample Input 2
6
1 2
2 3
3 4
4 5
1 5
2 6
Sample Output 2
6
Sample Input 3
7
1 3
2 4
3 5
4 6
6 7
2 6
4 7
Sample Output 3
4
Comments