#P1322. logo语言

logo语言

Description

Logo language commands can direct a turtle to crawl on the screen. This problem uses only three Logo statements: forward FD, backward BK, and repeat REPEAT, so the turtle moves back and forth along a single straight line. Given one line of a Logo command line, output the distance between the turtle and its original position (assume the screen is large enough to let the turtle move up to a distance of 10910^9).

For example:

  • Input FD 100, output: 100100.
  • Input FD 100 BK 150, output: 5050.
  • Input REPEAT 5[FD 100 BK 50], output: 250250.
  • Input REPEAT 5[FD 50 REPEAT 10[FD 100]], output: 52505250.

Input Format

One line containing a string that is a valid Logo command line as specified above.

Output Format

A single number: the distance from the turtle’s original position.

FD 100

100

Hint

The absolute value of each statement’s argument does not exceed 10001000. The output will not exceed 10910^9.

Translated by ChatGPT 5