• + 0 comments
    import java.util.*;
    class Solution{
    	
    	public static void main(String []argh)
    	{
    		Scanner sc = new Scanner(System.in);
    		while (sc.hasNext()) {
    			String input=sc.next();
                Deque <Character> q = new ArrayDeque<>();
                Deque <Character> q1 = new ArrayDeque<>();
                char [] arr = input.toCharArray();
                for (char c: arr){
                    q.push(c);
                }
                boolean p = false;
                while (!q.isEmpty()){
                    char c = q.pop();
                    if (c=='}' || c==')' || c==']' ){
                        q1.push(c);
                    }
                    if ((c=='{' || c=='(' || c=='[')){
                        if (q1.isEmpty()){
                            p=false;
                            break;
                        }
                        if (c=='{' && q1.pop()=='}') p=true;
                        else if (c=='(' && q1.pop()==')') p=true;
                        else if (c=='[' && q1.pop()==']') p=true;
                        else{
                            p=false;
                            break;
                        }
                    }
                }
                if (!q1.isEmpty()){
                    p=false;
                }
                System.out.println(p);
                //sc.close();
    		}
    		
    	}
    }