eolymp
bolt
Try our new interface for solving problems
Problems

Trigonometric optimization

Trigonometric optimization

Many problems arising in practical applications may be stated as \textit{optimization problems}. Usually it is necessary to maximize or minimize so called \textit{criterion function} taking into account some \textit{constraints}. Let’s consider a \textit{trigonometric optimization} problem. It is necessary to maximize or to minimize criterion function \textbf{F_1(x) + F_2(y) + F_3(z)} with constraint \textbf{x + y + z = S}, where \textbf{x}, \textbf{y}, \textbf{z} -- variables, \textbf{S} -- parameter, \textbf{x}, \textbf{y}, \textbf{z}, \textbf{S} - natural numbers. Each of the functions \textbf{F_1}, \textbf{F_2} and \textbf{F_3} is a trigonometric function \textbf{sin} or \textbf{cos}. You need to write a program which solves the \textit{trigonometric optimization} problem. \InputFile Input data are which contains \textbf{5} lines. The first line describes function \textbf{F_1} and contains either \textbf{sin} or \textbf{cos}. The second and the third lines describe functions \textbf{F_2} and \textbf{F_3} respectively and have the same format as the first line. Next, the fourth line contains either \textbf{min} or \textbf{max}. If the line contains \textbf{min} than it is necessary to minimize \textit{criterion function}, otherwise it is necessary to maximize \textit{criterion function}. Finally, the fifth line contains parameter \textbf{S} value (\textbf{3} ≤ \textbf{S} ≤ \textbf{1000000}). \OutputFile Output data are put into the only line of the file contains one real number -- the found value of the \textit{criterion function}, described in the input file. Absolute error of your answer must not exceed \textbf{10^\{-10\}}.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
sin
cos
sin
max
10
Output example #1
2.778765140301729
Source ACM Programming Contest 2005, Minsk, October 2005