A - Glutton Takahashi Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100100

問題文

高橋君は NN 個の料理を食べようとしています。

ii 番目に食べようとしている料理は、Si=S_i = sweet のとき甘い料理であり、Si=S_i = salty のとき塩辛い料理です。

高橋君は甘い料理を 22 つ連続で食べると気持ち悪くなってしまい、その後料理が食べられなくなってしまいます。

高橋君がすべての料理を食べることができるか判定してください。

制約

  • NN11 以上 100100 以下の整数
  • SiS_isweet または salty

入力

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

NN
S1S_1
S2S_2
\vdots
SNS_N

出力

高橋君がすべての料理を食べることができるならば Yes を、できないならば No を出力せよ。


入力例 1Copy

Copy
5
salty
sweet
salty
salty
sweet

出力例 1Copy

Copy
Yes

高橋君は甘い料理を 22 つ連続で食べることがないので、気持ち悪くなることなくすべての料理を食べることができます。


入力例 2Copy

Copy
4
sweet
salty
sweet
sweet

出力例 2Copy

Copy
Yes

高橋君は気持ち悪くなってしまいますが、すべての料理を食べることができます。


入力例 3Copy

Copy
6
salty
sweet
sweet
salty
sweet
sweet

出力例 3Copy

Copy
No

高橋君は 33 番目の料理を食べると気持ち悪くなってしまい、44 番目以降の料理が食べられなくなります。

Score : 100100 points

Problem Statement

Takahashi is planning to eat NN dishes.

The ii-th dish he plans to eat is sweet if Si=S_i = sweet, and salty if Si=S_i = salty.

If he eats two sweet dishes consecutively, he will feel sick and be unable to eat any more dishes.

Determine whether he can eat all the dishes.

Constraints

  • NN is an integer between 11 and 100100, inclusive.
  • Each SiS_i is sweet or salty.

Input

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

NN
S1S_1
S2S_2
\vdots
SNS_N

Output

Print Yes if Takahashi can eat all the dishes, and No otherwise.


Sample Input 1Copy

Copy
5
salty
sweet
salty
salty
sweet

Sample Output 1Copy

Copy
Yes

He will not eat two sweet dishes consecutively, so he can eat all the dishes without feeling sick.


Sample Input 2Copy

Copy
4
sweet
salty
sweet
sweet

Sample Output 2Copy

Copy
Yes

He will feel sick but can still eat all the dishes.


Sample Input 3Copy

Copy
6
salty
sweet
sweet
salty
sweet
sweet

Sample Output 3Copy

Copy
No

He feels sick when eating the 3rd dish and cannot eat the 4th and subsequent dishes.



2025-04-23 (Wed)
19:04:31 +00:00