One magical night Patrik and Josip were talking about the number 42 and the meaning of life. They were interrupted by the famous lady voice in the tram: The next stop is Jordanovac. Patrik and Josip were distracted by this common sentence and started discussing:
Patrik: It is a very short ride between Joranovac and Maksimir, isn't it?
Josip: It is, but the ride between Mašićeva and Kvatrić is way shorter.
Patrik: Really? I disagree.
Josip: I wonder, which is the shortest ride between all stations?
Paula, a big public traffic transport, was carefully listening to their conversation. The problem of finding the shortest ride interested her so much that she stayed in the tram longer than she intended just to listen to their conversation.
At each station (except for the first one, when they entered the tram), one of the following two things happened:
- Patrik said: minutes have passed since we entered the tram
- Josip said: From station to this station minutes have passed
But before Paula could hear their conclusion about which ride was the shortest, they left the tram! Luckily, Paula remembers all their statements. Now she needs your help! Help her find the duration of the shortest ride and between which two stations the tram drove on that ride.
Input Specification
The first line contains the integer , the number of tram stations.
The -th of the following lines contains the information about station in one of the following formats:
- Patrik – Duration of the ride between station and station is
- Josip – Duration of the ride between station and station is
Every station will be in a distinct position.
Output Specification
In one line, output three numbers: , , , the duration of the shortest ride and the indices of the starting and ending stations of that ride.
If multiple solutions exist, print the one with the smallest indices of the stations.
Constraints
Subtask | Points | Constraints |
---|---|---|
Every sentence was said by Patrik. | ||
No additional constraints. |
Sample Input 1
4
Patrik 3
Patrik 5
Josip 1 7
Sample Output 1
2 2 3
Explanation for Sample Output 1
The tram drove for minutes from the first to the second station and from the first to the third. We can conclude that from the second to the third station, it took minutes, which is the shortest ride.
Sample Input 2
2
Josip 1 5
Sample Output 2
5 1 2
Sample Input 3
5
Patrik 4
Josip 2 4
Josip 2 6
Josip 4 2
Sample Output 3
2 3 4
Explanation for Sample Output 3
The ride between the fourth and fifth station is also minutes but because they have greater indices,
only the 2 3 4
solution is accepted.
Comments