P2027 BrainFuck

Background

bf is a programming language, short for BrainFuck. Since the problem title should not be too explicit, we abbreviate it as bf.

Description

The execution model is very simple: there is an array of $30000$ signed $8$-bit integers (range $[-128,127]$) and a pointer to a position in this array, which initially points to the first cell. The character set is also very simple: only `+ - , . > < []`. |Character|Meaning| |:-|:-| |``  |Increase the memory address pointed to by the pointer by one.| |`+`  |Increase the value in the current cell by one.| |`-`  |Decrease the value in the current cell by one.| |`.`  |Output the value in the current cell as a character.| |`,`  |Read one byte from the input buffer into the current cell. If the input buffer is empty, store $-1$.| |`[`  |While the value in the current cell is not $0$, repeat the statements between it and the matching `]`, until upon returning to `[` the current cell becomes $0$.| |`]`  |Same as above.|

Input Format

The input consists of several lines; the code may contain comments. The code ends at the first `$`. Immediately after the `$` comes a space (which does not belong to the input buffer), then the contents of the input buffer, ending with a space and a `$`.

Output Format

Output the result of executing this code.

Explanation/Hint

For $10\%$ of the testdata, there are no loops. For another $10\%$ of the testdata, loops have no nesting. For $100\%$ of the testdata, the program will not access out of bounds, the program will finish within $10^6$ steps, and the input string length is no greater than $30000$. The value of a character in memory is the character’s ASCII code. Translated by ChatGPT 5