In 2111, on the eve of the 128th National Olympiad in Informatics in Provinces Winter Camp, Z-kun found the problems from the 32nd Winter Camp in 2015 to practice.
He opened the third problem, "Future Program":
"This is an answer-submission problem with a total of 10 test cases.
For each test case, you will be given the source code of a program and the input for that program. You must run this program and save its output.
Unfortunately, these programs are extremely inefficient and cannot produce output within the 5-hour contest time limit."
Z-kun thought for a moment and decided to try running this problem using a computer from 2111, but a problem arose: Z-kun could no longer find the test data from that competition 96 years ago.
An answer-submission problem without input data is not worthy of the name "answer-submission problem." To solve this, Z-kun decided to transform this problem into a traditional problem.
Z-kun knew that the performance of computers 96 years ago was much worse than it is today, so the scale of the input data in this problem's test cases was designed to be very small, allowing contestants to pass by simply simulating the workflow of the source code.
Now, this problem is placed before you.
This is a traditional problem with a total of 10 test cases.
For each test case, your program will receive the source code of a program and the input for that program. Your program needs to execute this source code and output the result.
Conventions for the Provided Source Code
Z-kun is a C++ programmer. To simplify this problem, Z-kun removed many features of the C++ language from the provided source code. Consequently, the source code has the following characteristics:
- The first line is always "#include<iostream>" (without quotes).
- Only the objects cin, cout, endl, the cin function >>(int), and the cout function <<(int) are called from this library. These two functions are used to input and output an integer, respectively, and return cin and cout.
- The second line is always "#include<cstdio>" (without quotes).
- Only the putchar function is called from this library. putchar(c) outputs the character with ASCII code $c$ and returns $c$.
- The third line is always "using namespace std;" (without quotes).
- Calls to the object cin no longer need to be made via std::cin; the same applies to cout and endl.
- int main() has no parameters.
- All variables are of type int or int arrays (including multi-dimensional arrays).
- The objects cin, cout, and endl are exceptions. Note that the parameter of putchar is also of type int. We guarantee that the value of this parameter will be between $0$ and $127$ at runtime.
- There will be no array out-of-bounds issues at runtime.
- No dimension range is $1$. That is, cases like int a[1][1][1][1][1]; will not occur.
- Dimension ranges are given directly by decimal constants. That is, cases like int a[(100+100)*2]; will not occur.
- The objects cin, cout, and endl are exceptions. Note that the parameter of putchar is also of type int. We guarantee that the value of this parameter will be between $0$ and $127$ at runtime.
- All functions are of type int, and function parameters can only be of type int.
- Note that function return values can be discarded.
- When there is no explicit return value, $0$ is returned.
- Note that function return values can be discarded.
- The bool type is considered a special int type.
- == returns $1$ if the two parameters are the same, otherwise $0$.
- != returns $0$ if the two parameters are the same, otherwise $1$.
- < returns $1$ if the first parameter is less than the second, otherwise $0$.
- <= returns $1$ if the first parameter is less than or equal to the second, otherwise $0$.
- > returns $1$ if the first parameter is greater than the second, otherwise $0$.
- >= returns $1$ if the first parameter is greater than or equal to the second, otherwise $0$.
- && returns $1$ if both parameters are non-zero, otherwise $0$.
- || returns $0$ if both parameters are $0$, otherwise $1$.
- ^ returns $1$ if exactly one of the two parameters is $0$, otherwise $0$.
- ! returns $1$ if the parameter is $0$, otherwise $0$.
- Since bool is replaced by int, all expressions must be fully evaluated: for example, in the expression (a && (b = c)), even if a is already determined to be $0$, (b = c) must still be evaluated, even though the value of the entire expression is $0$ regardless of the value of (b = c).
- == returns $1$ if the two parameters are the same, otherwise $0$.
- The operators that may be used and their precedence are as follows (from highest to lowest):
- (), []
- !, + (unary plus), - (unary minus)
- *, /, %
- + (addition), - (subtraction)
- <=, >=, <, >
- ==, !=
- ^
- &&
- ||
- =
- cout's << and cin's >>.
- All int constants are given in decimal form.
- Z-kun did not obfuscate the source code, so it is readable; you do not need to worry about deeply nested braces or similar "junk code."
- The peak memory usage of variables at runtime does not exceed $8\texttt{MB}$, i.e., $2^{21}$ ints.
- The function call depth will not exceed $10^3$ levels.
- Continuous assignments may occur, such as a = (b = (c = 3) + 2) % c.
- Previous assignments to c will be reflected in subsequent references to c.
- = is right-associative; a = b = c is treated as a = (b = c).
- The return value of an assignment is the value after the assignment.
- Possible program flow control statements:
- if (statement) statement [else statement]
- while (statement) statement
- for ([statement]; [statement]; [statement]) statement
- The return value of a statement used as a condition should be treated as a bool. Specifically, if the return value is $0$, it is false; if the return value is non-zero, it is true. In a for loop, if the second [statement] is empty, it is treated as true.
- Whitespace characters are only newlines (\n) and spaces.
- Variables have a default initial value of $0$ when declared; they are not assigned values during declaration.
- No comments.
- No semicolons after closing braces.
- No commas used to connect statements.
- No function and variable name conflicts.
Input
The input file consists of two parts.
The first line contains an integer $N$, describing the number of integers contained in the source code's corresponding input file program.in.
The following $N$ integers constitute the input file program.in for the source code.
The subsequent part constitutes the source code program.cpp.
Output
The output file is the result obtained by compiling program.cpp and running it with program.in as input.
Examples
Input 1
2
1 2
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{int a, b; cin >> a >> b; cout << a + b << endl;}Output 1
3
Input 2
10
9
6 1 7 5 1 7 2 2 4
#include<iostream>
#include<cstdio>
using namespace std;
int n, a[100];
int main()
{
cin >> n;
int i, j, this_VARIABLE_is_NOT_used;
for (i = 1; i <= n; i = i + 1) cin >> a[i];
for (i = 1; i <= n; i = i + 1)
for (j = i + 1; j <= n; j = j + 1)
if (a[i] > a[j])
{
int t;
t = a[i];
a[i] = a[j];
a[j] = t;
}
for (i = 1; i <= n; i = i + 1)
{
cout << a[i];
if (i == n) cout << endl; else putchar(32);
}
return 0;
}Output 2
1 1 2 2 4 5 6 7 7
Constraints
All program.cpp files are hand-written, and each input file size does not exceed $7\texttt{KB}$.
For program.cpp of test case #1, see the sample data and additional file downloads.
For program.cpp of test cases #2 to #4, the format is as follows:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
cout << <1> << endl;
}
In #2: <1> is an expression containing only addition, subtraction, multiplication, division, modulo operations, and natural number constants, without parentheses.
In #3 and #4: <1> is an expression that does not guarantee the above properties.
In test case #5: There are no functions other than main, and the entire program consists only of sequential structures.
In test cases #6 and #7: There are no functions other than main.
In test case #8: All variables are global variables.
Test cases #9 and #10 do not guarantee any special properties.
All program.cpp can be compiled and run using MinGW GCC 4.7.2. This means all program.cpp files have no syntax errors. However, due to different compilation commands, the program.exe obtained by direct compilation might produce different outputs compared to the reference solution because of default $0$ values for undeclared variables and uninitialized return values, as well as different handling of the bool type.
To more accurately describe the possible elements of the program, and as a hint, a context-free grammar is provided below, with the initial symbol PROGRAM. It is guaranteed that every program.cpp can be generated by the following grammar, but not every program that can be generated is a valid program.
PROGRAM ::= # include < iostream > # include < cstdio > using namespace std ; FUNC_AND_VAR
FUNC_AND_VAR ::=
| ε
| int NAME ( OPTPARAMS ) { STATEMENTS } FUNC_AND_VAR
| int DEFINEVAR DEFINEVARS ; FUNC_AND_VAR
OPTPARAMS ::=
| ε
| int NAME PARAMS
PARAMS ::=
| ε
| , int NAME PARAMS
STATEMENTS ::=
| ε
| STATEMENT STATEMENTS
STATEMENT ::=
| EXPRESSION ;
| { STATEMENTS }
| int DEFINEVAR DEFINEVARS ;
| if ( EXPRESSION ) STATEMENT
| if ( EXPRESSION ) STATEMENT else STATEMENT
| for ( STATEMENT_IN_FOR ; OPTEXPRESSION ; STATEMENT_IN_FOR ) STATEMENT
| while ( EXPRESSION ) STATEMENT
| return EXPRESSION ;
STATEMENT_IN_FOR ::=
| EXPRESSION
| int DEFINEVAR DEFINEVARS
OPTEXPRESSION ::=
| ε
| EXPRESSION
EXPRESSION ::=
| UNIT9
| EXPRESSION << UNIT9
| EXPRESSION >> UNIT9
UNIT0 ::=
| INT_CONSTANT
| UNIT0 [ EXPRESSION ]
| ( EXPRESSION )
| NAME ( OPTARGUS ) // Note: NAME here is a function name
| NAME // Note: NAME here is a variable name
| cin
| cout
| endl
UNIT1 ::=
| UNIT0
| + UNIT1
| - UNIT1
| ! UNIT1
UNIT2 ::=
| UNIT1
| UNIT2 * UNIT1
| UNIT2 / UNIT1
| UNIT2 % UNIT1
UNIT3 ::=
| UNIT2
| UNIT3 + UNIT2
| UNIT3 - UNIT2
UNIT4 ::=
| UNIT3
| UNIT4 < UNIT3
| UNIT4 <= UNIT3
| UNIT4 > UNIT3
| UNIT4 >= UNIT3
UNIT5 ::=
| UNIT4
| UNIT5 == UNIT4
| UNIT5 != UNIT4
UNIT6 ::=
| UNIT5
| UNIT6 ^ UNIT5
UNIT7 ::=
| UNIT6
| UNIT7 && UNIT6
UNIT8 ::=
| UNIT7
| UNIT8 || UNIT7
UNIT9 ::=
| UNIT8
| UNIT8 = UNIT9
OPTARGUS ::=
| ε
| EXPRESSION ARGUS
ARGUS ::=
| ε
| , EXPRESSION ARGUS
DEFINEVARS ::=
| ε
| , DEFINEVAR DEFINEVARS
DEFINEVAR ::=
| NAME
| DEFINEVAR [ INT_CONSTANT ]
NAME ::= A non-empty string containing only uppercase/lowercase letters, digits, and underscores, not starting with a digit.
INT_CONSTANT ::= A non-empty string containing only digits, not starting with 0, or the string is 0.