Peterson Polyglot
Time limit2sMemory limit512 MB
Given a trie of words, find the position p whose letter, deleted from every long word, leaves the smallest trie, and print that trie's size.
Problem
Peterson loves to learn new languages, but his favorite hobby is making new ones. A language is a set of words, and a word is a sequence of lowercase Latin letters.
Peterson makes a new language every morning. Storing a whole language is hard, so Peterson invented a data structure called a broom to store them. A broom is a rooted tree whose edges are marked with letters. Initially the broom is a single vertex, the root. To add a new word, Peterson starts at the root and processes the letters one by one. Suppose Peterson is at vertex . If there is an edge from marked with the current letter, he follows that edge. Otherwise he adds a new edge from to a new vertex , marks it with the current letter, and follows the new edge. The size of a broom is the number of its vertices.
In the evening, Peterson cannot understand the language he made that morning. It is too difficult, so he tries to simplify it. Simplifying a language means erasing some letters from some of its words. Formally, Peterson picks a positive integer and erases the -th letter from every word whose length is at least . Letters are indexed starting from 1. The simplification must change at least one word, so at least one word must have length at least . Peterson wants the simplified language to have the smallest possible broom, so he chooses to minimize the size of the resulting broom.
Help Peterson find the smallest possible broom size and the integer to choose. If several values of give the minimum, print the smallest one.
Input
The first line contains an integer (), the size of the broom. Each of the next lines contains integers , and a letter , describing an edge from to marked with . Vertices are numbered from 1 to , and vertex 1 is the root. Every is a lowercase Latin letter. The edges describe a valid broom built from Peterson's language.
Output
The first line contains the minimum possible size of the broom after simplification. The second line contains the integer to choose. If several suitable values of exist, print the smallest one.
Constraints
Let the language consist of words . Let be the total length of the words, that is, . Let be the maximum word length, that is, .
Hints

The broom for the language in the second test case can be built from the words "piece", "of", "pie", "pretty", and "prefix". Simplifying it with gives the words "pece", "o", "pe", "petty", and "pefix". This language gives the broom with the smallest possible size.