405334: GYM101908 D Unraveling Monty Hall

Memory Limit:1024 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Unraveling Monty Halltime limit per test0.5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

On the stage of an auditorium program there are three closed doors: door 1, door 2 and door 3. Behind one of these doors there is a car and behind the other two doors there is a goat. The production of the program randomly chooses the door where the car is without cheating. Only the host of the program knows where the car is. He asks the player to choose one of the doors. We can see that, because there is only one car, and at at least one of the two doors that the player did not choose, there has to be a goat!

Therefore, the presenter can always do the following: between the two doors that the Player did not choose, he opens one that has a goat, so that the player and the spectators can see the goat. The presenter now asks: "Do you want to change your door to the other door that is still closed?". Is it a beneficial change or not? The player wants to stay with the door that has the car, of course!

Paulinho saw a rigorous demonstration that the odds of the car being behind door the player chose initially is $$$\frac{1}{3}$$$ and the odds of the car being behind the other door which is still closed and the player did not choose initially is $$$\frac{2}{3}$$$ and therefore the exchange is advantageous. Paulinho doesn't conform, his intuition tells him that either way, the probability is $$$\frac{1}{2}$$$ for both doors still closed.

To bring this matter to an end, let's simulate this game thousands of times and count how many times the player won the car. We will assume that:

  • The player picks door 1 initially;
  • The player always changes doors after the presenter reveals a goat by opening one of the two doors that were not initially selected.

In these conditions, in a game, given the number of the door that contains the car, we can know exactly whether the player will win the car or not.

Input

The first line of the input contains an integer $$$N$$$ ($$$1 \leq N \leq 10^4$$$), indicating the number of games in the simulation. Each of the $$$N$$$ following rows contains an integer: 1, 2 or 3; representing the door number containing the car in that game.

Output

Your program must produce a single line containing an integer representing the number of times the player won the car in this simulation, assuming that he always chooses the door 1 and always switch doors after the host reveals a goat by opening one of the two doors that were not initially selected.

ExamplesInput
5
1
3
2
2
1
Output
3
Input
1
1
Output
0
Input
15
3
2
3
1
1
3
3
2
2
1
2
3
2
1
1
Output
10

加入题单

算法标签: