B - Go Straight and Turn Right Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

xy 平面を考えます。x 軸の正の向きを東向き、y 軸の正の向きを北向きとします。
高橋君ははじめ、点 (x, y) = (0, 0) にいて東( x 軸の正の向き)を向いています。

SR のみからなる長さ N の文字列 T = t_1t_2\ldots t_N が与えられます。 高橋君は i = 1, 2, \ldots, N の順番で下記を行います。

  • t_i = S ならば、高橋君はいま向いている方向に距離 1 だけ進む。
  • t_i = R ならば、高橋君はその場で右に 90 度回転する。その結果、高橋君の向いている方向が下記の通りに変わる。
    • 回転前の向きが東向き( x 軸の正の向き)ならば、回転後の向きは南向き( y 軸の負の向き)になる。
    • 回転前の向きが南向き( y 軸の負の向き)ならば、回転後の向きは西向き( x 軸の負の向き)になる。
    • 回転前の向きが西向き( x 軸の負の向き)ならば、回転後の向きは北向き( y 軸の正の向き)になる。
    • 回転前の向きが北向き( y 軸の正の向き)ならば、回転後の向きは東向き( x 軸の正の向き)になる。

上記の手順を終えた後に高橋君がいる点の座標を出力してください。

制約

  • 1 \leq N \leq 10^5
  • N は整数
  • TSR のみからなる長さ N の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
T

出力

問題文中の手順を終えた後に高橋君がいる点の座標 (x, y) を、下記の形式にしたがって空白区切りで出力せよ。

x y

入力例 1

4
SSRS

出力例 1

2 -1

高橋君ははじめ (0, 0) にいて東を向いています。その後、高橋君は下記の通りに行動します。

  1. t_1 = S であるので、高橋君は東に距離 1 だけ進んだ (1, 0) に移動します。
  2. t_2 = S であるので、高橋君は東に距離 1 だけ進んだ (2, 0) に移動します。
  3. t_3 = R であるので、高橋君は右に 90 度回転し、高橋君は南を向きます。
  4. t_4 = S であるので、高橋君は南に距離 1 だけ進んだ (2, -1) に移動します。

よって、高橋君の最終的な位置である (x, y) = (2, -1) を出力します。


入力例 2

20
SRSRSSRSSSRSRRRRRSRR

出力例 2

0 1

Score : 200 points

Problem Statement

Consider an xy-plane. The positive direction of the x-axis is in the direction of east, and the positive direction of the y-axis is in the direction of north.
Takahashi is initially at point (x, y) = (0, 0) and facing east (in the positive direction of the x-axis).

You are given a string T = t_1t_2\ldots t_N of length N consisting of S and R. Takahashi will do the following move for each i = 1, 2, \ldots, N in this order.

  • If t_i = S, Takahashi advances in the current direction by distance 1.
  • If t_i = R, Takahashi turns 90 degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.
    • If he is facing east (in the positive direction of the x-axis) before he turns, he will face south (in the negative direction of the y-axis) after he turns.
    • If he is facing south (in the negative direction of the y-axis) before he turns, he will face west (in the negative direction of the x-axis) after he turns.
    • If he is facing west (in the negative direction of the x-axis) before he turns, he will face north (in the positive direction of the y-axis) after he turns.
    • If he is facing north (in the positive direction of the y-axis) before he turns, he will face east (in the positive direction of the x-axis) after he turns.

Print the coordinates Takahashi is at after all the steps above have been done.

Constraints

  • 1 \leq N \leq 10^5
  • N is an integer.
  • T is a string of length N consisting of S and R.

Input

Input is given from Standard Input in the following format:

N
T

Output

Print the coordinates (x, y) Takahashi is at after all the steps described in the Problem Statement have been completed, in the following format, with a space in between:

x y

Sample Input 1

4
SSRS

Sample Output 1

2 -1

Takahashi is initially at (0, 0) facing east. Then, he moves as follows.

  1. t_1 = S, so he advances in the direction of east by distance 1, arriving at (1, 0).
  2. t_2 = S, so he advances in the direction of east by distance 1, arriving at (2, 0).
  3. t_3 = R, so he turns 90 degrees clockwise, resulting in facing south.
  4. t_4 = S, so he advances in the direction of south by distance 1, arriving at (2, -1).

Thus, Takahashi's final position, (x, y) = (2, -1), should be printed.


Sample Input 2

20
SRSRSSRSSSRSRRRRRSRR

Sample Output 2

0 1