题目描述
Problem Description
Nico Nico TV-chan decided to do some simple calculations as a mental exercise. Since Nico Nico TV-chan is not human, she calculates using Reverse Polish Notation.
Specifically, for a string $ S $ consisting of 0 ~ 9, -, and +, she follows these rules:
- First, consider having an initially empty, infinitely long stack. Then, look at the characters of $ S $ from the beginning.
- If
0~9appears, push it onto the stack. - If
+appears, pop one element $ a $ and another element $ b $ from the stack, then push $ b+a $ onto the stack. - If
-appears, pop one element $ a $ and another element $ b $ from the stack, then push $ b-a $ onto the stack. - Finally, if there is exactly one element in the stack, that is the answer.
- If there is not exactly one element in the stack, or if trying to pop from an empty stack, $ S $ is not a valid expression.
Nico Nico TV-chan randomly wrote a string $ S $. Just calculating it is boring, so she decided to solve the following problem:
- Can this string be rewritten within $ K $ characters to become a valid expression? If so, among the valid expressions, what is the maximum value of the calculated result?
However, this is too difficult, so please help her solve it instead.
Input Format
The input is given from the standard input in the following format:
$ K $ $ S $
Output Format
If it is not possible to make a valid expression, output NG. If it is possible, output OK and on the next line, output the maximum value of the calculated result.
Sample Input and Output
Sample Input #1
0
21+
Sample Output #1
OK
3
Sample Input #2
1
21+
Sample Output #2
OK
11
Sample Input #3
1
21-
Sample Output #3
OK
8
Sample Input #4
0
1+1
Sample Output #4
NG
Sample Input #5
3
1234567
Sample Output #5
OK
13
Notes/Hints
Constraints
- $ S $ is a string consisting of
0~9,-, and+. - $1 \leq |S| \leq 52$
- $0 \leq K \leq |S|$
Sample Explanation 1
This expression, in normal notation, is 2+1.
Sample Explanation 2
Rewriting it to 29+ maximizes the result.
Sample Explanation 3
Rewriting it to 91- maximizes the result.
Sample Explanation 4
Such an expression is not a valid Reverse Polish Notation.
Sample Explanation 5
Rewriting it to 12+4+6+ maximizes the result.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分