`.#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 isAllowedchar(char c) {
    return (isdigit(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 (isClosing(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;
}