Wait Time

No attempts yetTime limit1sMemory limit256 MB

Problem

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 XX.
  • S X: a message was sent to the friend numbered XX.

Messages travel instantly. Between two consecutive entries of the kind above, exactly one of the following holds.

  • A single W X entry sits between them, and they happen XX seconds apart.
  • Nothing sits between them, and they happen one second apart.

The rules of message etiquette are always obeyed.

  • Every message you send is a reply to a message you already received.
  • You send at most one reply to any single message from a friend.
  • A friend does not send another message until you reply to the previous one.

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 XX received a reply, the total wait time for friend XX is the sum of the wait times of those messages. If even one message from friend XX went unanswered, the total wait time for friend XX is -1.

Compute the total wait time for each friend.

Input

The first line contains the integer MM (1M201 \le M \le 20). Each of the next MM lines contains one character (W, R, or S), a single space, and an integer XX (1X1001 \le X \le 100). Those MM lines are the entries described above, given in the order they happened.

Output

For each friend who sent a message, print one line in the form X T, where XX is the friend number and TT is the total wait time for that friend. Print the lines in increasing order of friend number.

Hint

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.