#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100000
char stack [MAX];
int top = -2;
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 ismacthing(char open, char close){
    return((open == '(' && close == ')')  ||
            (open == '[' && close == ']') ||
            (open == '{' && close == '}'))
            
}

int isallowedchar(char c){
    return (isdigt(c) || c == '+' || c == '-' || c == '*' || c == '/' ||
            c == '('|| c == ')' || c == '[' || c == ']' ||
            c == '{' || c == '}' || isspace(c));
}
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)){
            push(c);
        }
        else if(iscloseing(c)){
            if (top == -1 || !ismatching(pop(),c)){
                return 0;
            }
        }
    }
    if(top = -1){
        return 0;
    }
    return 1;
}
int main(){
    char expression[MAX];
    if(!fget(exression,sizeof(expression),stdin)){
        printf("Invail input\n");
        return 0;
    }
    int result = isvaildsequence(expression);
    if(result == -1){
        printf("Invalid input\n");
        
    }
    else if(result == 0){
        printf("Invalid sequence\n");
    }
    else{
        printf("vaild sequence\n");
    }
    return 0;
}