P24967 [AtCoder] [ARC039C] Kindergarten Child Takahashi
提高
题目描述

Problem Description

An infinite two-dimensional grid extends infinitely. The coordinates of a grid point that is $ x $ to the right and $ y $ upwards from the origin $ (0,0) $ are represented as $ (x,y) $.

Kindergarten child Takahashi loves to move around freely on this grid. However, due to his overly spontaneous movements, he got lost. The following actions of Takahashi are known from the investigation:

  • Initially, Takahashi was at $ (0,0) $.
  • Takahashi chooses a direction (up, down, left, right) and moves straight in that direction until he steps on a grid point that he has not visited before. Once he steps on an unvisited grid point, he stops.
  • Then, Takahashi repeats the above operation until he gets tired and falls asleep at that grid point.

As a guardian, you have learned that Takahashi decided on a direction and moved straight exactly $ K $ times, and you know the direction he chose at each point. You decided to write a program to pinpoint the location where Takahashi is sleeping.

Input Format

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

$ K $ $ S_1S_2S_3…S_K $

  • The first line contains an integer $K\ (1≦K≦200,000)$, which represents the number of times Takahashi moved.
  • The second line contains $ K $ characters of information representing Takahashi's movement. The $ i(1≦i≦K) $ -th character $ S_i $ indicates the direction he moved in the $ i $ -th move. $ S_i $ being L, R, U, D respectively means he moved left, right, up, or down in the $ i $ -th move.

Output Format

Output should be done to the standard output in the following format:

The first line should contain two integers $ x,y $, which represent the coordinates $ (x,y) $ of the location where Takahashi is sleeping.

Do not forget the newline at the end.

Sample Input and Output

Sample Input #1

3
RLU

Sample Output #1

-1 1

Sample Input #2

7
RURDRUL

Sample Output #2

0 1

Sample Input #3

25
RLRLRLRLRLRLURLRLRLRLRLRL

Sample Output #3

-12 1

Notes/Hints

Sample Explanation 1

Listing the grid points where Takahashi stopped, including the starting point, in order gives $ (0,0)→(1,0)→(-1,0)→(-1,1) $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 RLU
样例输出
-1 1