import java.util.*;
//任意输入一段含括号的式子,判断括号是否匹配
public class QueueAndStack {
public static boolean isGoodBracket(String s) {
//建立一个字符堆栈
Stack<Character> a = new Stack<Character>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '(')
a.push(')');
if (c == '[')
a.push(']');
if (c == '{')
a.push('}');
if (c == ')' || c == ']' || c == '}') {
if (a.size()==0)
return false;
if (a.pop() != c)
return false;
}
}
if (a.size()!=0)
return false;
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
boolean result = isGoodBracket(s);
System.out.println(result);
}
}
//任意输入一段含括号的式子,判断括号是否匹配
public class QueueAndStack {
public static boolean isGoodBracket(String s) {
//建立一个字符堆栈
Stack<Character> a = new Stack<Character>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '(')
a.push(')');
if (c == '[')
a.push(']');
if (c == '{')
a.push('}');
if (c == ')' || c == ']' || c == '}') {
if (a.size()==0)
return false;
if (a.pop() != c)
return false;
}
}
if (a.size()!=0)
return false;
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
boolean result = isGoodBracket(s);
System.out.println(result);
}
}