Under construction

Still being built. Things may change

Connect3

Time limit0.5sMemory limit512 MB

Summary
Given Black's opening column x and White's winning square (a,b), count final 4x4 board states where White's move there completes three in a row first.
Level

Medium5 of 10

Topics
Backtracking, Simulation, Implementation
Solved
No attempts yet

Problem

Connect3 is a simplified version of Connect4. Two players, black and white, take turns putting stones of their own color on a 4×44 \times 4 board. Each square is written as (a,b)(a, b), where aa is the row and bb is the column. The lower left square is (1,1)(1, 1) and the upper right square is (4,4)(4, 4).

On a turn a player chooses a column, and the stone falls to the lowest empty square of that column. Square (3,1)(3, 1) can be taken only after (2,1)(2, 1) and (1,1)(1, 1) are occupied.

(4, 1)(4, 2)(4, 3)(4, 4)
(3, 1)(3, 2)(3, 3)(3, 4)
(2, 1)(2, 2)(2, 3)(2, 4)
(1, 1)(1, 2)(1, 3)(1, 4)

The board of Connect3. Each square is written as (a,b)(a, b) with row aa and column bb.

The game ends the moment three stones of the same color stand next to each other in a row, in a column, or on a diagonal, and the player of that color wins. While no such triple exists, play goes on.

Black moves first and puts a stone on square (1,x)(1, x). After that white and black alternate. The game ends when white puts a stone on square (a,b)(a, b), so the white stone on (a,b)(a, b) is the one that completes three white stones in a line. Let ss be the board at that moment. Count how many different boards ss are possible. The order in which the stones were placed does not matter, so two boards are the same only when every square holds the same thing, a black stone, a white stone, or nothing. If no game can end this way, the answer is 0.

Input

The first line has one integer xx (1≤x≤41 \le x \le 4), the column of the first stone, which black puts on square (1,x)(1, x).

The second line has two integers aa and bb (1≤a≤41 \le a \le 4, 1≤b≤41 \le b \le 4), the square (a,b)(a, b) where the last stone of the game is put.

Output

Print one integer, the number of different final boards ss.

Examples2

  1. Example 1

    Input
    2
    2 3
    
    Expected output
    516
    
  2. Example 2

    Input
    3
    4 4
    
    Expected output
    177