#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100000
char stack[MAX];
int top = -1;
void push(char c) {
    if (top < MAX - 1) {
        stack[++top] = c;
    }
}
char pop(){
    if (top >= 0) {
        return stack[top--];
    }
    return -1;
}
 char peek(){
     if (top >=0) return stack[top];
     return -1;
 }
 int isopening(char c) {
     return (c == '('||c == '['||c == '{');
 }
 int isclosing(char c){
     return (c == ')'|| c == ']'|| c == '}');
 }
 int isMatching(char open,char close) {
     return (( open =='('&& close == ')') ||
             (open == '['&& close == ']') ||
             (open == '{'&& close == '}'));
 }
 int isValidSequence(char *exp) {
     int len = strlen(exp);
     for (int i = 0;i<len; i++){
         char c= exp[i];
         if (!isAllowedchar(c)) {
             return -1;
         }
         if (isopening(c)){
             if (top == -1|| !isMatching(pop(),c)) {
                 return 0;
             }
         }
         
     }
     if (top != -1) {
         return 0;
     }
     return 1;
 }
 int main() {
     char expression[MAX];
     if (!fgets(expression,sizeof (expression),stdin)) {
         printf("Invalid input\n");
         return 0;
     }
     int result = isValidSequence(expression);
     if (result == -1) {
         printf("Invalid input\n");
     }
     else if (result == 0) {
         printf("Invalid Sequence\n");
     }
     else{
         printf("valid Sequence\n");
     }
     return 0;
 }