#include<cstdio>
#include<cstring>
//栈匹配括号
#define Max 100
typedef struct{
char data[Max];
int top;
} SqStack;
bool initStack(SqStack &S){
S.top = -1;
return true;
}
bool Push(SqStack &S,char x){
if(S.top == Max-1) return false; //栈满,退出
S.data[++S.top] = x;
return true;
}
bool Pop(SqStack &S,char &x){
if(S.top == -1) return false; //栈空
x = S.data[S.top--];
return true;
}
bool isEmpty(SqStack &S){
if(S.top == -1) return true;
else return false;
}
bool Bracketcheck(char str[],int length){ //length是字符串长度
SqStack S;
initStack(S);
for(int i=0;i<length;i++){
if(str[i]=='('||str[i]=='['||str[i]=='{'){
Push(S,str[i]);
}else{
if(isEmpty(S) == true) return false; //栈空,右括号单身
char s; //记录出栈元素
Pop(S,s);
if(str[i] == ')' && s != '(') return false;
if(str[i] == ']' && s != '[') return false;
if(str[i] == '}' && s != '{') return false;
}
}
if(isEmpty(S) != true) return false;
else return true;
}
int main(){
char str[Max];
scanf("%s",str);
if(Bracketcheck(str,strlen(str)) == true) printf("成功匹配!");
else printf("匹配失败!");
return 0;
}