#include <iostream.h>
#include <stdio.h>
#include <string>
#include "stack_linkedlist.hpp"

string itos( int n );

int main( void )
{
	string input;
	string rpn;
	stack<char> stk;
	char type;
	char charset[256];
	string x = "";

	//Set up charset for priority
	int i = 0;
	for( i = 0; i < 256; i++ )
		charset[i] = -1;
	for( i = 'A'; i < 91; i++ )
		charset[i] = 0;
	for( i = 'a'; i < 123; i++ )
		charset[i] = 0;
	charset[ '*' ] = 9;
	charset[ '/' ] = 9;
	charset[ '+' ] = 5;
	charset[ '-' ] = 5;
	charset[ '=' ] = 3;
	charset[ '(' ] = 1;
	charset[ ')' ] = 2;


	cin >> input;
	cout << input << endl;
	for( int i = 0; i < input.length(); i++ )
	{
		switch( charset[ input[i] ] )
		{
		case 0:rpn = rpn + input[i];
		       break;
		case 1:stk.push( input[i] );
			 break;
		case 2:while( stk.top() != '(' )
			 {
				 rpn = rpn + stk.top();
				 stk.pop();
			 }
			 stk.pop();
			 break;
		case 3:
			{
				while( !stk.empty() && stk.top() != '(' && charset[ stk.top() ]  >= charset[ input[i] ] )
			 {
				 rpn = rpn + stk.top();
				 stk.pop();
			 }
			 stk.push( input[i] );
			 //cout << "operator" << endl;
			}
		case 5:
			{
				while( !stk.empty() && stk.top() != '(' && charset[ stk.top() ]  >= charset[ input[i] ] )
			 {
				 rpn = rpn + stk.top();
				 stk.pop();
			 }
			 stk.push( input[i] );
			 //cout << "operator" << endl;
			}
		case 9:
			{
				while( !stk.empty() && stk.top() != '(' && charset[ stk.top() ]  >= charset[ input[i] ] )
			 {
				 rpn = rpn + stk.top();
				 stk.pop();
			 }
			 stk.push( input[i] );
			 //cout << "operator" << endl;
			}
		}
	}
	while( !stk.empty() )
	{
		rpn =  rpn + stk.top();
                stk.pop();
	}
	cout << rpn;


	stack<string> sts;
	int n = 0;
	for( int k = 0; k < rpn.length(); k++ ) 
	{		
		switch( charset[ rpn[k] ] )
		{
		case 0:{
			x = rpn[k];
			sts.push( x );
			break;
			}
		case 3||5||9:{
			string tmpvar;
			string a = sts.top();
			sts.pop();
			string b = sts.top();
			sts.pop();
			if( rpn[k] == '+' )
			{
				cout << "load " << a << endl;
				cout << "add  " << b << endl; 
				tmpvar = "T" + itos( n++ ); 
				sts.push( tmpvar );
				continue;
			}
			if( rpn[k] == '-' )
			{
				cout << "load " << a << endl;
				cout << "sub  " << b << endl; 
				tmpvar = "T" + itos( n++ ); 
				sts.push( tmpvar );
				continue;
			}
			if( rpn[k] == '/' )
			{
				cout << "load " << a << endl;
				cout << "div  " << b << endl; 
				tmpvar = "T" + itos( n++ ); 
				sts.push( tmpvar );
				continue;
			}
			if( rpn[k] == '*' )
			{
				cout << "load " << a << endl;
				cout << "add  " << b << endl; 
				tmpvar = "T" + itos( n++ ); 
				sts.push( tmpvar );
				continue;
		 	}
			if( rpn[k] == '=' )
			{
				cout << "load " << a << endl;
				cout << "sto  " << b << endl; 
				tmpvar = "T" + itos( n++ ); 
				sts.push( tmpvar );
				continue;
			}
			cout << "Invalid operator input" << endl;
			exit( 1 );
			} 
		}
	}
}

string itos( int n )
{ 
	string * x = new string; 
	char c; 
	stack<char> digits; 
	if ( n < 0 ) 
		n = -n; 
	for(;;) 
	{ 
		c = n % 10; 
		digits.push( c ); 
		if (( n = n/10 ) == 0 ) 
			break; 
	}
	while ( !digits.empty() ) 
	{
		*x = *x + (char)('0' + digits.top()); 
		digits.pop(); 
	}
	return *x; 
}
