#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 */

/* Variables and functions */
int /*<<< orphan*/ is_day_legit(int, int);
int /*<<< orphan*/ is_month_legit(int);
int last_dig(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char arr[12];
  int egn[10] = {0};
  int i, month = 0, day = 0;
  scanf("%s", arr);
  int l;
  l = strlen(arr);
  if (l != 10) {
    printf("0");
    return 0;
  }
  for (i = 0; i < 10; i++) {
    egn[i] = arr[i] - 48;
  }
  month = (egn[2] * 10) + egn[3];
  day = (egn[5] * 10) + egn[6];
  if (!is_month_legit(month) && !is_day_legit(day, month)) {
    printf("0");
    return 0;
  }
  if (egn[9] == last_dig(egn)) {
    printf("1");
  } else {
    printf("0");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
lea    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xa,-0x50(%rbp)
je     11db <main+0x6b>
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <main+0x12f>
movl   $0x0,-0x44(%rbp)
cmpl   $0xa,-0x44(%rbp)
jge    120e <main+0x9e>
movslq -0x44(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%ecx
sub    $0x30,%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e2 <main+0x72>
imul   $0xa,-0x38(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x48(%rbp)
imul   $0xa,-0x2c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%edi
call   1070 <is_month_legit@plt>
cmp    $0x0,%eax
jne    125f <main+0xef>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1030 <is_day_legit@plt>
cmp    $0x0,%eax
jne    125f <main+0xef>
lea    0xdb5(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <main+0x12f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    -0x40(%rbp),%rdi
call   1080 <last_dig@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jne    128c <main+0x11c>
lea    0xd83(%rip),%rdi
call   1050 <printf@plt>
jmp    1298 <main+0x128>
lea    0xd70(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xea1(%rip),%rdi
lea    0x4(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x30,%ebx
cmp    $0xa,%eax
jne    1255 <main+0xf5>
movd   0x4(%rsp),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
psrad  $0x18,%xmm0
movdqa 0xe53(%rip),%xmm1
paddd  %xmm1,%xmm0
movdqa %xmm0,0x20(%rsp)
movd   0x8(%rsp),%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
psrad  $0x18,%xmm2
paddd  %xmm1,%xmm2
movdqa %xmm2,0x10(%rsp)
movdqa %xmm2,0x30(%rsp)
movsbl 0xc(%rsp),%eax
add    $0xffffffd0,%eax
mov    %eax,0x40(%rsp)
movsbl 0xd(%rsp),%ebp
add    $0xffffffd0,%ebp
mov    %ebp,0x44(%rsp)
pshufd $0xee,%xmm0,%xmm1
movd   %xmm1,%eax
lea    (%rax,%rax,4),%eax
pshufd $0xff,%xmm0,%xmm0
movd   %xmm0,%ecx
lea    (%rcx,%rax,2),%r14d
mov    %r14d,%edi
call   1060 <is_month_legit@plt>
test   %eax,%eax
jne    1241 <main+0xe1>
movdqa 0x10(%rsp),%xmm1
pshufd $0x55,%xmm1,%xmm0
movd   %xmm0,%eax
lea    (%rax,%rax,4),%eax
pshufd $0xee,%xmm1,%xmm0
movd   %xmm0,%ecx
lea    (%rcx,%rax,2),%edi
mov    %r14d,%esi
call   1040 <is_day_legit@plt>
test   %eax,%eax
je     1255 <main+0xf5>
lea    0x20(%rsp),%rdi
call   1070 <last_dig@plt>
xor    %ebx,%ebx
cmp    %eax,%ebp
sete   %bl
or     $0x30,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [10 x i32]* %3 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %68
17: ; preds = %0
store i32 0, i32* %4
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 48
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %29
store i32 %27, i32* %30
br label %31
31: ; preds = %21
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %18
34: ; preds = %18
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
%36 = load i32, i32* %35
%37 = mul nsw i32 %36, 10
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 3
%39 = load i32, i32* %38
%40 = add nsw i32 %37, %39
store i32 %40, i32* %5
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 5
%42 = load i32, i32* %41
%43 = mul nsw i32 %42, 10
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 6
%45 = load i32, i32* %44
%46 = add nsw i32 %43, %45
store i32 %46, i32* %6
%47 = load i32, i32* %5
%48 = call i32 @is_month_legit(i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %57, label %50
50: ; preds = %34
%51 = load i32, i32* %6
%52 = load i32, i32* %5
%53 = call i32 @is_day_legit(i32 %51, i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %50
%56 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %68
57: ; preds = %50, %34
%58 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 9
%59 = load i32, i32* %58
%60 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%61 = call i32 @last_dig(i32* %60)
%62 = icmp eq i32 %59, %61
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %67
65: ; preds = %57
%66 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %67
67: ; preds = %65, %63
store i32 0, i32* %1
br label %68
68: ; preds = %67, %55, %15
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [10 x i32]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = bitcast [10 x i32]* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = call i32 @strlen(i8* %3)
%7 = icmp eq i32 %6, 10
br i1 %7, label %8, label %49
8: ; preds = %0
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%10 = bitcast [12 x i8]* %1 to <4 x i8>*
%11 = load <4 x i8>, <4 x i8>* %10
%12 = sext <4 x i8> %11 to <4 x i32>
%13 = add nsw <4 x i32> %12, <i32 -48, i32 -48, i32 -48, i32 -48>
%14 = bitcast [10 x i32]* %2 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %14
%15 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 4
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 4
%17 = bitcast i8* %15 to <4 x i8>*
%18 = load <4 x i8>, <4 x i8>* %17
%19 = sext <4 x i8> %18 to <4 x i32>
%20 = add nsw <4 x i32> %19, <i32 -48, i32 -48, i32 -48, i32 -48>
%21 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %21
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 8
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = add nsw i32 %24, -48
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 8
store i32 %25, i32* %26
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 9
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, -48
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 9
store i32 %30, i32* %31
%32 = extractelement <4 x i32> %13, i64 2
%33 = mul nsw i32 %32, 10
%34 = extractelement <4 x i32> %13, i64 3
%35 = add nsw i32 %33, %34
%36 = call i32 @is_month_legit(i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %8
%39 = extractelement <4 x i32> %20, i64 1
%40 = mul nsw i32 %39, 10
%41 = extractelement <4 x i32> %20, i64 2
%42 = add nsw i32 %40, %41
%43 = call i32 @is_day_legit(i32 %42, i32 %35)
%44 = icmp eq i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %38, %8
%46 = call i32 @last_dig(i32* %9)
%47 = icmp eq i32 %30, %46
%48 = select i1 %47, i32 49, i32 48
br label %49
49: ; preds = %45, %38, %0
%50 = phi i32 [ 48, %0 ], [ 48, %38 ], [ %48, %45 ]
%51 = call i32 @putchar(i32 %50)
ret i32 0
}