402652: GYM100834 A Polycarp and Digits
Description
Polycarp decided to get into the maze. The maze consists of N rooms connected by N - 1 corridors. In the beginning he is in the room 1, from which he can go to any other. While being in one of the rooms he tries to go to the one where he hasn't been yet. If there are no such rooms, Polycarp goes to the room where he came from or exits from the maze if he is in the room 1 and visited all other rooms. In each room there is an integer. Polycarp defined that in the room i recorded the number ai, repeated bi times. For example, if ai equal to 123 and bi equal to 3, the number will look like 123123123. Every time visiting another room, Polycarp writes the number specified number of times to his notepad. Besides it is considered that in the beginning Polycarp visits room 1. Therefore, he gets one more integer c, composed from all written numbers to the notepad. Polycarp is interested in all subsequences of the consecutive identical digits. Among these subsequences he chooses those who have the greatest length, and among the he chooses the one that is composed of the least digit. He needs to determine from what minimum digit and maximum length it is possible to construct such a subsequence.
InputThe first line contains integer N — the number of rooms. 1 ≤ N ≤ 100000. The following N lines contain pairs of integers separated by spaces: ai and bi. 1 ≤ ai ≤ 100 000, 1 ≤ bi ≤ 1000. In next N - 1 lines there are pairs of integers fi и ti — description of the corridors. Corridor i connects room fi with room ti. Polycarp checks the unvisited rooms in a sequence, written in the input file.
OutputIn the first line print two numbers — the minimal digit that appears sequentially more often in c, and how many times it occurs.
ExamplesInput3Output
11211 1
11111 1
11111 1
1 2
1 3
1 9Input
3Output
3 1
3 3
3 7
1 2
1 3
3 13