#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#define MAX_STACK_SIZE 200
typedef char element;
typedef struct StackType {
element data[MAX_STACK_SIZE];
int top;
}StackType;
void init_stack(StackType* s) {
s->top = -1;
}
int is_empty(StackType* s) {
return (s->top == -1);
}
// top은 현재 최고 높이 요소의 인덱스, 스택이 꽉차면 스택 크기 - 1
int is_full(StackType* s) {
return (s->top == (MAX_STACK_SIZE - 1));
}
void push(StackType* s, element item) {
if (is_full(s)) {
return;
}
else
s->data[++(s->top)] = item;
}
char pop(StackType* s) {
if (is_empty(s)) {
return;
}
else
return s->data[(s->top)--];
}
int check_valid(char* string) {
StackType s;
char ch1, ch2;
init_stack(&s);
for (int i = 0; i < n; i++) {
ch1 = string[i];
if (ch1 == '(' || ch1 == '[') {
push(&s, ch1);
}
else if (ch1 == ')' || ch1 == ']') {
if (is_empty(&s)) return 0;
else {
ch2 = pop(&s);
if (!((ch1 == ')' && ch2 == '(') || (ch1 == ']' && ch2 == '['))) {
return 0;
}
}
}
}
if (!is_empty(&s)) return 0;
return 1;
}
int main() {
char string[MAX_STACK_SIZE];
int num = 0;
scanf("%[^\n]s", string
);
if (check_valid
(string
)) printf("yes\n");
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBNQVhfU1RBQ0tfU0laRSAyMDAKCnR5cGVkZWYgY2hhciBlbGVtZW50OwoKdHlwZWRlZiBzdHJ1Y3QgU3RhY2tUeXBlIHsKCWVsZW1lbnQgZGF0YVtNQVhfU1RBQ0tfU0laRV07CglpbnQgdG9wOwp9U3RhY2tUeXBlOwoKdm9pZCBpbml0X3N0YWNrKFN0YWNrVHlwZSogcykgewoJcy0+dG9wID0gLTE7Cn0KCmludCBpc19lbXB0eShTdGFja1R5cGUqIHMpIHsKCXJldHVybiAocy0+dG9wID09IC0xKTsKfQoK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