History of Football

Time limit2sMemory limit64 MB

Problem

Henry is a historian who studies the history of sports, and of football in particular. Whenever he finds the standings table of a football tournament, he stores it in his database.

Recently he came across the standings of a small tournament. Unfortunately, the individual game results had been lost; the only surviving information was the number of points earned by each team.

Curious, he decides to work out in how many different ways the games of the tournament could have ended. He does not care about the exact scores of the games — only about who won each game.

The tournament followed these rules:

  • Each team plays against every other team exactly once.
  • If a game is a draw, each of the two teams earns 1 point.
  • Otherwise the winner earns 3 points and the loser earns 0 points.

For example, suppose there are 3 teams and each finished with 3 points. Then there are exactly two possible outcome tables:

TeamABCPoints
A-303
B0-33
C30-3
TeamABCPoints
A-033
B3-03
C03-3

Help Henry compute the number of different possible outcome tables, ignoring the exact scores of the games.

Input

The first line contains an integer $n$, the number of teams in the tournament ($2 \le n \le 8$). Each of the following $n$ lines contains one integer — the number of points earned by the corresponding team.

Output

Print one integer: the number of possible outcome tables that produce the given point totals. It is guaranteed that at least one such table exists.