A - Alternately Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100100

問題文

NN 人が一列に並んでいます。列の状態は長さ NN の文字列 SS で与えられ、前から ii 番目の人は SSii 文字目が M のとき男性、F のとき女性です。

男女が交互に並んでいるかどうか判定してください。

男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在しないとき、かつ、そのときに限り、男女が交互に並んでいるといいます。

制約

  • 1N1001 \leq N \leq 100
  • NN は整数である
  • SSM および F のみからなる長さ NN の文字列である

入力

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

NN
SS

出力

男女が交互に並んでいるとき Yes、そうでないとき No と出力せよ。


入力例 1Copy

Copy
6
MFMFMF

出力例 1Copy

Copy
Yes

男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在せず、男女が交互に並んでいます。


入力例 2Copy

Copy
9
FMFMMFMFM

出力例 2Copy

Copy
No

入力例 3Copy

Copy
1
F

出力例 3Copy

Copy
Yes

Score : 100100 points

Problem Statement

There is a row of NN people. They are described by a string SS of length NN. The ii-th person from the front is male if the ii-th character of SS is M, and female if it is F.

Determine whether the men and women are alternating.

It is said that the men and women are alternating if and only if there is no position where two men or two women are adjacent.

Constraints

  • 1N1001 \leq N \leq 100
  • NN is an integer.
  • SS is a string of length NN consisting of M and F.

Input

The input is given from Standard Input in the following format:

NN
SS

Output

Print Yes if the men and women are alternating, and No otherwise.


Sample Input 1Copy

Copy
6
MFMFMF

Sample Output 1Copy

Copy
Yes

There is no position where two men or two women are adjacent, so the men and women are alternating.


Sample Input 2Copy

Copy
9
FMFMMFMFM

Sample Output 2Copy

Copy
No

Sample Input 3Copy

Copy
1
F

Sample Output 3Copy

Copy
Yes


2025-04-02 (Wed)
20:27:37 +00:00