Malevich's Frames
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
The author of the famous painting "Black Square", Kazimir Malevich, is pondering over his new creation. This time his attention was drawn to puzzles — a puzzle game that looks like a mosaic that needs to be assembled from separate fragments. Therefore, Kazimir took one of the replicas of his famous painting and cut many separate puzzles out of its frame (and therefore all the puzzles turned out to be equally black). There are seven types of puzzles, which are shown to you in the picture below. Each side is convex, concave, or flat. By connecting a concave and a convex side from different puzzles, you connect them together.
Kazimir is wondering how many numbers \(n \ge 3\) exist such that a square frame of size \(n\) by \(n\) can be assembled from the available puzzles. (each puzzle has a size of 1 by 1). Not all puzzles have to be used in the assembly, each puzzle can be rotated, but cannot be flipped over to the other side. A square frame is considered a square structure of size \(n\) by \(n\), the interior of size \(n-2\) by \(n-2\) of which is empty. In addition, the puzzles must not contain concavities that are not filled or convexities that stick out beyond the limits of the frame (that is, each side must be perfectly flat).
Finally, each part of the frame must be connected to exactly two other components, meaning that touching two components by a flat side is not valid. Help Kazimir by telling him how many options exist to realize his creative idea.
Input
The only line of input contains seven space-separated numbers — the quantities of components of each type. The order of the numbers corresponds to the order of the components in the picture in the statement.
Output
Output a single number — the number of different \(n\).
Constraints
The number of components of each type will be an integer from \(0\) to \(10^9\) inclusive.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 0 0 4 0 4 0 2 | 1 |
| Input (stdin) | Output (stdout) |
|---|---|
| 1 1 1 1 1 1 1 | 0 |
| Input (stdin) | Output (stdout) |
|---|---|
| 0 4 0 4 4 4 12 | 5 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|