Paleontologists in Siberia recently unearthed many fragments of a Jurassic-period dinosaur skeleton and want to ship them to a paleontology museum. The dinosaur was so huge that no available box could hold the fragments, so the team detached the skeleton into separate bones to be reassembled at the museum. To make reassembly easier, every joint where two bones had been connected was tagged with a label.
While packing, several additional loose bones were discovered and added to the same package before it was shipped.
When the package arrived, two complications surfaced:
A to Z are used. Two joints that must be connected always share the same letter, but several different pairs of joints may carry that same letter.Help the museum reconstruct a skeleton fragment. Choose a set of bones that can be joined so that all of the following hold:
Two bones may be joined through several joints at once.
The first line contains an integer N --- the number of bones (1≤N≤24). Each of the next N lines contains one bone: a non-empty string of distinct capital letters listing the labels on that bone's joints.
Print a single integer L --- the largest number of bones that can be used together to reassemble a skeleton fragment. If no bones can be used, print 0.