// Arup Guha
// 3/28/2020
// Solution to 2020 MAPS Problem G: Litespace
// Written in Contest, Commented Later

import java.util.*;

public class litespace {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		char[] s = stdin.next().toCharArray();
		
		int i = 0;
		
		// top == -1 means empty.
		long[] stack = new long[10000];
		int top = -1;
	
		// Just read it.
		while (i < s.length) {
			
			// dummy val.
			int end = i;
			
			// I process all S commands first.
			if (s[i] == 'S') {
				
				// SS<Int> Push on stack.
				if (s[i+1] == 'S') {
				
					// Sign, set up value.
					int sign = s[i+2] == 'S' ? 1:-1;
					long val = 0;
					
					// Use Horner's method to get the unsigned value.
					int j = i+3;
					while (s[j] != 'N') {
						int bit = s[j] == 'T' ? 1 : 0;
						val = 2*val + bit;
						j++;
					}
					
					// Update with sign and add to stack.
					val *= sign;
					stack[top+1] = val;
					top++;
					i = j+1;
					continue;
				}
				
				// SNS, Copy op.
				else if (s[i+2] == 'S') {
					
					// Invalid check.
					if (top == -1) {
						System.out.println("Invalid copy operation");
					}
					
					// This is easy just add to stack what's at the top and move top.
					else {
						stack[top+1] = stack[top];
						top++;
					}
					i = i+3;
					continue;
				}
				
				// SNT, swap
				else if (s[i+2] == 'T') {
					
					// Invalid swap.
					if (top < 1) {
						System.out.println("Invalid swap operation");
					}
					
					// We have 2 things, swap them.
					else {
						long tmp = stack[top];
						stack[top] = stack[top-1];
						stack[top-1] = tmp;
					}
					i = i+3;
					continue;
				}
				
				// SNN, remove.
				else {
					
					// Invalid remove.
					if (top == -1) {
						System.out.println("Invalid remove operation");
					}
					
					// Just get rid of.
					else {
						stack[top] = 0;
						top--;
					}
					i = i+3;
					continue;
				}
			}
			
			// All T ops here.
			else {
			
				// TNST, print.
				if (s[i+1] == 'N') {
					
					// Nothing to print.
					if (top == -1) {
						System.out.println("Invalid print operation");
					}
					
					// Print and then remove.
					else {
						System.out.println(stack[top]);
						stack[top] = 0;
						top--;
					}
					i = i+4;
					continue;
				}
				
				// TSTS - Division
				else if (s[i+2] == 'T') {
					
					// Don't have 2 numbers to divide.
					if (top < 1) {
						System.out.println("Invalid division operation");
					}
					
					// Can't divide by 0.
					else if (stack[top] == 0) {
						System.out.println("Division by zero");
					}
					
					// Divide the two and reduce the stack size.
					else {
						stack[top-1] = stack[top-1]/stack[top];
						top--;
					}
					i = i+4;
					continue;
				}
				
				// TSSS - Addition
				else if (s[i+3] == 'S') {
					
					// Don't have 2 numbers to add.
					if (top < 1) {
						System.out.println("Invalid addition operation");
					}
					
					// Add the two and reduce the stack size by 1.
					else {
						stack[top-1] += stack[top];
						top--;
					}
					i = i+4;
					continue;
				}
				
				// TSST - Subtraction.
				else if (s[i+3] == 'T') {
					
					// Don't have two things to subtract.
					if (top < 1) {
						System.out.println("Invalid subtraction operation");
					}
					
					// Subtract them and reduce stack size by 1.
					else {
						stack[top-1] -= stack[top];
						top--;
					}
					i = i+4;
					continue;					
				}
				
				// TSSN - Multiplication
				else {
					
					// Don't have 2 things to multiply.
					if (top < 1) {
						System.out.println("Invalid multiplication operation");
					}
					
					// Multiply and reduce stack size by 1.
					else {
						stack[top-1] *= stack[top];
						top--;
					}
					i = i+4;
					continue;					
				}
			}
		}
	}
}	