eolymp
bolt
Try our new interface for solving problems
Problems

Triangle

Triangle

An equilateral triangle with side n can be split into n2 unit triangles as shown on picture (a):

prb8507.gif

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 (1n5). The second line contains four non-negative integers n1, n2, n3 and n4, 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 n1 + n2 + n3 + n4 = n2.

Output

Output the sought number of correct colored equilateral triangles.

Time limit 1 second
Memory limit 256 MiB
Input example #1
2
0 1 0 3
Output example #1
3
Input example #2
2
1 1 1 1
Output example #2
12
Source 2007 Петрозаводск, Petr Mitrichev Contest 2, Январь 30, Задача D