eolymp
bolt
Try our new interface for solving problems
Problems

Triangular Room

Triangular Room

Many books on entertaining mathematics contain following task. \textit{Arrange }\textbf{3}\textit{ chairs around the perimeter of triangular room such that there would be }\textbf{2}\textit{ chairs near each wall}. The solution of this problem is to put one chair in each corner of the room. Consider more general problem. Let the room is represented by triangle \textbf{ABC}. The total number of chairs \textbf{n}, the number of chairs \textbf{n_AB} , which must be standing near wall \textbf{AB}, the number of chairs \textbf{n_BC}, which must be standing near wall \textbf{BC}, and the number of chairs \textbf{n_AC}, which must be standing near wall \textbf{AC} are given. It is necessary to find the number of arrangements satisfying conditions. Chairs can be put in corners of the room or along walls only, and should not be put in the center of the room. In each corner you can put any number of chairs. \InputFile The input file contains integer numbers \textbf{n}, \textbf{n_AB}, \textbf{n_BC}, \textbf{n_AC} (\textbf{0} ≤ \textbf{n}, \textbf{n_AB}, \textbf{n_BC}, \textbf{n_AC} ≤ \textbf{10^18}). \OutputFile Write the number of different chairs arrangements in first line of the input file. If there is at least one arrangement, write \textbf{6} nonnegative integer numbers in the second line: \textbf{k_A}, \textbf{k_AB}, \textbf{k_B}, \textbf{k_BC}, \textbf{k_C}, \textbf{k_AC}, represented number of chairs, which must be put in the corner \textbf{A}, along the wall \textbf{AB}, in the corner \textbf{B}, along the wall \textbf{BC}, in the corner \textbf{C} and along the wall \textbf{AC} respectively.
Time limit 0.5 seconds
Memory limit 64 MiB
Input example #1
3 2 2 2
Output example #1
1
1 0 1 0 1 0
Author В.Неспирный
Source Зимние сборы в Харькове 2010 День 1