#P2027. BrainFuck

BrainFuck

Description

The execution model is very simple: there is an array of 3000030000 signed 88-bit integers (range [128,127][-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
< Decrease the memory address pointed to by the pointer by one.
> 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-1.
[ While the value in the current cell is not 00, repeat the statements between it and the matching ], until upon returning to [ the current cell becomes 00.
] 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.

write whatever u c ,.,.,.,. $ asdf $
asdf

Hint

For 10%10\% of the testdata, there are no loops.

For another 10%10\% of the testdata, loops have no nesting.

For 100%100\% of the testdata, the program will not access out of bounds, the program will finish within 10610^6 steps, and the input string length is no greater than 3000030000.

The value of a character in memory is the character’s ASCII code.

Translated by ChatGPT 5