/*
AizuOnline A1137
Maximum Sum Sequence
*/
#include <stdio.h>
char buffer[101];
char stack[100];
int  sp;


main()
{
  char *p;

  while(NULL != fgets(buffer,100,stdin) && buffer[0]!='.')
    {
      p=buffer;
      sp=0;
      while(*p != '.' && *p)
	{
	  if(*p=='(' || *p== '[')
	    {  stack[sp]=*p;
	      sp++;
	    }
	  if(*p==')' )
	    if(stack[sp-1]=='(')
	      sp--;
	    else
	      goto NOMATCH;
	  if(*p==']' )
	    { 
	      if(sp < 1)
		goto NOMATCH;

	      if(stack[sp-1]=='[')
		sp--;
	      else
		goto NOMATCH;
	    }
	  p++;
	}
      if(sp==0)
	{
	  printf("YES\n");
	  continue;
	}
    NOMATCH:
      printf("NO\n");
    }
return(0);
}