#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct Stack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char **, int *);
struct Stack *stack_create(int);
int /*<<< orphan*/ stack_destroy(struct Stack *);
scalar_t__ stack_is_empty(struct Stack *);
char stack_pop(struct Stack *);
int /*<<< orphan*/ stack_push(struct Stack *, char);
int main() {
  char *str = 0;
  int str_len = 0;
  int failure = 0;
  struct Stack *s;
  scanf("%m[^\n]%n", &str, &str_len);
  s = stack_create(str_len / 2);
  for (int i = 0; !failure && (i < str_len); ++i) {
    switch (str[i]) {
    case '(':
      stack_push(s, '(');
      break;
    case ')':
      if (stack_is_empty(s) || (stack_pop(s) != '(')) {
        failure = 1;
      }
      break;
    case '[':
      stack_push(s, '[');
      break;
    case ']':
      if (stack_is_empty(s) || (stack_pop(s) != '[')) {
        failure = 1;
      }
      break;
    case '{':
      stack_push(s, '{');
      break;
    case '}':
      if (stack_is_empty(s) || (stack_pop(s) != '{')) {
        failure = 1;
      }
      break;
    case '<':
      stack_push(s, '<');
      break;
    case '>':
      if (stack_is_empty(s) || (stack_pop(s) != '<')) {
        failure = 1;
      }
      break;
    }
  }
  if (!stack_is_empty(s)) {
    failure = 1;
  }
  printf("%s\n", failure ? "NO" : "YES");
  stack_destroy(s);
  free(str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe54(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <stack_create@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x25(%rbp)
jne    11f1 <main+0x71>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1201 <main+0x81>
jmp    13c4 <main+0x244>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x28,%eax
je     1295 <main+0x115>
jmp    121e <main+0x9e>
mov    -0x2c(%rbp),%eax
sub    $0x29,%eax
je     12a8 <main+0x128>
jmp    122f <main+0xaf>
mov    -0x2c(%rbp),%eax
sub    $0x3c,%eax
je     136a <main+0x1ea>
jmp    1240 <main+0xc0>
mov    -0x2c(%rbp),%eax
sub    $0x3e,%eax
je     137d <main+0x1fd>
jmp    1251 <main+0xd1>
mov    -0x2c(%rbp),%eax
sub    $0x5b,%eax
je     12dc <main+0x15c>
jmp    1262 <main+0xe2>
mov    -0x2c(%rbp),%eax
sub    $0x5d,%eax
je     12ef <main+0x16f>
jmp    1273 <main+0xf3>
mov    -0x2c(%rbp),%eax
sub    $0x7b,%eax
je     1323 <main+0x1a3>
jmp    1284 <main+0x104>
mov    -0x2c(%rbp),%eax
sub    $0x7d,%eax
je     1336 <main+0x1b6>
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
mov    $0x28,%esi
call   1090 <stack_push@plt>
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
call   1080 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    12d0 <main+0x150>
mov    -0x20(%rbp),%rdi
call   10a0 <stack_pop@plt>
movsbl %al,%eax
cmp    $0x28,%eax
je     12d7 <main+0x157>
movl   $0x1,-0x18(%rbp)
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
mov    $0x5b,%esi
call   1090 <stack_push@plt>
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
call   1080 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    1317 <main+0x197>
mov    -0x20(%rbp),%rdi
call   10a0 <stack_pop@plt>
movsbl %al,%eax
cmp    $0x5b,%eax
je     131e <main+0x19e>
movl   $0x1,-0x18(%rbp)
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
mov    $0x7b,%esi
call   1090 <stack_push@plt>
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
call   1080 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    135e <main+0x1de>
mov    -0x20(%rbp),%rdi
call   10a0 <stack_pop@plt>
movsbl %al,%eax
cmp    $0x7b,%eax
je     1365 <main+0x1e5>
movl   $0x1,-0x18(%rbp)
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
mov    $0x3c,%esi
call   1090 <stack_push@plt>
jmp    13b1 <main+0x231>
mov    -0x20(%rbp),%rdi
call   1080 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    13a5 <main+0x225>
mov    -0x20(%rbp),%rdi
call   10a0 <stack_pop@plt>
movsbl %al,%eax
cmp    $0x3c,%eax
je     13ac <main+0x22c>
movl   $0x1,-0x18(%rbp)
jmp    13b1 <main+0x231>
jmp    13b6 <main+0x236>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d6 <main+0x56>
mov    -0x20(%rbp),%rdi
call   1080 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    13de <main+0x25e>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
lea    0xc28(%rip),%rsi
lea    0xc1e(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xc0c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <stack_destroy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xf36(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1050 <stack_create@plt>
mov    %rax,%rbx
mov    $0x1,%r14b
cmpl   $0x0,0xc(%rsp)
jle    12b4 <main+0x134>
xor    %ebp,%ebp
lea    0xe23(%rip),%r15
jmp    11fe <main+0x7e>
mov    $0x5b,%al
movzbl %al,%esi
mov    %rbx,%rdi
call   1090 <stack_push@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jge    12b4 <main+0x134>
mov    0x10(%rsp),%rax
movsbl (%rax,%rbp,1),%eax
lea    -0x28(%rax),%ecx
cmp    $0x35,%ecx
ja     1240 <main+0xc0>
mov    $0x28,%al
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    %rbx,%rdi
call   1080 <stack_is_empty@plt>
test   %rax,%rax
jne    12b1 <main+0x131>
mov    %rbx,%rdi
call   10a0 <stack_pop@plt>
cmp    $0x28,%al
je     11ec <main+0x6c>
jmp    12b1 <main+0x131>
nopl   0x0(%rax)
cmp    $0x7b,%eax
je     12aa <main+0x12a>
cmp    $0x7d,%eax
jne    11ec <main+0x6c>
mov    %rbx,%rdi
call   1080 <stack_is_empty@plt>
test   %rax,%rax
jne    12b1 <main+0x131>
mov    %rbx,%rdi
call   10a0 <stack_pop@plt>
cmp    $0x7b,%al
je     11ec <main+0x6c>
jmp    12b1 <main+0x131>
mov    $0x3c,%al
jmp    11e1 <main+0x61>
mov    %rbx,%rdi
call   1080 <stack_is_empty@plt>
test   %rax,%rax
jne    12b1 <main+0x131>
mov    %rbx,%rdi
call   10a0 <stack_pop@plt>
cmp    $0x3c,%al
je     11ec <main+0x6c>
jmp    12b1 <main+0x131>
mov    %rbx,%rdi
call   1080 <stack_is_empty@plt>
test   %rax,%rax
jne    12b1 <main+0x131>
mov    %rbx,%rdi
call   10a0 <stack_pop@plt>
cmp    $0x5b,%al
je     11ec <main+0x6c>
jmp    12b1 <main+0x131>
mov    $0x7b,%al
jmp    11e1 <main+0x61>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1080 <stack_is_empty@plt>
test   %rax,%rax
lea    0xe22(%rip),%rsi
lea    0xe18(%rip),%rax
cmove  %rax,%rsi
test   %r14b,%r14b
cmove  %rax,%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <stack_destroy@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Stack = type { i32 }
@.str = [9 x i8] c"%m[^\0A]%n\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [3 x i8] c"NO\00"
@.str.3 = [4 x i8] c"YES\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.Stack*
%6 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2, i32* %3)
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 2
%10 = call %struct.Stack* @stack_create(i32 %9)
store %struct.Stack* %10, %struct.Stack** %5
store i32 0, i32* %6
br label %11
11: ; preds = %84, %0
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %20, label %87
20: ; preds = %18
%21 = load i8*, i8** %2
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %83 [
i32 40, label %27
i32 41, label %30
i32 91, label %41
i32 93, label %44
i32 123, label %55
i32 125, label %58
i32 60, label %69
i32 62, label %72
]
27: ; preds = %20
%28 = load %struct.Stack*, %struct.Stack** %5
%29 = call i32 @stack_push(%struct.Stack* %28, i8 signext 40)
br label %83
30: ; preds = %20
%31 = load %struct.Stack*, %struct.Stack** %5
%32 = call i64 @stack_is_empty(%struct.Stack* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load %struct.Stack*, %struct.Stack** %5
%36 = call signext i8 @stack_pop(%struct.Stack* %35)
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 40
br i1 %38, label %39, label %40
39: ; preds = %34, %30
store i32 1, i32* %4
br label %40
40: ; preds = %39, %34
br label %83
41: ; preds = %20
%42 = load %struct.Stack*, %struct.Stack** %5
%43 = call i32 @stack_push(%struct.Stack* %42, i8 signext 91)
br label %83
44: ; preds = %20
%45 = load %struct.Stack*, %struct.Stack** %5
%46 = call i64 @stack_is_empty(%struct.Stack* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %44
%49 = load %struct.Stack*, %struct.Stack** %5
%50 = call signext i8 @stack_pop(%struct.Stack* %49)
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 91
br i1 %52, label %53, label %54
53: ; preds = %48, %44
store i32 1, i32* %4
br label %54
54: ; preds = %53, %48
br label %83
55: ; preds = %20
%56 = load %struct.Stack*, %struct.Stack** %5
%57 = call i32 @stack_push(%struct.Stack* %56, i8 signext 123)
br label %83
58: ; preds = %20
%59 = load %struct.Stack*, %struct.Stack** %5
%60 = call i64 @stack_is_empty(%struct.Stack* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %67, label %62
62: ; preds = %58
%63 = load %struct.Stack*, %struct.Stack** %5
%64 = call signext i8 @stack_pop(%struct.Stack* %63)
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 123
br i1 %66, label %67, label %68
67: ; preds = %62, %58
store i32 1, i32* %4
br label %68
68: ; preds = %67, %62
br label %83
69: ; preds = %20
%70 = load %struct.Stack*, %struct.Stack** %5
%71 = call i32 @stack_push(%struct.Stack* %70, i8 signext 60)
br label %83
72: ; preds = %20
%73 = load %struct.Stack*, %struct.Stack** %5
%74 = call i64 @stack_is_empty(%struct.Stack* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %81, label %76
76: ; preds = %72
%77 = load %struct.Stack*, %struct.Stack** %5
%78 = call signext i8 @stack_pop(%struct.Stack* %77)
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 60
br i1 %80, label %81, label %82
81: ; preds = %76, %72
store i32 1, i32* %4
br label %82
82: ; preds = %81, %76
br label %83
83: ; preds = %20, %82, %69, %68, %55, %54, %41, %40, %27
br label %84
84: ; preds = %83
%85 = load i32, i32* %6
%86 = add nsw i32 %85, 1
store i32 %86, i32* %6
br label %11
87: ; preds = %18
%88 = load %struct.Stack*, %struct.Stack** %5
%89 = call i64 @stack_is_empty(%struct.Stack* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %92, label %91
91: ; preds = %87
store i32 1, i32* %4
br label %92
92: ; preds = %91, %87
%93 = load i32, i32* %4
%94 = icmp ne i32 %93, 0
%95 = zext i1 %94 to i64
%96 = select i1 %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%97 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %96)
%98 = load %struct.Stack*, %struct.Stack** %5
%99 = call i32 @stack_destroy(%struct.Stack* %98)
%100 = load i8*, i8** %2
%101 = call i32 @free(i8* %100)
%102 = load i32, i32* %1
ret i32 %102
}

LLVM IR (-O2):
%struct.Stack = type { i32 }
@.str = [9 x i8] c"%m[^\0A]%n\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [3 x i8] c"NO\00"
@.str.3 = [4 x i8] c"YES\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i32
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %1, i32* %2)
%6 = load i32, i32* %2
%7 = sdiv i32 %6, 2
%8 = call %struct.Stack* @stack_create(i32 %7)
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %48, %51, %41, %44, %34, %37, %27, %30, %57, %0
%12 = phi i1 [ true, %0 ], [ false, %48 ], [ false, %51 ], [ false, %41 ], [ false, %44 ], [ false, %34 ], [ false, %37 ], [ false, %27 ], [ false, %30 ], [ true, %57 ]
%13 = call i64 @stack_is_empty(%struct.Stack* %8)
%14 = icmp ne i64 %13, 0
%15 = and i1 %12, %14
%16 = select i1 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @stack_destroy(%struct.Stack* %8)
%19 = load i8*, i8** %1
%20 = call i32 @free(i8* %19)
ret i32 0
21: ; preds = %0, %57
%22 = phi i64 [ %58, %57 ], [ 0, %0 ]
%23 = load i8*, i8** %1
%24 = getelementptr inbounds i8, i8* %23, i64 %22
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %57 [
i32 40, label %54
i32 41, label %27
i32 91, label %33
i32 93, label %34
i32 123, label %40
i32 125, label %41
i32 60, label %47
i32 62, label %48
]
27: ; preds = %21
%28 = call i64 @stack_is_empty(%struct.Stack* %8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %11
30: ; preds = %27
%31 = call signext i8 @stack_pop(%struct.Stack* %8)
%32 = icmp eq i8 %31, 40
br i1 %32, label %57, label %11
33: ; preds = %21
br label %54
34: ; preds = %21
%35 = call i64 @stack_is_empty(%struct.Stack* %8)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %11
37: ; preds = %34
%38 = call signext i8 @stack_pop(%struct.Stack* %8)
%39 = icmp eq i8 %38, 91
br i1 %39, label %57, label %11
40: ; preds = %21
br label %54
41: ; preds = %21
%42 = call i64 @stack_is_empty(%struct.Stack* %8)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %11
44: ; preds = %41
%45 = call signext i8 @stack_pop(%struct.Stack* %8)
%46 = icmp eq i8 %45, 123
br i1 %46, label %57, label %11
47: ; preds = %21
br label %54
48: ; preds = %21
%49 = call i64 @stack_is_empty(%struct.Stack* %8)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %11
51: ; preds = %48
%52 = call signext i8 @stack_pop(%struct.Stack* %8)
%53 = icmp eq i8 %52, 60
br i1 %53, label %57, label %11
54: ; preds = %21, %47, %40, %33
%55 = phi i8 [ 91, %33 ], [ 123, %40 ], [ 60, %47 ], [ 40, %21 ]
%56 = call i32 @stack_push(%struct.Stack* %8, i8 signext %55)
br label %57
57: ; preds = %54, %21, %30, %37, %44, %51
%58 = add nuw nsw i64 %22, 1
%59 = load i32, i32* %2
%60 = sext i32 %59 to i64
%61 = icmp slt i64 %58, %60
br i1 %61, label %21, label %11
}