spoj#PEGS. Triangle

Triangle

.center-text-container { text-align: center; } .center-text-container > * { display: inline-block; } .example-table { text-align: left; margin-top: 10px; width: 100%; } .example-table td { vertical-align: top; } .section { margin-top: 19px; margin-bottom:19px; } .paragraph { text-align: left; margin-top: 10px; margin-bottom: 10px; } .paragraph ul, .paragraph ol { margin-top: 3px; margin-bottom: 3px; }

Description

Consider the following common single-player game.
A board has fifteen holes, arranged in a triangular pattern. Pegs fit in these holes.
A valid move is to take a peg and jump in a straight line over an adjacent peg to the an empty hole two positions away from the starting position. The peg that was jumped is removed from the board. The player wins the game when there is only one peg remaining.
For example, in the game below, the player wins in two moves.
    x             .            .
   x .           . .          . .
  . . .   =>    x . .   =>   . . .
 . x . .       . x . .      . . . .
. . . . .     . . . . .    . . x . .
In the game below, the player has no possible moves and loses.
    x
   . .
  x . .
 . . . .
. . . . .
Given a starting position, determine if it is possible to win.

Input

The first line is N, the number of starting pegs (0 < N < 15).
The next N lines are the pegs' positions. The positions on the board are numbered as following:
        1
      2   3
    4   5   6
  7   8   9  10
11  12  13  14  15
Input Input Input
3
1
2
8
14
2
3
4
5
6
7
8
9
10
11
12
13
14
15
13
2
3
13
5
8
11
10
9
12
4
14
15
13
Output Output Output
yes
yes
yes