33OJ
登录 注册

#P17680. [IO 2025 #2] 米沙与斯韦塔

[IO 2025 #2] 米沙与斯韦塔

Problem Description

Misha and Sveta got into the Ugabuga Institute of Technology™ and, like real university students, moved into dormitory No. 52. The two are good friends, so the dormitory management allowed them to live in adjacent rooms separated by a single wall. They happily ran into their rooms, only to be surprised: a long steel pillar was sticking out of the wall between them. Neither Misha nor Sveta liked this interior design, so they took ridiculously huge hammers out of their suitcases and started hammering the pillar, trying to drive it completely into the wall.

The two hammer from opposite sides of the wall, so this turns into a contest: who can push the pillar toward the other side, and farther? Each hit moves the pillar by a given distance in the direction away from the person who hits it. Determine who wins in the end, and how far the winner has moved the pillar away from themselves relative to its initial position.

Input Format

The first line contains an integer nn, the total number of hits, with 1≤n≤1051\le n\le 10^5.

The next nn lines describe the hits in the order they happen. Each line contains the first letter of the hitter's name and an integer kk, separated by a space: M stands for Misha and S stands for Sveta; kk is the distance the pillar moves due to this hit, with 1≤k≤1091\le k\le 10^9.

Output Format

If the final position of the pillar differs from its initial position, output on one line the first letter of the winner's name (M or S) and the distance the pillar has moved away from the winner relative to its initial position, separated by a space.

If the pillar ends up back at its initial position, output only 0.

5
M 5
M 10
S 3
M 10
S 3
M 19

Hint

Translated by QwenWork