

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
人が一列に並んでいます。列の状態は長さ の文字列 で与えられ、前から 番目の人は の 文字目が M
のとき男性、F
のとき女性です。
男女が交互に並んでいるかどうか判定してください。
男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在しないとき、かつ、そのときに限り、男女が交互に並んでいるといいます。
制約
- は整数である
- は
M
およびF
のみからなる長さ の文字列である
入力
入力は以下の形式で標準入力から与えられる。
出力
男女が交互に並んでいるとき Yes
、そうでないとき No
と出力せよ。
入力例 1Copy
6 MFMFMF
出力例 1Copy
Yes
男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在せず、男女が交互に並んでいます。
入力例 2Copy
9 FMFMMFMFM
出力例 2Copy
No
入力例 3Copy
1 F
出力例 3Copy
Yes
Score : points
Problem Statement
There is a row of people. They are described by a string of length . The -th person from the front is male if the -th character of 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
- is an integer.
- is a string of length consisting of
M
andF
.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if the men and women are alternating, and No
otherwise.
Sample Input 1Copy
6 MFMFMF
Sample Output 1Copy
Yes
There is no position where two men or two women are adjacent, so the men and women are alternating.
Sample Input 2Copy
9 FMFMMFMFM
Sample Output 2Copy
No
Sample Input 3Copy
1 F
Sample Output 3Copy
Yes