← Home
package main

import (
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	input, err := io.ReadAll(os.Stdin)
	if err != nil {
		return
	}

	s := string(input)

	// Filter out any whitespace or unwanted characters from the input
	var expr string
	for _, c := range s {
		if (c >= '0' && c <= '9') || c == '+' || c == '-' {
			expr += string(c)
		}
	}

	if len(expr) == 0 {
		return
	}

	var result int
	var currentNum int
	var currentOp byte = '+'

	// Parse and evaluate the arithmetic expression
	for i := 0; i < len(expr); i++ {
		c := expr[i]
		if c >= '0' && c <= '9' {
			currentNum = currentNum*10 + int(c-'0')
		} else if c == '+' || c == '-' {
			if currentOp == '+' {
				result += currentNum
			} else {
				result -= currentNum
			}
			currentOp = c
			currentNum = 0
		}
	}

	// Apply the final operand
	if currentOp == '+' {
		result += currentNum
	} else {
		result -= currentNum
	}

	// Although the problem states the final result is in [0, 255], 
	// applying 8-bit unsigned wrap-around is a safe measure.
	result = ((result % 256) + 256) % 256

	// Convert the evaluated result to a string
	resStr := fmt.Sprintf("%d", result)

	// Generate Brainfuck code
	// Since Brainfuck doesn't accept input here (no ',' command support needed),
	// our generator will write code that simply outputs the result characters.
	var bf strings.Builder
	for i := 0; i < len(resStr); i++ {
		// Output '+' equal to the ASCII value of the character
		bf.WriteString(strings.Repeat("+", int(resStr[i])))
		// Print the character and move to the next memory cell
		bf.WriteString(".>")
	}

	// Print the generated Brainfuck program to standard output
	fmt.Print(bf.String())
}