Anomaly Mahjong 1
InterviewTime limit1sMemory limit1024 MB
Given a sequence of mahjong tiles, find the position of the first tile whose kind appears a fifth time, or print 0 if no kind reaches five.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
A tile (牌) in mahjong comes in 34 kinds, with 4 copies of each kind, for 136 tiles in total. The kinds are as follows.
You are placing mahjong tiles one by one, shuffled, to learn their shapes. You have not yet noticed one thing. Some tiles are undergoing an anomaly.
Each kind of tile has 4 copies in mahjong, but an anomalous tile changes its kind, so in some cases 5 or more tiles of the same kind can appear.
While you lay out the tiles, you must notice the anomaly and resolve it when 5 or more tiles of the same kind have appeared. Find the moment when you can notice the anomaly.
Input
The first line contains the number of tiles to lay out.
The second line contains the tiles in the order you place them, separated by spaces. Every tile in the input is one of the 34 kinds described above.
Output
Print if you can notice the anomaly after placing the -th tile. If you lay out every tile and still do not notice the anomaly, print 0 instead.