#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ElementType int
#define EmptyTOS (-1)
#define MinStackSize (5)
struct StackRecord{
int Capacity;
int TopOfStack;
ElementType *Array;
};
typedef struct StackRecord *Stack;
Stack CreateStack(int MaxElements);
void DisposeStack( Stack S );
int IsEmpty( Stack S );
void MakeEmpty( Stack S );
void Push(ElementType X, Stack S);
ElementType Top( Stack S );
void Pop( Stack S );
Stack CreateStack(int MaxElements)
{
Stack S;
S = (Stack)malloc( sizeof( struct StackRecord) );
S->Array = (ElementType *)malloc(sizeof(ElementType)*MaxElements);
S->Capacity = MaxElements;
MakeEmpty(S);
return S;
}
void DisposeStack( Stack S )
{
if( S != NULL)
{
free(S->Array);
free(S);
}
}
int IsEmpty( Stack S )
{
return S->TopOfStack == EmptyTOS;
}
int IsFull( Stack S )
{
return S->TopOfStack == S->Capacity;
}
void MakeEmpty( Stack S )
{
S->TopOfStack = EmptyTOS;
}
void Push(ElementType X, Stack S)
{
if(IsFull(S))
{
}
else
{
S->Array[++S->TopOfStack] = X;
}
}
ElementType Top( Stack S )
{
if(!IsEmpty(S))
return S->Array[S->TopOfStack];
}
void Pop( Stack S )
{
if(IsEmpty( S ))
{
}
else
{
S->TopOfStack--;
}
}
char s[105];
int priority[255];
int main()
{
scanf("%s", s);
priority['+'] = 1;
priority['-'] = 1;
priority['*'] = 2;
priority['/'] = 2;
priority['^'] = 2;
priority['('] = 3;
priority[')'] = 3;
Stack number = CreateStack(105);
Stack punct = CreateStack(105);
int len = strlen(s);
int num = 0;
for(int i=0; i<len; i++)
{
if(s[i]<='9' && s[i]>='0')
{
num = num*10 + (s[i]-'0');
if(i+1>=len || !(s[i+1]<='9' && s[i+1]>='0') )
{
Push(num, number);
num = 0;
}
}
else
{
if(s[i] == ')')
{
while(Top(punct) != '(')
{
char p = Top(punct);
int a1=0,a2=0,ans=0;
a2 = Top(number);
Pop(number);
a1 = Top(number);
Pop(number);
switch(p){
case '+':
ans = a1 + a2;
break;
case '-':
ans = a1 - a2;
break;
case '*':
ans = a1 * a2;
break;
case '/':
ans = a1 / a2;
break;
case '^':
ans = pow(a1,a2);
default:
break;
}
Push(ans, number);
Pop(punct);
if(IsEmpty(punct)) break;
}
Pop(punct);
continue;
}
else if(!IsEmpty(punct) &&
priority[Top(punct)] >= priority[s[i]])
{
char tmp = s[i];
while(Top(punct)!='(' && priority[Top(punct)] >= priority[tmp])
{
char p = Top(punct);
int a1=0,a2=0,ans=0;
a2 = Top(number);
Pop(number);
a1 = Top(number);
Pop(number);
switch(p){
case '+':
ans = a1 + a2;
break;
case '-':
ans = a1 - a2;
break;
case '*':
ans = a1 * a2;
break;
case '/':
ans = a1 / a2;
break;
case '^':
ans = pow(a1,a2);
default:
break;
}
Push(ans, number);
Pop(punct);
if(IsEmpty(punct)) break;
}
}
Push(s[i], punct);
}
}
while(!IsEmpty(punct))
{
char p = Top(punct);
int a1=0,a2=0,ans=0;
a2 = Top(number);
Pop(number);
a1 = Top(number);
Pop(number);
switch(p){
case '+':
ans = a1 + a2;
break;
case '-':
ans = a1 - a2;
break;
case '*':
ans = a1 * a2;
break;
case '/':
ans = a1 / a2;
break;
case '^':
ans = pow(a1,a2);
default:
break;
}
Push(ans, number);
Pop(punct);
}
int ans = Top(number);
Pop(number);
printf("%d\n", ans);
}