#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX 100

int applyOp(char op, int a, int b) {
    switch(op) {
        case '+': return a + b;
        case '*': return a * b;
        case '-': return a - b;
        case '/': return b == 0 ? -1 : a / b;
        default: return -1;
    }
}

int evaluate(const char *s) {
    int stack[MAX], top = -1;
    int len = strlen(s);

    for (int i = len - 1; i >= 0; i--) {
        char ch = s[i];
        if (isdigit(ch)) {
            stack[++top] = ch - '0';
        } else if (ch == '+' || ch == '-' || ch == '*' || ch == '/') {
            if (top < 1) return -1;
            int a = stack[top--];
            int b = stack[top--];
            int res = applyOp(ch, a, b);
            if (res == -1) return -1;
            stack[++top] = res;
        } else {
            return -1;
        }
    }

    return top == 0 ? stack[top] : -1;
}

int main() {
    char input[MAX];
    scanf("%s", input);
    char[] temp = "Balanced";
    int result = evaluate(input);
    if (result == -1)
        printf("Invalid input\n");
    else
        for(int i = 0 ; i < result;i++ ){
            printf("%s\n",temp);
        }
    return 0;
}