406819: GYM102565 H Shopping Bags
Description
Since Jimmy and Johnny are not allowed to leave their home, they have created a game out of boredom, but because they didn't have many things to play with in the house, they have used shopping bags. An interesting property of shopping bags is that they can fit inside other bags which can fit inside others and so on. So the 2 kids have used N bags, indexed from 1 to N, deciding for each one whether to put it in another bag or not.
After finishing the slow process of putting bags inside each other, the kids can start playing. They take turns, Jimmy being the first one to make a move. In a move, a kid can choose a bag that is still in the game and remove it together with all the bags inside it out of the game. The loser is the player that has no more bags to choose from when it is his turn.
Jimmy is a very competitive player, so he needs your help to tell him if, for a certain configuration of bags, he has a safe winning strategy or not.
InputThe first line of the input will contain one positive integer $$$N$$$ ($$$1 \leq N \leq 1000$$$) that represents the number of shopping bags.
The next line will contain $$$N$$$ integers $$$b_1,b_2,b_3,...,b_n$$$, where $$$b_i$$$ ($$$0 \leq b_i \leq N$$$) represents the bag that the $$$i^{th}$$$ bag is directly inside in. If $$$b_i$$$ is equal to $$$0$$$ that means that the $$$i^{th}$$$ bag isn't inside any other bag.
OutputThe output should be either $$$YES$$$ if Jimmy has a safe winning strategy or $$$NO$$$ if he doesn't.
ExamplesInput5 0 1 2 3 4Output
YESInput
6 0 1 2 2 0 5Output
NOInput
5 0 1 1 0 4Output
YESNote
In the first example Jimmy can choose to take out bag number $$$1$$$ as his first move, making Johnny lose.
In the second example, if Johnny plays optimal, Jimmy will lose no matter what his strategy is.
In the third example, Jimmy has a safe winning strategy.