Chocolate is a two-dimensional programming language. How it works is described below.
In Chocolate, identical characters adjacent horizontally or vertically form a block, and such blocks are the unit of operation. Spaces (ASCII 32) are ignored. The first block to be executed is the block containing the leftmost character of the first line. If it is a space, the program does not run.
Moving across blocks
Two values and determine the next block to run. represents the direction forward (right, down, left, or up), and looking in that direction, chooses either the leftmost or the rightmost block on that side. When program starts, is right and is left. Given the current values of and , the next block to run is determined as follows:
For example, in the image below, the next block to move after running the P block can be one of 8 different blocks, labelled 1 through 8. If is right and is left, the destination is 1. If is down and is right, the destination is 4.
If the position to move next is blank or out of program space, then such a move is not valid, and and are changed as follows until a valid move is found.
이때 이동할 칸이 빈 칸이거나 프로그램 영역 밖이면 이동할 수 없으며, 다음과 같이 와 를 바꿔가며 이동할 칸을 찾는다.
An integer is given. ()
The input ends with a newline (ASCII 10).
Over lines, print asterisks (ASCII 42). On the -th line, print asterisks without blanks. Don't forget to print newlines (ASCII 10) between two lines.
The verdict will be Wrong Answer when at least one of the following is true:
r commands exceeds 1,000,000Interpreters in C++ and Python are available at GitHub Gist. How to run: chocolate.exe src.txt < input.txt or python chocolate.py src.txt < input.txt
For example, in the picture above, assume that the current is right and is down. Then the moves to be tried are 1, 2, 4, 3, 5, 6, 8, and 7 in that order.
If all 8 possible moves are invalid, the program exits. This is the only way to properly exit the program.
Instructions
In Chocolate, all values are stored in a single stack, whose elements are integers in the range of .
When a block is entered, the instruction that corresponds to the character of that block is executed. An instruction is simply ignored when an operation is not possible (not enough numbers in the stack, division by zero, EOF for input commands, etc.).
I: Take one character from stdin, and put its ASCII value on the top of the stack. Ignore if stdin is empty.O: Pop one value from the stack, and print the character whose ASCII value is its value modulo 256.P: Push an integer equal to the area of the current block.p: Pop a number from the stack and discard it.+: Pop and , and push to the stack.-: Pop and , and push to the stack.*: Pop and , and push to the stack./: Pop and , and push to the stack.%: Pop and , and push to the stack. It satisfies the rule .!: Pop , and push 1 if is 0, 0 otherwise.>: Pop and , and push 1 if , 0 otherwise.D: Pop , and rotate by 90 degrees clockwise times. If is negative, rotate counterclockwise times instead.C: Pop , and switch times.d: Pop , and push twice.r: Pop and , and "rotate" the top values of the stack times. "Rotate" here means to move the topmost value to the bottom and move the rest up by one slot. If is negative, do the opposite operation times. If or is greater than the number of elements in the stack after popping and , do not perform rotation and push and back to the stack.When an unknown character is executed, it is a runtime error. For this problem, you will get Wrong Answer.
Undefined behavior
In the following cases, the behavior of the program is undefined:
In these cases, the grader follows the C++ implementation of the interpreter below.
The following is an example Chocolate program that prints Hello World!:
PPPPPPdP+*d
PP dO
Ppd+PPd* Od
dd P -- dP
OO dOPPd+ ++ P
d ++ P +- P /
* P PP/O d p +
+ P P OO O P d
P P O PP p P
PPO d-+dPP dPP
P d+ P POPP
dP +*+PdPPP PP
PP P --
PO+PPOdOdO
Now solve the following task with Chocolate.