P23721 [AtCoder] [ABC025B] Twins and Watermelon Splitting
入门
题目描述

Problem Description

Naota and Naoko are twins. Today, they decided to practice splitting watermelons in the hallway of their house.

The hallway is infinitely long in the east-west direction, with Naota's room entrance at one point. Initially, Naota and Naoko are standing in front of Naota's room.

In the practice of splitting watermelons, they will perform the following N moves in sequence:

  • The i-th move: First, Naoko specifies a direction and a distance in meters, \( d_i \). The direction can be either east or west, and \( d_i \) is a positive integer. Then, Naota will face the specified direction and move the specified distance \( d_i \).

Naota has difficulty moving less than \( A \) meters or more than \( B \) meters in one move. Therefore, the final moving distance when the target distance is \( d_i \) meters is as follows:

  • When \( d_i < A \), Naota moves \( A \) meters in the facing direction.
  • When \( A \leq d_i \leq B \), Naota moves \( d_i \) meters in the facing direction.
  • When \( d_i > B \), Naota moves \( B \) meters in the facing direction.

Your task is to determine where Naota will be after completing the N moves.

Input Format

The input is given from the standard input in the following format:

\( N \) \( A \) \( B \) \( s_1 \) \( d_1 \) \( s_2 \) \( d_2 \) : \( s_N \) \( d_N \)

  • The first line contains three integers \( N \) ( \( 1 \leq N \leq 100 \) ), \( A \), and \( B \) ( \( 1 \leq A \leq B \leq 100 \) ) separated by spaces.
  • The next \( N \) lines contain the movement information. The i-th line ( \( 1 \leq i \leq N \) ) contains a string \( s_i \) and an integer \( d_i \) ( \( 1 \leq d_i \leq 100 \) ) separated by spaces. The string \( s_i \) is either East or West, indicating the direction specified by Naoko, which is either east or west, respectively.

Output Format

  • When Naota's final position is \( X \) ( \( 1 \leq X \)) meters east of his room, output the string East and \( X \) in this order separated by a space in one line.
  • When Naota's final position is \( X \) ( \( 1 \leq X \)) meters west of his room, output the string West and \( X \) in this order separated by a space in one line.
  • When Naota's final position is the same as his room, output the integer \( 0 \) in one line.

In all cases, include a newline at the end of the output.

Sample Input and Output

Sample Input #1

3 5 10
East 7
West 3
West 11

Sample Output #1

West 8

Sample Input #2

3 3 8
West 6
East 3
East 1

Sample Output #2

0

Sample Input #3

5 25 25
East 1
East 1
West 1
East 100
West 1

Sample Output #3

East 25

Notes/Hints

Sample Explanation 1

  • In the first move, Naoko specifies 7 meters east. Naota moves 7 meters east, so he is 7 meters east of his room.
  • In the second move, Naoko specifies 3 meters west. Naota moves 5 meters west, so he is 2 meters east of his room.
  • In the third move, Naoko specifies 11 meters west. Naota moves 10 meters west, so he is 8 meters west of his room.
  • Finally, Naota is 8 meters west of his room.

Sample Explanation 2

  • In this example, Naota ends up at the same position as his room.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 5 10 East 7 West 3 West 11
样例输出
West 8