https://codeforc.es/gym/101987
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",x)
#define sfl(x) scanf("%lld",&x)
#define sfs(x) scanf("%s",x)
#define pb push_back
#define fl() printf("flag!\n")
#define INF 0x3f3f3f3f
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=2e5+9;
const int mod=1e9+7;
char s[maxn],tmp[maxn];
int n,cnt;
bool isc(char c)
{
return c>='a'&&c<='z';
}
bool iso(char c)
{
return c=='/'||c=='%'||c=='-'||c=='+'||c=='*';
}
bool ch1(char s[],int len)
{
//for(int i=0;i<len;i++) cout<<s[i];
if(s[0]==')') return 0;
if(s[len-1]=='(') return 0;
if(iso(s[0])||iso(s[len-1])) return 0;
for(int i=1;i<len;i++)
{
//cout<<s[i];
if(isc(s[i])&&isc(s[i-1])) return 0;// aa
if(iso(s[i])&&iso(s[i-1])) return 0;// ++
if(s[i-1]=='('&&iso(s[i])) return 0;// (+
if(iso(s[i-1])&&s[i]==')') return 0;// +)
if(s[i-1]==')'&&isc(s[i])) return 0;// )a
if(isc(s[i-1])&&s[i]=='(')return 0;// a(
if(s[i-1]=='('&&s[i]==')') return 0;
if(s[i-1]==')'&&s[i]=='(') return 0;
}
int num=0;//()
for(int i=0;i<len;i++)
{
if(s[i]=='(') num--;
else if(s[i]==')') num++;
if(num>0) return 0;// ( ))
}
if(num!=0) return 0;// (( )
return 1;
}
bool ch2(char s[],int len)
{
if(len==1) return 1;
int op=0;
int h=0;
for(int i=0;i<len;i++)
if(iso(s[i])) op++;
stack<char>st;
for(int i=0;i<len;i++)
{
if(isc(s[i])) continue;
if(s[i]=='('||iso(s[i])) st.push(s[i]);
else
{
int op2=0;
while(st.size())
{
char c=st.top();
st.pop();
if(iso(c)) op2++;
else
{
break;
}
}
if(op2!=1) return 0;
else h++;
}
}
return h==op-1;
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
gets(tmp);
n=strlen(tmp);
cnt=0;
for(int i=0;i<n;i++)
{
if(tmp[i]!=' ')
{
s[cnt++]=tmp[i];
}
}
s[cnt]='\0';
n=cnt;
//cout<<s<<endl;
if(!ch1(s,n))
{
cout<<"error"<<endl;
}
else
{
if(ch2(s,n))
{
cout<<"proper"<<endl;
}
else cout<<"improper"<<endl;
}
return 0;
}