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