Jurassic Remains

No attempts yetTime limit1sMemory limit128 MB

Problem

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:

  • The labels are not all distinct. Only the capital letters 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.
  • The same labels were also used to tag the extra loose bones, so some labeled joints do not need to be connected to anything. Fortunately, on any single bone each letter appears on at most one joint.

Help the museum reconstruct a skeleton fragment. Choose a set of bones that can be joined so that all of the following hold:

  • Two joints may be connected only if they carry the same label.
  • For every chosen bone, each of its labeled joints is connected to some other joint.
  • The number of chosen bones is as large as possible.

Two bones may be joined through several joints at once.

Input

The first line contains an integer NN --- the number of bones (1N241 \le N \le 24). Each of the next NN lines contains one bone: a non-empty string of distinct capital letters listing the labels on that bone's joints.

Output

Print a single integer LL --- the largest number of bones that can be used together to reassemble a skeleton fragment. If no bones can be used, print 00.