Triangle
An equilateral triangle with side n can be split into n^2
unit triangles as shown on picture (a):
Each unit triangle can be colored with two colors in four different ways (numbered from 1 to 4), shown on picture (b). A colored equilateral triangle with side n can then be assembled from colored unit triangles in many different ways. A colored equilateral triangle is correct if the neighboring sides of adjacent unit triangles have the same color. Such triangles form beautiful pictures like picture (c).
You are to find the number of different correct colored equilateral triangles that can be assembled from a given set of unit triangles. You're allowed to rotate unit triangles arbitrarily, however, the position of the big triangle is fixed (i.e., the colorings that are rotations of each other are considered different).
Input
The first line contains an integer n (1 ≤ n ≤ 5). The second line contains four non-negative integers n[1]
, n[2]
, n[3]
and n[4]
, denoting the amounts of available unit triangles of kinds 1, 2, 3 and 4 respectively (as shown on picture (b)). It is always true that n[1]
+ n[2]
+ n[3]
+ n[4]
= n^2
.
Output
Output the sought number of correct colored equilateral triangles.