topic description
Zhang Bing and Wang Wu are backgammon fans, and they often play chess in their spare time. No, it's down again now. After walking for a while, the pawns were deployed, and I began to think about a line. The distribution of chess pieces on this line is as follows:
represented by an array: -1 0 1 1 1 0 1 0 1 -1
chess piece distribution description:
- -1 means white, 0 means empty, 1 means black
- Array length L, satisfying 1 < L < 40, L is an odd number
You have to help him write a program to calculate the most favorable position for the child. The most favorable definition:
- Find a vacancy (0) and fill the position with chess pieces (1/-1), which can increase the maximum continuous length of the current piece
- If there are multiple locations, return the coordinates of the smaller one closest to the middle
- If there is no feasible position, return -1 directly
- The continuous length cannot exceed 5 (backgammon constraints)
enter description
Line 1: current child color
Second line: current game state
output description
1 integer, indicating the array subscript of the sub-position
Example
enter | 1 -1 0 1 1 1 0 1 -1 1 |
output |