Problem:


覆面算

 数式の一部を隠してしまって、隠した数字を探す問題を覆面算といいます。今回は、数式の中のある数字のいくつかを X で隠してしまった式を扱います。以下の数式を入力して、結果を出力するプログラムを作成してください。

  数式

「数字列 + 数字列 = 数字列」の形で、1 行の単純な足し算式です。

 「数字列」は、数字 0 から 9 と文字 X の並びです。

 2 桁以上の「数字列」の左端の数字は 0 ではないものとします。

  X は、数式全体の中で必ず 1 つ以上含まれます。

  結果

  覆面算の答えです。数式が成り立つ様な X の値で 0 ~ 9 のどれか 1 つです。2 つ以上の答えはないものとします。

  答えがない場合、結果は“NA”としてください。

Input

複数のデータセットが与えられます。各データセットとして、X を 1 つ以上含む足し算式(空白を含まない 126 文字以内の文字列) が１行に与えられます。データセットの数は 150 を超えません。

Output

各データセットについて、覆面算の結果を１行に出力してください。数字 0 ~ 9 または NA を出力してください。

Sample Input

123+4X6=X79
12X+4X6=X79
XX22+89=X2XX

Output for the Sample Input

5
NA
1



Sample input:
123+4X6=X79
12X+4X6=X79
XX22+89=X2XX


Sample output:
5
NA
1

Submission status: Wrong Answer

Solution code:
while True:
    try:
        s = input().replace('=', '==')
    except EOFError:
        break

    for x in '0123456789':
        t = s.replace('X', x)
        if t[0] == '0' or t[t.index('+')+1] == '0' or t[t.index('=')+2] == '0':
            continue
        if eval(t):
            print(x)
            break
    else:
        print('NA')

Submission status: Wrong Answer

Solution code:
while(True):
    try:
        a,b = input().split("=")
        for i in range(10):
            if not i and len([1 for c in a.split("+") if c[0]=="X" ]):
                continue
            if eval(a.replace("X",str(i))) == int(b.replace("X",str(i))):
                print(i)
                break
        else:
            print("NA")
    except:
        break

Submission status: Wrong Answer

Solution code:
while(True):
    try:
        a,b = input().split("=")
        for i in range(10):
            if not i and (len([1 for c in a.split("+") if c[0]=="X"]) or b[0]=="X"):
                continue
            if eval(a.replace("X",str(i))) == int(b.replace("X",str(i))):
                print(i)
                break
        else:
            print("NA")
    except:
        break

Submission status: Wrong Answer

Solution code:
while(True):
    try:
        a,c = input().split("=")
        a,b = a.split("+")
        for i in range(10):
            if i==0 and ( a[0]=="X" or b[0]=="X" or c[0]=="X"):
                continue
            if int(a.replace("X",str(i)))+int(b.replace("X",str(i))) == int(c.replace("X",str(i))):
                print(i)
                break
        else:
            print("NA")
    except:
        break

Submission status: Wrong Answer

Solution code:
#import math

def correct(a,b,c):
    if a + b == c:
        return True
    else:
        return False

def cheak(x):
    p = x.find("X")
    if p == 0:
        return False
    return True

def change(x,k):
    p = x.find("X")
    if p == -1:
        return int(x)
    xx = x.replace("X",str(k))
    return int(xx)

def find(a,b,c):
    if cheak(a) and cheak(b) and cheak(c):
        for i in range(0,9):
            if correct(change(a,i),change(b,i),change(c,i)):
                print(i)
                return
    else:
        for i in range(1,9):
            if correct(change(a, i), change(b, i), change(c, i)):
                print(i)
                return
    print("NA")

while True:
     try:
        ab,c = list(input().split("="))
        a,b = list(ab.split("+"))
        find(a, b, c)
     except:
         break

Submission status: Wrong Answer

Solution code:
#import math

def correct(a,b,c):
    if a + b == c:
        return True
    else:
        return False

def cheak(x):
    p = x.find("X")
    if p == 0:
        return False
    return True

def change(x,k):
    p = x.find("X")
    if p == -1:
        return int(x)
    xx = x.replace("X",str(k))
    return int(xx)

def find(a,b,c):
    if cheak(a) and cheak(b) and cheak(c):
        for i in range(10):
            if correct(change(a,i),change(b,i),change(c,i)):
                print(i)
                return
    else:
        for i in range(1,10):
            if correct(change(a, i), change(b, i), change(c, i)):
                print(i)
                return
    print("NA")

while True:
     try:
        ab,c = list(input().split("="))
        a,b = list(ab.split("+"))
        find(a, b, c)
     except:
         break

Submission status: Wrong Answer

Solution code:
#import math

def correct(a,b,c):
    if int(a) + int(b) == int(c):
        return True
    else:
        return False

def cheak(x):
    p = x.find("X")
    if p == 0 and len(x) > 1:
        return False
    return True

def find(a,b,c):
    for i in range(0,10):
        if i == 0 and cheak(a) and cheak(b) and cheak(c):
            continue
        if correct(a.replace("X",str(i)),b.replace("X",str(i)),c.replace("X",str(i))):
            print(i)
            return
    print("NA")

while True:
    try:
        ab,c = list(input().split("="))
    except:
        break
    a,b = list(ab.split("+"))
    find(a, b, c)

Submission status: Wrong Answer

Solution code:
#import math

def correct(a,b,c):
    if int(a) + int(b) == int(c):
        return True
    else:
        return False

def cheak(x):
    if x[0] == "X" and len(x) > 1:
        return True
    return False

def find(ss):
    for i in range(0,10):
        s = ss.replace("X",str(i))
        ab, c = list(s.split("="))
        a, b = list(ab.split("+"))
        if i == 0 and (cheak(a) or cheak(b) or cheak(c)):
            continue
        if correct(a,b,c):
            print(i)
            return
    print("NA")

while True:
    try:
        s = input()
        find(s)
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        s_origin=input()
        for X in range(10):
            s=s_origin.replace("X",str(X))
            s=s.split("=")
            s[1]=int(s[1])
            a,b=s[0].split("+")
            if int(a)+int(b)==s[1]:
                print(X)
                break
        else:
            print("NA")
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import re
while True:
    try:
        s_origin=input()
        for X in range(10):
            s=s_origin.replace("X",str(X))
            if re.search("^0|\+0|=0",s)!=None:
                continue
            if eval(s.replace("=","==")):
                print(X)
                break
        else:
            print("NA")
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = input()
        x = None

        for i in range(10):
            formula = n.replace('X', str(i))
            left, right = formula.split('=')
            if eval(left.lstrip('0')) == int(right):
                x = i

        if x:
            print(x)
        else:
            print('NA')
    except:
       break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = input()
        x = None

        for i in range(10):
            formula = n.replace('X', str(i))
            l, r = formula.split('=')
            l1, l2 = l.split('+')
            if int(l1) + int(l2) == int(r):
                x = i

        if x:
            print(x)
        else:
            print('NA')
    except:
       break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = input()
        x = None

        for i in range(10):
            formula = n.replace('X', str(i))
            l, r = formula.split('=')
            l1, l2 = l.split('+')
            if l1[0] == '0' or l2[0] == '0':
                continue
            if eval(l) == int(r):
                x = i

        if x:
            print(x)
        else:
            print('NA')
    except:
       break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = input()
        x = None

        for i in range(10):
            formula = n.replace('X', str(i))
            l, r = formula.split('=')
            l1, l2 = l.split('+')
            if l1[0] == '0' or l2[0] == '0' or r[0] == '0':
                continue
            print(l, r)
            if eval(l) == int(r):
                x = i

        if x:
            print(x)
        else:
            print('NA')
    except:
       break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = input()
        x = None

        for i in range(10):
            formula = n.replace('X', str(i))
            l, r = formula.split('=')
            l1, l2 = l.split('+')
            if l1[0] == '0' or l2[0] == '0' or r[0] == '0':
                continue
            if eval(l+'=='+r):
                x = i
        if x:
            print(x)
        else:
            print('NA')
    except:
       break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        flag = False
        ls,rs = map(str,raw_input().split('='))
        for i in range(10):
            if i == 0 and (ls[0] == 'X' or ls.split('+')[1][0] == 'X' or rs[0] == 'X'):
                continue
            if eval(ls.replace('X',str(i))) == eval(rs.replace('X',str(i))):
                print i
                flag = True
                break
        if not flag:
            print 'NA'
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        flag = False
        l,r = map(str,raw_input().split('='))
        l1,l2 = l.split('+')
        
        flag = True        
        for i in range(10):
            if i == 0 and (l1[0] == 'X' or l2[0] == 'X' or r[0] == 'X'):
                continue
            elif int(l1.replace('X',str(i)))+int(l2.replace('X',str(i))) == int(r.replace('X',str(i))):
                print i
                flag = False
        if flag:
            print 'NA'
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        flag = False
        l,r = map(str,raw_input().split('='))
        l1,l2 = l.split('+')
        
        flag = True        
        for i in range(10):
            if i == 0 and (l1[0] == 'X' or l2[0] == 'X' or r[0] == 'X'):
                pass
            elif int(l1.replace('X',str(i)))+int(l2.replace('X',str(i))) == int(r.replace('X',str(i))):
                print i
                flag = False
        if flag:
            print 'NA'
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        flag = False
        l,r = map(str,raw_input().split('='))
        l1,l2 = map(str,l.split('+'))
        
        flag = True        
        for i in range(10):
            if i == 0 and (l1[0] == 'X' or l2[0] == 'X' or r[0] == 'X'):
                pass
            elif int(l1.replace('X',str(i)))+int(l2.replace('X',str(i))) == int(r.replace('X',str(i))):
                print i
                flag = False
        if flag:
            print 'NA'
    except:
        break

Submission status: Wrong Answer

Solution code:
# Edit: 2014/09/28
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":
    while True:
        try:
            st0 = input()
            # print(st0)
            st0 = st0.replace("+", ",").replace("=", ",")
            #print(st0)
            #strA, strB, strC = str.split(",")
            #print(strA, strB, strC)

            for i in range(10):
                #print(i,str(i))
                a, b, c = st0.replace("X", str(i)).split(",")
                #print(strI)
                #pass
                if int(a) + int(b) == int(c):
                    print(i)
                    break
            else:
                print("NA")
        except:
            break

Submission status: Wrong Answer

Solution code:
# Edit: 2014/09/28
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":
    while True:
        try:
            st0 = input()
            # print(st0)
            st0 = st0.strip("\n").replace("+", ",").replace("=", ",")
            #print(st0)
            #strA, strB, strC = str.split(",")
            #print(strA, strB, strC)

            for i in range(10):
                #print(i,str(i))
                a, b, c = st0.replace("X", str(i)).split(",")
                #print(strI)
                #pass
                if int(a) + int(b) == int(c):
                    print(i)
                    break
            else:
                print("NA")
        except:
            break

Submission status: Wrong Answer

Solution code:
# Edit: 2014/09/28
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":
    while True:
        try:
            st0 = input()
            # print(st0)
            st0 = st0.strip("\n").replace("+", ",").replace("=", ",")
            # print(st0)
            #strA, strB, strC = str.split(",")
            #print(strA, strB, strC)

            for i in range(10):
                #print(i,str(i))
                a, b, c = st0.replace("X", str(i)).split(",")
                if a[0] == "0" or b[0] == "0" or c[0] == "0":
                    continue
                #print(strI)
                #pass
                if int(a) + int(b) == int(c):
                    print(i)
                    break
            else:
                print("NA")
        except:
            break

Submission status: Wrong Answer

Solution code:
import sys

X="X"
N="0123456789"
for s in sys.stdin:
  i=s.find("=")
  j=s.find("+")
  k=s[0]==X or s[i+1]==X or s[j+1]==X
  f=0
  for c in N[k:]:
    a=s.replace(X,c)
    if eval(a[:i])==eval(a[i+1:]): f=1; break
  print ["NA",c][f]

Submission status: Wrong Answer

Solution code:
import sys

for s in sys.stdin:
  i=s.find("+")
  j=s.find("=")
  A=[s[0:i],s[i+1:j],s[j+1:-1]]

  m="NA"
  for c in "0123456789":
    try: x,y,z=map(int,[e.replace("X",c) for e in A])
    except: continue
    if x+y==z: m=c; break
  print m

Submission status: Wrong Answer

Solution code:
import sys

for s in sys.stdin:
  i=s.find("+")
  j=s.find("=")
  A=[s[0:i],s[i+1:j],s[j+1:-1]]

  m="NA"
  for c in "0123456789":
    try:
      x,y,z=map(int,[e.replace("X",c) for e in A])
      if x+y==z: m=c; break
    except: pass
  print m

Submission status: Wrong Answer

Solution code:
import sys

for s in sys.stdin:
  m="NA"
  s=s[:-1].replace("=","==")
  for c in "0123456789":
    try:
      if eval(s.replace("X",c)): m=c; break
    except: pass
  print m

Submission status: Wrong Answer

Solution code:
import sys, re

def f(s):
    for i in range(0,10):
        t = s.replace("X", str(i))
        a, b, c = map(int, re.split(r'\+|\=', t))
        if a + b == c and str(a) + "+" + str(b) + "=" + str(c) == t:
            return i
    return "NA"

for s in sys.stdin:
    print f(s)

Submission status: Wrong Answer

Solution code:
import sys
formula = raw_input().split("=")
sum = formula[1]
left = formula[0].split("+")
a = left[0]
b = left[1]
for i in range(10):
    if (i == 0 and (len(a) > 1 and a[0] == 'X' or len (b) and b[0] == 'X')):
        continue
    else:
        A = int(a.replace('X', str(i)))
        B = int(b.replace('X', str(i)))
        Sum = int(sum.replace("X", str(i)))
        if (A + B == Sum):
            print i
            sys.exit()

print "NA"

Submission status: Wrong Answer

Solution code:
while(1):
    try:
        eq=raw_input()
    except:
        break
    N=[0,0,0] #C,B,A
    D=[0,0,0]
    n=0
    d=0
    Xtop=0
    na=1
    for c in eq[::-1]:
        print c
        if c=='+'or'=':
            d=0
            n=n+1
        elif c=='X':
            D[n]=D[n]+10**d
            d=d+1
        else:
            N[n]=N[n]+int(c)*10**d
            d=d+1
    for i in range(3):
        if D[i]>N[i]:
            Xtop=1
    print N,D
    for i in range(10):
        if N[0]+D[0]*i==N[1]+D[1]*i+N[2]+D[2]*i:
            if not (Xtop and i==0):
                print i
                na=0
                break
    if na:
        print 'NA'

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
while True:
    try:
        left,right = raw_input().split("=")
    except EOFError:
        break
    
    first,second = left.split("+")
    for x in range(10):
        tmpf = first
        tmps = second
        tmpr = right
        if "X" in first:
            tmpf = first.replace("X",str(x))
        if "X" in second:
            tmps = second.replace("X",str(x))
        if "X" in right:
            tmpr = right.replace("X",str(x))
        
        if int(tmpf)+int(tmps)==int(tmpr):
            print x
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
while True:
    try:
        left,right = raw_input().split("=")
    except EOFError:
        break
    
    first,second = left.split("+")
    for x in range(10):
        tmpf = first
        tmps = second
        tmpr = right
        if "X" in first:
            tmpf = first.replace("X",str(x))
        if "X" in second:
            tmps = second.replace("X",str(x))
        if "X" in right:
            tmpr = right.replace("X",str(x))
        a = len(tmpf)>=2 and tmps[0] != "0" 
        b = len(tmps)>=2 and tmps[0] != "0"
        c = len(tmpr)>=2 and tmps[0] != "0"

        if all((a,b,c,int(tmpf)+int(tmps)==int(tmpr))):
            print x
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        string = raw_input()
    except EOFError:
        break
    for i in range(10):
        translated = string.replace("X",str(i))
        left,right = translated.split("=")
        right = int(right)
        first,second = map(int,left.split("+"))
        if first + second == right:
            print i
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        string = raw_input()
    except EOFError:
        break
    for i in range(10):
        translated = string.replace("X",str(i))
        left,right = translated.split("=")
        first,second = left.split("+")
        if i == 0 and (first[0]=="0" or second[0]=="0" or right[0]=="0"):
            continue
        elif int(first) + int(second) == int(right):
            print i
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        string = raw_input()
    except EOFError:
        break
    for i in range(10):
        translated = string.replace("X",str(i))
        left,right = translated.split("=")
        first,second = left.split("+")
        if i == 0 and any((first[0]=="0",second[0]=="0",right[0]=="0")):
            continue
        elif int(first) + int(second) == int(right):
            print i
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      ikedalab
#
# Created:     26/10/2015
# Copyright:   (c) ikedalab 2015
# Licence:     <your licence>
#-------------------------------------------------------------------------------

while 1:
    try:
        line = raw_input()
        fir = line.split('+')[0]
        secthr = line.split('+')[1]
        sec = secthr.split('=')[0]
        thr = secthr.split('=')[1]
        #print fir, sec, thr

        for x in range(10):
            n1 = fir
            n1 = n1.replace("X",str(x))
            n1 = int(n1)
            n2 = sec
            n2 = n2.replace("X",str(x))
            n2 = int(n2)
            n3 = thr
            n3 = n3.replace("X",str(x))
            n3 = int(n3)
            #print n1,n2,n3
            if(n1+n2==n3):
                print x
                break
        else:
            print "NA"






    except(EOFError):
        break;

Submission status: Wrong Answer

Solution code:
while 1:
    try:
        line = raw_input()
        fir = line.split('+')[0]
        secthr = line.split('+')[1]
        sec = secthr.split('=')[0]
        thr = secthr.split('=')[1]
        #print fir, sec, thr
        for x in range(10):
            n1 = fir
            n1 = n1.replace("X",str(x))
            n1 = int(n1)
            n2 = sec
            n2 = n2.replace("X",str(x))
            n2 = int(n2)
            n3 = thr
            n3 = n3.replace("X",str(x))
            n3 = int(n3)
            #print n1,n2,n3
            if(n1+n2==n3):
                print x
                break
        else:
            print "NA"
    except(EOFError):
        break;

Submission status: Wrong Answer

Solution code:
def doc_string():
	"""
	I can fly.
	"""
while True:
	try:
		code = raw_input()
	except EOFError:
		break
	
	for i in xrange(10):
		encode = code.replace("X", str(i))
		encode = encode.split("=")
		sing = map(int,encode[0].split("+"))
		flag = int(encode[1])
		if sing[0] + sing[1] == flag:
			print i
			break
		elif i == 9:
			print "NA"

Submission status: Wrong Answer

Solution code:
while True:
	try:
		code = raw_input()
	except EOFError:
		break
	
	a,b = map(str,code.split("+"))
	b,c = map(str,b.split("="))
	num = [a,b,c]
	
	judge = True
	for i in xrange(10):
		if int(num[0].replace("X", str(i))) + int(num[1].replace("X", str(i))) == int(num[2].replace("X", str(i))):
			judge = False
			print i
			
	if judge:
		print "NA"

Submission status: Wrong Answer

Solution code:
while True:
	try:
		code = raw_input()
	except EOFError:
		break
	
	a,b = map(str,code.split("+"))
	b,c = map(str,b.split("="))
	num = [a,b,c]
	
	judge = True
	for i in xrange(10):
		if (num[0][:1] == "X" or num[1][:1] == "X" or num[2][:1] == "X") and i == 0:
			continue
		if int(num[0].replace("X", str(i))) + int(num[1].replace("X", str(i))) == int(num[2].replace("X", str(i))):
			judge = False
			print i
			
	if judge:
		print "NA"

Submission status: Wrong Answer

Solution code:
while True:
  try:
    l = input().rstrip()
    [a,b] = l.split("+")
    [c,d] = b.split("=")
    for i in range(10):
      A = int(a.replace("X",str(i)))
      C = int(c.replace("X",str(i)))
      D = int(d.replace("X",str(i)))
      if A+C == D:
        print(i)
        break
    else:
      print('NA')
  except:
    break

Submission status: Wrong Answer

Solution code:
while True:
  try:
    l = input().rstrip()
    [a,b] = l.split("+")
    [c,d] = b.split("=")
    for i in range(10):
      if i == 0:
        if a[0] == "X" or c[0] == "X" or d[0] == "X":
          continue
      A = int(a.replace("X",str(i)))
      C = int(c.replace("X",str(i)))
      D = int(d.replace("X",str(i)))
      if A+C == D:
        print(i)
        break
    else:
      print('NA')
  except:
    break

Submission status: Wrong Answer

Solution code:
while True:
  try:
    l = input().rstrip()
    [a,b] = l.split("+")
    [c,d] = b.split("=")
    for i in range(10):
      if (i == 0) and (a[0] == "X" or c[0] == "X" or d[0] == "X"):
        pass
      else:
        A = int(a.replace("X",str(i)))
        C = int(c.replace("X",str(i)))
        D = int(d.replace("X",str(i)))
        if A+C == D:
          print(i)
          break
    else:
      print('NA')
  except:
    break

Submission status: Wrong Answer

Solution code:
import sys

for s in sys.stdin:
    p=s.split("=")

    ans="NA"

    st=0
    tmp=p[0].split("+")
    if tmp[0][0]=="X" or tmp[1][0]=="X" or p[1][0]=="X":
        st=1

    for i in range(st,10):
        a=eval(p[0].replace("X",str(i)))
        b=eval(p[1].replace("X",str(i)))
        if a==b:
            ans=i
            break

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

for s in sys.stdin:
    p=s.split("=")

    ans="NA"
    st=0

    tmp=p[0].split("+")
    if tmp[0][0]=="X" and len(tmp[0])>1:
        st=1
    if tmp[1][0]=="X" and len(tmp[1])>1:
        st=1
    if p[1][0]=="X" and len(p[1])>1:
        st=1

    for i in range(st,10):
        a=eval(p[0].replace("X",str(i)))
        b=eval(p[1].replace("X",str(i)))
        if a==b:
            ans=i
            break

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

for s in sys.stdin:
    #?????????????????????
    s=s[:-1]
    #????????¨??????????????????
    p=s.split("=")

    ans="NA"
    st=0

    #X??¨??????0????¨±?????????????????????
    #2?????\?????§?????????X???????????¨????????????
    tmp=p[0].split("+")
    if tmp[0][0]=="X" and len(tmp[0])>1:
        st=1
    if tmp[1][0]=="X" and len(tmp[1])>1:
        st=1
    if p[1][0]=="X" and len(p[1])>1:
        st=1

    print(p)
    for i in range(st,10):
        a=eval(p[0].replace("X",str(i)))
        b=eval(p[1].replace("X",str(i)))
        if a==b:
            ans=i
            break

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin.readlines()

for s in data:
	for i in range(10):
		tmp = s.replace('X',str(i))
		tmp = tmp.replace('+','=')
		list = tmp.split('=')
		if int(list[0])+int(list[1])==int(list[2]) :
			print i
			break
		if i==9 :
			print "NA"

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin.readlines()

def func (list):
	for i in list:
		if len(i)>=2 and i[0]=='0': return 1
	return 0

for s in data:
	for i in range(10):
		tmp = s.replace('X',str(i))
		tmp = tmp.replace('+','=')
		list = tmp.split('=')
		if not func(list) :
			if int(list[0])+int(list[1])==int(list[2]) :
				print i
				break
			if i==9 :
				print "NA"

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin.readlines()

def func (list):
	for i in list:
		if len(i)>=2 and i[0]=='0': return 1
	return 0

for s in data:
	for i in range(10):
		tmp = s.replace('X',str(i))
		tmp = tmp.replace('+','=')
		list = tmp.split('=')
		if func(list)==0 :
			if int(list[0])+int(list[1])==int(list[2]) :
				print i
				break
		if i==9 :
			print "NA"

Submission status: Wrong Answer

Solution code:
import sys
import re
def line():return sys.stdin.readline().strip()

while True:
    try:
        e = re.findall(r"[0-9X]+",line())

        ans = -1
        for i in range(10):
            a,b,c = [int(_.replace("X",str(i))) for _ in e]
            if a + b == c :
                ans = i
                break

        if ans == -1:
            print("NA")
        else:
            print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
import sys
import re
def line():return sys.stdin.readline().strip()

while True:
    try:
        e = re.findall(r"[0-9X]+",line())

        ans = -1
        for i in range(10):
            a,b,c = [_.replace("X",str(i)) for _ in e]
            if i == 0 and (a[0] == "0" or b[0] == "0" or c[0] == "0"):
                continue 
            if int(a) + int(b) == int(c) :
                ans = i
                break

        if ans == -1:
            print("NA")
        else:
            print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
import sys
import re
for line in sys.stdin:
	line=re.split('[+=]',line)
	flag=True
	for i in range(10):
		if(line[0][0]=='X'or line[1][0]=='X'or line[2][0]=='X')and i==0:continue
		cnt=0
		for j in range(2):
			s=line[j]
			s=s.replace('X',str(i))
			cnt+=int(s)
		s=line[2]
		s=s.replace('X',str(i))
		if cnt==int(s):
			flag=False
			print(i)
			break
	if flag:print("NA")

Submission status: Wrong Answer

Solution code:
import sys
import re
for line in sys.stdin:
	s=re.split('[+=]',line)
	line=line.replace('=','==')
	ans="NA"
	f=any([x[0]=='X' for x in s])
	for i in '0123456789'[f:]:
		if eval(line.replace('X',i)):ans=i
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
for line in sys.stdin:
	line=line.replace('\n','')
	s=re.split('[+=]',line)
	line=line.replace('=','==')
	ans="NA"
	f=any([x[0]=='X' for x in s])
	for i in '0123456789'[f:]:
		if eval(line.replace('X',i)):
			ans=i
			break
	print(ans)

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  for x in range(0,10):
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  for x in range(0,10):
    if a.find(str(x))>-1:
      next
    elif b.find(str(x))>-1:
      next
    elif c.find(str(x))>-1:
      next
    else:
      A=a.replace("X",str(x))
      B=b.replace("X",str(x))
      C=c.replace("X",str(x))
      if int(A)+int(B)==int(C):
        print(x)
        break
      if x == 9:
        print("NA")

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  for x in range(0,11):
    if x == 10:
      print("NA")
    if a.find(str(x))!=-1:
      next
    elif b.find(str(x))!=-1:
      next
    elif c.find(str(x))!=-1:
      next
    else:
      A=a.replace("X",str(x))
      B=b.replace("X",str(x))
      C=c.replace("X",str(x))
      if int(A)+int(B)==int(C):
        print(x)
        break

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  # a+b=c
  for x in range(0,10):
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  # a+b=c
  for x in range(0,10):
    if x==0 and (a[0]=="X" or b[0]=="X" or c[0]=="X"):
        next
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  # a+b=c
  for x in range(0,10):
    if x==0:
      if a[0]=="X" or b[0]=="X" or c[0]=="X":
        if len(a)==1 or len(b)==1 or len(c)==1:
          next
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  # a+b=c
  for x in range(0,10):
    if x==0:
      if (a[0]=="X" and len(a)==1)or(b[0]=="X" and len(b)==1)or(c[0]=="X" and len(c)==1):
          next
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")

Submission status: Wrong Answer

Solution code:
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  # a+b=c
  print(a,b,c)
  for x in range(0,10):
    if x==0:
      if (a[0]=="X" and len(a)>1)or(b[0]=="X" and len(b)>1)or(c[0]=="X" and len(c)>1):
          continue
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")