atcoder#AGC016B. [AGC016B] Colorful Hats
[AGC016B] Colorful Hats
Score : points
Problem Statement
There are cats. We number them from through .
Each of the cats wears a hat. Cat says: "there are exactly different colors among the hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print Yes
if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No
otherwise.
3
1 2 2
Yes
For example, if cat , and wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.
3
1 1 2
No
From the remark of cat , we can see that cat and wear hats of the same color. Also, from the remark of cat , we can see that cat and wear hats of the same color. Therefore, cat and wear hats of the same color, which contradicts the remark of cat .
5
4 3 4 3 4
No
3
2 2 2
Yes
4
2 2 2 2
Yes
5
3 3 3 3 3
No