You exchange text messages with your friends. You receive so many messages that you want to measure how long your friends wait for your replies.
Your device logs every message you receive and every message you send, in order, using two kinds of entries.
R X: a message arrived from the friend numbered X.S X: a message was sent to the friend numbered X.Messages travel instantly. Between two consecutive entries of the kind above, exactly one of the following holds.
W X entry sits between them, and they happen X seconds apart.The rules of message etiquette are always obeyed.
The wait time of a message is the time that passes from the moment it arrives to the moment you reply to it. If every message from friend X received a reply, the total wait time for friend X is the sum of the wait times of those messages. If even one message from friend X went unanswered, the total wait time for friend X is -1.
Compute the total wait time for each friend.
The first line contains the integer M (1≤M≤20). Each of the next M lines contains one character (W, R, or S), a single space, and an integer X (1≤X≤100). Those M lines are the entries described above, given in the order they happened.
For each friend who sent a message, print one line in the form X T, where X is the friend number and T is the total wait time for that friend. Print the lines in increasing order of friend number.
In the first example, friend 2 sends a message at second 0 and friend 3 sends a message at second 1. Friend 2 gets a reply at second 6 and friend 3 gets a reply at second 7.
In the second example, the message from friend 12 arrives at second 0 and is answered at second 13. Friend 23 sends two messages, the first with a wait time of 6 seconds and the second with a wait time of 2 seconds. The message from friend 34 arrives at second 12 and is answered at second 14. The last message from friend 45 never gets a reply.