#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(void) {
  int add1, add2, sum, i, j;
  char str1[127], copy[127], str2[127],
      a[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  while (scanf("%s\n", str1) != EOF) {
    for (i = 0; i < 10; i++) {
      strcpy(copy, str1);
      for (j = 0; j < strlen(copy); j++) {
        if (copy[j] == 'X') {
          copy[j] = a[i];
        }
      }
      sscanf(copy, "%d+%d=%d", &add1, &add2, &sum);
      sprintf(str2, "%d+%d=%d", add1, add2, sum);
      if (strlen(str1) != strlen(str2))
        continue;
      if (add1 + add2 == sum)
        break;
    }
    if (i == 10) {
      printf("NA\n");
    } else {
      printf("%d\n", i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x1aa(%rbp)
mov    0xe81(%rip),%ax
mov    %ax,-0x1a2(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1070 <scanf@plt>
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
je     1308 <main+0x1a8>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    12d5 <main+0x175>
lea    -0x120(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1b0(%rbp),%eax
cmp    %ecx,%eax
jge    123f <main+0xdf>
movslq -0x18(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x58,%eax
jne    122c <main+0xcc>
movslq -0x14(%rbp),%rax
mov    -0x1aa(%rbp,%rax,1),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
jmp    1231 <main+0xd1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11dc <main+0x7c>
lea    -0x120(%rbp),%rdi
lea    0xdc1(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1060 <sscanf@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xd98(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1b4(%rbp)
lea    -0x1a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1b4(%rbp),%eax
cmp    %ecx,%eax
je     12ae <main+0x14e>
jmp    12c7 <main+0x167>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    12c2 <main+0x162>
jmp    12d5 <main+0x175>
jmp    12c7 <main+0x167>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <main+0x58>
cmpl   $0xa,-0x14(%rbp)
jne    12f2 <main+0x192>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1303 <main+0x1a3>
mov    -0x14(%rbp),%esi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    118e <main+0x2e>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
lea    0xe82(%rip),%rdi
lea    0x90(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rax
jne    11b5 <main+0x45>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rbx
lea    0x90(%rsp),%r14
lea    0xe37(%rip),%r15
lea    0x110(%rsp),%r12
xor    %r13d,%r13d
jmp    120d <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
lea    0xe34(%rip),%rdi
call   1040 <puts@plt>
lea    0xe17(%rip),%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
mov    $0x0,%r13d
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <main+0x31>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1260 <main+0xf0>
xor    %ebp,%ebp
jmp    1243 <main+0xd3>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1260 <main+0xf0>
cmpb   $0x58,0x10(%rsp,%rbp,1)
jne    1230 <main+0xc0>
movzbl 0x0(%r13,%r15,1),%eax
mov    %al,0x10(%rsp,%rbp,1)
jmp    1230 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xda4(%rip),%rbp
mov    %rbp,%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1070 <sscanf@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %r12,%rdi
mov    %rbp,%rsi
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebp
jne    12e0 <main+0x170>
mov    0x8(%rsp),%eax
add    0xc(%rsp),%eax
cmp    0x4(%rsp),%eax
jne    12e0 <main+0x170>
cmp    $0xa,%r13d
je     11e0 <main+0x70>
lea    0xd49(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11ec <main+0x7c>
nopl   (%rax)
add    $0x1,%r13
cmp    $0xa,%r13
jne    120d <main+0x9d>
jmp    11e0 <main+0x70>

LLVM IR (-O0):
@__const.main.a = [10 x i8] c"0123456789"
@.str = [4 x i8] c"%s\0A\00"
@EOF = global i64 0
@.str.1 = [9 x i8] c"%d+%d=%d\00"
@.str.2 = [4 x i8] c"NA\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [127 x i8]
%8 = alloca [127 x i8]
%9 = alloca [127 x i8]
%10 = alloca [10 x i8]
store i32 0, i32* %1
%11 = bitcast [10 x i8]* %10 to i8*
br label %12
12: ; preds = %82, %0
%13 = getelementptr inbounds [127 x i8], [127 x i8]* %7, i64 0, i64 0
%14 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i64, i64* @EOF
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %83
17: ; preds = %12
store i32 0, i32* %5
br label %18
18: ; preds = %71, %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %74
21: ; preds = %18
%22 = getelementptr inbounds [127 x i8], [127 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds [127 x i8], [127 x i8]* %7, i64 0, i64 0
%24 = call i32 @strcpy(i8* %22, i8* %23)
store i32 0, i32* %6
br label %25
25: ; preds = %46, %21
%26 = load i32, i32* %6
%27 = getelementptr inbounds [127 x i8], [127 x i8]* %8, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %49
30: ; preds = %25
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [127 x i8], [127 x i8]* %8, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 88
br i1 %36, label %37, label %45
37: ; preds = %30
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [127 x i8], [127 x i8]* %8, i64 0, i64 %43
store i8 %41, i8* %44
br label %45
45: ; preds = %37, %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %25
49: ; preds = %25
%50 = getelementptr inbounds [127 x i8], [127 x i8]* %8, i64 0, i64 0
%51 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%52 = getelementptr inbounds [127 x i8], [127 x i8]* %9, i64 0, i64 0
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %53, i32 %54, i32 %55)
%57 = getelementptr inbounds [127 x i8], [127 x i8]* %7, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = getelementptr inbounds [127 x i8], [127 x i8]* %9, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %63
62: ; preds = %49
br label %71
63: ; preds = %49
%64 = load i32, i32* %2
%65 = load i32, i32* %3
%66 = add nsw i32 %64, %65
%67 = load i32, i32* %4
%68 = icmp eq i32 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %63
br label %74
70: ; preds = %63
br label %71
71: ; preds = %70, %62
%72 = load i32, i32* %5
%73 = add nsw i32 %72, 1
store i32 %73, i32* %5
br label %18
74: ; preds = %69, %18
%75 = load i32, i32* %5
%76 = icmp eq i32 %75, 10
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %82
79: ; preds = %74
%80 = load i32, i32* %5
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %79, %77
br label %12
83: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [10 x i8] c"0123456789"
@.str = [4 x i8] c"%s\0A\00"
@EOF = global i64 0
@.str.1 = [9 x i8] c"%d+%d=%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [3 x i8] c"NA\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [127 x i8]
%5 = alloca [127 x i8]
%6 = alloca [127 x i8]
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = getelementptr inbounds [127 x i8], [127 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [127 x i8], [127 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [127 x i8], [127 x i8]* %6, i64 0, i64 0
%13 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %66, label %16
16: ; preds = %0, %53
%17 = phi i64 [ %54, %53 ], [ 0, %0 ]
%18 = call i32 @strcpy(i8* %11, i8* %10)
%19 = call i32 @strlen(i8* %11)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = getelementptr inbounds [10 x i8], [10 x i8]* @__const.main.a, i64 0, i64 %17
br label %23
23: ; preds = %21, %30
%24 = phi i64 [ 0, %21 ], [ %31, %30 ]
%25 = getelementptr inbounds [127 x i8], [127 x i8]* %5, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 88
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = load i8, i8* %22
store i8 %29, i8* %25
br label %30
30: ; preds = %23, %28
%31 = add nuw nsw i64 %24, 1
%32 = call i32 @strlen(i8* %11)
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %23, label %35
35: ; preds = %30, %16
%36 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%37 = load i32, i32* %1
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %38, i32 %39)
%41 = call i32 @strlen(i8* %10)
%42 = call i32 @strlen(i8* %12)
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = load i32, i32* %1
%46 = load i32, i32* %2
%47 = add nsw i32 %46, %45
%48 = load i32, i32* %3
%49 = icmp eq i32 %47, %48
br i1 %49, label %55, label %50
50: ; preds = %44, %35
%51 = add nuw nsw i64 %17, 1
%52 = icmp eq i64 %51, 10
br i1 %52, label %58, label %53
53: ; preds = %50, %62
%54 = phi i64 [ %51, %50 ], [ 0, %62 ]
br label %16
55: ; preds = %44
%56 = trunc i64 %17 to i32
%57 = icmp eq i32 %56, 10
br i1 %57, label %58, label %60
58: ; preds = %50, %55
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %62
60: ; preds = %55
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %56)
br label %62
62: ; preds = %60, %58
%63 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%64 = load i64, i64* @EOF
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %53
66: ; preds = %62, %0
ret i32 0
}