   Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register
Language:
Trigonometric optimization
 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 510 Accepted: 51 Case Time Limit: 2000MS Special Judge

Description

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 F1(x) + F2(y) + F3(z) with constraint x + y + z = S, where x, y, z – variables, S – parameter, x, y, z, S – natural numbers excluding zero.  Each of the functions F1, F2 and F3 is a trigonometric function sin or cos.

You need to write a program which solves the trigonometric optimization problem.

Input

The input contains 5 lines. The first line describes function F1 and contains either sin or cos. The second and the third lines describe functions F2 and F3 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 ≤ S1 000 000).

Output

The only line of the output 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.

Sample Input

```sin
cos
sin
max
10```

Sample Output

`2.7787651403`

Hint

Beware that GNU compilers for C and C++ provide relatively slow trigonometric functions.

Source

Northeastern Europe 2005, Western Subregion

[Submit]   [Go Back]   [Status]   [Discuss] Home Page Go Back To top