CF39G Inverse Function
Description
Petya wrote a programme on C++ that calculated a very interesting function $ f(n) $ . Petya ran the program with a certain value of $ n $ and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of $ n $ the program was run. Help Petya, carry out the inverse function!
Mostly, the program consists of a function in C++ with the following simplified syntax:
- $ function $ ::= int f(int n) { $ operatorSequence $ }
- $ operatorSequence $ ::= $ operator | operator operatorSequence $
- $ operator $ ::= return $ arithmExpr $ ; $ | $ if ( $ logicalExpr $ ) return $ arithmExpr $ ;
- $ logicalExpr $ ::= $ arithmExpr>arithmExpr $ $ | $ $ arithmExpr<arithmExpr $ $ | $ $ arithmExpr $ == $ arithmExpr $
- $ arithmExpr $ ::= $ sum $
- $ sum $ ::= $ product $ $ | $ $ sum+product $ $ | $ $ sum-product $
- $ product $ ::= $ multiplier $ $ | $ $ product*multiplier $ $ | $ $ product/multiplier $
- $ multiplier $ ::= n $ | $ $ number $ $ | $ f( $ arithmExpr $ )
- $ number $ ::= $ 0|1|2|...\ |32767 $
The whitespaces in a $ operatorSequence $ are optional.
Thus, we have a function, in which body there are two kinds of operators. There is the operator "return $ arithmExpr $ ;" that returns the value of the expression as the value of the function, and there is the conditional operator "if ( $ logicalExpr $ ) return $ arithmExpr $ ;" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language — cycles, assignment operators, nested conditional operators etc, and other variables except the $ n $ parameter are used in the function. All the constants are integers in the interval $ [0..32767] $ .
The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations ">" (more), "
Input Format
The first line has an integer $ f(n) $ from the interval $ [0..32767] $ . The next lines have the description of the function $ f $ . In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed $ 100 $ bytes.
Output Format
Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes).