CF893A.Chess For Three

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.

So they play with each other according to following rules:

  • Alex and Bob play the first game, and Carl is spectating;
  • When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.

Alex, Bob and Carl play in such a way that there are no draws.

Today they have played nn games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!

输入格式

The first line contains one integer nn ( 1<=n<=1001<=n<=100 ) — the number of games Alex, Bob and Carl played.

Then nn lines follow, describing the game log. ii -th line contains one integer aia_{i} ( 1<=ai<=31<=a_{i}<=3 ) which is equal to 11 if Alex won ii -th game, to 22 if Bob won ii -th game and 33 if Carl won ii -th game.

输出格式

Print YES if the situation described in the log was possible. Otherwise print NO.

输入输出样例

  • 输入#1

    3
    1
    1
    2
    

    输出#1

    YES
    
  • 输入#2

    2
    1
    2
    

    输出#2

    NO
    

说明/提示

In the first example the possible situation is:

  1. Alex wins, Carl starts playing instead of Bob;
  2. Alex wins, Bob replaces Carl;
  3. Bob wins.

The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.

首页