B. GoGo
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Baozii prefers using Go for programming problems that demand efficiency. In this task, Baozii challenges you to implement an interpreter for a simplified version of Go, called GoGo.

  1. Program Structure:
    • Every GoGo program starts with a main function, declared as func main() { on the first line.
    • The main function ends with a closing brace on its final line.

  2. Data Types and Variable Declarations:
    • GoGo supports two types: int (integer) and string.
    • Variables are declared using the syntax var x type, where x is the variable name and type is its data type (int or string).
    • Declared variables are initialized with their type's default value: $$$0$$$ for integers and an empty string for strings.
    • Re-declaration of a variable will lead to a runtime error.

  3. Literals:
    • Integer literals: Written in decimal, within the 64-bit signed integer range, and without leading zeroes.
    • String literals: Enclosed in double quotes and contain only lowercase English letters and digits.

  4. Variable Assignment:
    • Use x = y to assign the value of y to x.
    • x must be a declared variable, and y must be either a declared variable or a literal of the same type.
    • Assignments are pass-by-value, meaning changes to x or y afterward do not affect each other.
    • Violating any of these rules raises a runtime error.
    • Note that it is possible for x to be the same variable as y.

  5. Addition Operation:
    • Use x += y to add y to x.
      • If x and y are integers, this increments x by y.
      • If x and y are strings, this concatenates y to the end of x.
    • x must be a declared variable, and y must be either a declared variable or a literal of the same type. x and y must be of the same type. Violation of any of these rules will result in a runtime error.
    • Note that it is possible for x to be the same variable as y.

  6. Loops:
    • GoGo has a single loop type: for range n {, where n is the number of iterations (a positive integer literal no more than $$$100$$$).
    • The loop body ends with a closing brace on a single line.
    • No variable declarations or nested loops are allowed within for loops.

  7. Output:
    • Use Println(x) to print x to standard output.
    • If x is an integer, its decimal representation is printed. If x is a string, the string itself is printed.
    • x can be either a literal or a variable. If x is an undeclared variable, a runtime error occurs.
    • Each Println call moves the cursor to the next line.

You are now given a GoGo script. Your interpreter should output exactly what the program will output if it is run, and report any runtime errors.

Some possible clarifications:

  • For simplicity, there will be no indentation or empty lines in the script.
  • All variable names consist only of lowercase English letters and are no more than $$$3$$$ characters long. It is guaranteed that variable names do not coincide with keywords in GoGo such as var or for.
  • Except for possible type mismatch and use of undeclared variables, the script adheres to the given rules and there are no other sources of errors.
  • All operations will keep integers within 64-bit signed integer range. The sum of lengths of all string variables will be no more than $$$10^4$$$ at any time when executing the script.
Input

A GoGo script consisting of no more than $$$10^4$$$ characters.

Output

If a runtime error occurs, output "runtime error"(without quotes) on a single line only. Otherwise, output exactly what is printed to the standard output if the GoGo script is run. It is guaranteed that the total number of characters printed will be no more than $$$10^4$$$.

Examples
Input
func main() {
var x int
var y int
y = -10
Println(y)
var s string
s = "abc"
for range 5 {
Println(1)
Println(x)
x += x
x += 1
s += "p"
s += ""
}
Println("")
Println(s)
Println(x)
}
Output
-10
1
0
1
1
1
3
1
7
1
15

abcppppp
31
Input
func main() {
Println(x)
}
Output
runtime error
Input
func main() {
var x int
var x int
}
Output
runtime error