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:
        a = "NA"
        siki = input()
        for i in range(1,10):
            su = 0
            N_siki = list(siki.replace('X',str(i)))
            num = ""
            for l in range(N_siki.index("+")):
                num = num + N_siki[l]
            su = int(num)
            num = ""
            for j in range(N_siki.index("+") + 1,N_siki.index("=")):
                num = num + N_siki[j]
            su += int(num)
            num = ""
            for j in range(N_siki.index("=") + 1,len(N_siki)):
                num = num + N_siki[j]
            if int(num) == su:
                a = i
                break
        print(a)            
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        a = "NA"
        siki = input()
        for i in range(10):
            su = 0
            N_siki = list(siki.replace('X',str(i)))
            num = ""
            for l in range(N_siki.index("+")):
                num = num + N_siki[l]
            su = int(num)
            num = ""
            for j in range(N_siki.index("+") + 1,N_siki.index("=")):
                num = num + N_siki[j]
            su += int(num)
            num = ""
            for j in range(N_siki.index("=") + 1,len(N_siki)):
                num = num + N_siki[j]
            if int(num) == su:
                a = i
                break
        print(a)            
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import re
while 1:
    try:f=input()
    except:break
    s=any([x[0]=='X' for x in re.split('[+=]',f)])
    f=f.replace('=','==')
    for i in '0123456789'[s:]:
        if eval(f.replace('X',i)):print(i);break
    else:print('NA')

Submission status: Wrong Answer

Solution code:
import copy
try:
	while True:
		A = [[]]
		L = input()
		i = 0
		flag = 0
		for a in L:
			if a != "+" and a != "=":
				A[i].append(a)
			else:
				i = i + 1
				A.append([])
		for a in A:
			if "X" in a and len(A) == 1:
				flag = 1
		for i in range(10):
			B = copy.deepcopy(A)
			for Bi,b in enumerate(B):
				for bi,k in enumerate(b):
					if k == "X":
						B[Bi][bi] = str(i)
				B[Bi] = int("".join(B[Bi]))
			if B[0] + B[1] == B[2]:
				if i == 0 and flag == 1:
					print("NA")
					flag = 2
				else:
					print(i)
					flag = 2
		if flag == 1 or flag == 0:
			print("NA")
except EOFError:
	pass

Submission status: Wrong Answer

Solution code:
import copy
try:
	while True:
		A = [[]]
		L = input()
		i = 0
		flag = 0
		for a in L:
			if a != "+" and a != "=":
				A[i].append(a)
			else:
				i = i + 1
				A.append([])
		for a in A:
			if "X" in a and len(a) == 1:
				flag = 1
		for i in range(10):
			B = copy.deepcopy(A)
			for Bi,b in enumerate(B):
				for bi,k in enumerate(b):
					if k == "X":
						B[Bi][bi] = str(i)
				B[Bi] = int("".join(B[Bi]))
			if B[0] + B[1] == B[2]:
				if i == 0 and flag == 1:
					print("NA")
					flag = 2
				else:
					print(i)
					flag = 2
		if flag == 1 or flag == 0:
			print("NA")
except EOFError:
	pass

Submission status: Wrong Answer

Solution code:
while True:
    try:
        dataset = input()
    except:
        break
    flag = True
    for i in range(10):
        l, r = dataset.replace("X", str(i)).split("=")
        l = map(int, l.split("+"))
        if sum(l) == int(r):
            print(i)
            flag = False
            break
    if flag:
        print("NA")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    equation = s.strip()
    equation = equation.replace('=', '==')
    found = False

    for i in range(10):
        candidate = equation.replace('X', str(i))
        #print(candidate)

        # zero check
        if candidate[0] == '0' or candidate.find('+0') != -1 or candidate.find('=0') != -1:
            pass
        else:
            if eval(candidate):
                print(i)
                found = True
    if not found:
        print('NA')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0110
"""
# runtime error
import sys
import re

def solve(exp):
    p1 = re.compile('^0+')
    for i in range(10):
        modified_exp = exp.replace('X', str(i))
        left, right = modified_exp.split('=')
        left1, left2 = left.split('+')

        left1 = p1.sub('', left1)
        if left1 == '':
            left1 = '0'
        left2 = p1.sub('', left2)
        if left2 == '':
            left2 = '0'
        right = p1.sub('', right)
        if right == '':
            right = '0'

        print('{} + {} <=> {}'.format(left1, left2, right))
        if int(left1)+int(left2) == int(right):
            return i
    return 'NA'


def main(args):
    for line in sys.stdin:
        result = solve(line.strip())
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0110
"""
# runtime error
import sys
import re

def solve(exp):
    p1 = re.compile('^0+')
    for i in range(10):
        modified_exp = exp.replace('X', str(i))
        left, right = modified_exp.split('=')
        left1, left2 = left.split('+')

        left1 = p1.sub('', left1)
        if left1 == '':
            left1 = '0'
        left2 = p1.sub('', left2)
        if left2 == '':
            left2 = '0'
        right = p1.sub('', right)
        if right == '':
            right = '0'

        # print('{} + {} <=> {}'.format(left1, left2, right))
        if int(left1)+int(left2) == int(right):
            return i
    return 'NA'


def main(args):
    for line in sys.stdin:
        result = solve(line.strip())
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# Aizu Problem 0110: Alphametic

#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def alphametic(string):
    left, right = string.split('=')
    s1, s2 = left.split('+')
    if 'X' in [s1[0], s2[0], right[0]]:
        possible = list(range(1, 10))
    else:
        possible = list(range(10))
    for X in possible:
        x = str(X)
        i_right = int(right.replace('X', x))
        i_left = int(eval(left.replace('X', x)))
        if i_right == i_left:
            return X
    return "NA"

        
for line in sys.stdin:
    print(alphametic(line))

Submission status: Wrong Answer

Solution code:
import re
import sys

s = sys.stdin.readline()
while s:
    for i in range(10):
        tmp = s.replace("X",str(i))
        a,b,c = map(int,re.split("[+=]",tmp))
        if a+b-c == 0:
            print(i)
            break
    else:
        print("NA")
    s = sys.stdin.readline()

Submission status: Wrong Answer

Solution code:
while True:
    try:
        line = input()
    except:
        break
    flag = True
    for i in "0123456789":
        repline = line.replace("X", str(i))
        l, r = repline.split("=")
        a, b = l.split("+")
        if int(a) + int(b) == int(r):
            print(i)
            flag = False
            break
    if flag == True:
        print("NA")

Submission status: Wrong Answer

Solution code:
while True:
    try:
        line = input()
    except:
        break
    flag = True
    for i in "0123456789":
        l, r = line.split("=")
        a, b = l.split("+")
        if i == "0" and (a[0] == "X" or b[0] == "X" or r[0] == "X"):
            continue
        if int(a.replace("X", str(i))) + int(b.replace("X", str(i))) == int(r.replace("X", str(i))):
            print(i)
            flag = False
            break
    if flag == True:
        print("NA")

Submission status: Wrong Answer

Solution code:
while True:
    try:
        line = input()
    except:
        break
    flag = True
    l, r = line.split("=")
    a, b = l.split("+")
    for i in "0123456789":
        if i == 0:
            if a[0] == "X" and len(a) > 1:
                continue
            if b[0] == "X" and len(b) > 1:
                continue
            if r[0] == "X" and len(r) > 1:
                continue
        if int(a.replace("X", str(i))) + int(b.replace("X", str(i))) == int(r.replace("X", str(i))):
            print(i)
            flag = False
            break
    if flag == True:
        print("NA")

Submission status: Wrong Answer

Solution code:
while True:
    try:
        line = input()
    except:
        break
    flag = True
    l, r = line.split("=")
    a, b = l.split("+")
    for i in "0123456789":
        if i == "0":
            if a[0] == "X" and len(a) > 1:
                continue
            if b[0] == "X" and len(b) > 1:
                continue
            if r[0] == "X" and len(r) > 1:
                continue
        print([a.replace("X", str(i)), b.replace("X", str(i)), r.replace("X", str(i))])
        if int(a.replace("X", str(i))) + int(b.replace("X", str(i))) == int(r.replace("X", str(i))):
            print(i)
            flag = False
            break
    if flag == True:
        print("NA")

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'123456789':
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789':
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789':
  if e[0]+i==0:continue
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789':
  if'X'==e[0] and i=='0':continue
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'9876543210':
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789'[e[0]=='X'or'+X'in e or'=X'in e:]:
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  print(a,b,r)
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789'[e[0]=='X'or'+X'in e or'=X'in e:]:
  l,r=e.replace('X',i).split('=')
  a,b=map(int,l.split('+'))
  if a+b==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[e[0]==t or('+X'not in e and'+X'in e )or(e[-1]==t and'=X'in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[e[0]==t or('+X='not in e and'+X'in e )or(e[-1]==t and'=X'in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t and'+'==e[1]) or('+X='not in e and'+X'in e )or(e[-1]==t and'=X'in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*('+'!=e[1])or('+X'in e)*('+X='not in e)or('=X'in e)*(e[-2]!='='):]:
  if eval(e.replace(t,i).replace('=','==')):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e):]:
  if eval(e.replace(t,i).replace('=','==')):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e)*(e[-2]!='='):]:
  if eval(e.replace(t,i).replace('=','==')):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e)*(e[-2]!='='):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or(1 and'=X'in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import re,sys
for e in sys.stdin:
 for i in'0123456789'[any([len(x)>1 and x[0]=='X' for x in re.split('[+=]',e)]):]:
  if eval(e.replace('X',i).replace('=','==')):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys,re
for e in sys.stdin:
    s=any([len(x)>1 and x[0]=='X' for x in re.split('[+=]',e)])
    for i in '0123456789'[s:]:
        if eval(e.replace('X',i).replace('=','==')):print(i);break
    else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789'[(e[0]=='X')*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e):]:
  l,r=e.replace('X',i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789'[(e[0]=='X')*(e[1]!='+')or('+X'in e):]:
  l,r=e.replace('X',i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789'[(e[0]=='X')or('+X'in e)*('+X='not in e):]:
  l,r=e.replace('X',i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
for e in sys.stdin:
 for i in'0123456789'[(e[0]=='X')*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e):]:
  l,r=e.replace('X',i).split('=')
  if eval(l)==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
import sys
p,t='+X=','X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or(p[1:]in e)*(p not in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')

Submission status: Wrong Answer

Solution code:
def restore(sec, x):
  return int(sec.replace("X", str(x)))

while True:
  try:
    s = input()
    p_ind = s.index("+")
    e_ind = s.index("=")
    sec1 = s[:p_ind]
    sec2 = s[p_ind + 1:e_ind]
    sec3 = s[e_ind + 1:]

    for x in range(10):
      if restore(sec1, x) + restore(sec2, x) == restore(sec3, x):
        print(x)
        break
    else:
      print("NA")

  except EOFError:
    break

Submission status: Wrong Answer

Solution code:
def restore(sec, x):
  return int(sec.replace("X", str(x)))

while True:
  try:
    s = input()
    p_ind = s.index("+")
    e_ind = s.index("=")
    sec1 = s[:p_ind]
    sec2 = s[p_ind + 1:e_ind]
    sec3 = s[e_ind + 1:]

    print(sec1, sec2, sec3)
    for x in range(10):
      if not (not x and sec1[0] == "X" or sec2[0] == "X" or sec3[0] == "X"):
        if restore(sec1, x) + restore(sec2, x) == restore(sec3, x):
          print(x)
          break
    else:
      print("NA")

  except EOFError:
    break

Submission status: Wrong Answer

Solution code:
def restore(sec, x):
  return int(sec.replace("X", str(x)))

while True:
  try:
    s = input()
    p_ind = s.index("+")
    e_ind = s.index("=")
    sec1 = s[:p_ind]
    sec2 = s[p_ind + 1:e_ind]
    sec3 = s[e_ind + 1:]

    for x in range(10):
      if not (not x and (sec1[0] == "X" or sec2[0] == "X" or sec3[0] == "X")):
        if restore(sec1, x) + restore(sec2, x) == restore(sec3, x):
          print(x)
          break
    else:
      print("NA")

  except EOFError:
    break

Submission status: Wrong Answer

Solution code:
def restore(sec, x):
  return int(sec.replace("X", str(x)))

while True:
  try:
    s = input()
    p_ind = s.index("+")
    e_ind = s.index("=")
    sec1 = s[:p_ind]
    sec2 = s[p_ind + 1:e_ind]
    sec3 = s[e_ind + 1:]

    for x in range(10):
      if not (not x and (sec1[0] == "X" and len(sec1) == 1 or sec2[0] == "X" and len(sec2) == 1 or sec3[0] == "X" and len(sec3) == 1)):
        if restore(sec1, x) + restore(sec2, x) == restore(sec3, x):
          print(x)
          break
    else:
      print("NA")

  except EOFError:
    break

Submission status: Wrong Answer

Solution code:
import re,sys
def chk(t):
    for i in range(1,10):
        if eval(re.sub("X",str(i),t)):
            return i
    return False

l=[chk(i.replace("=","==")) for i in sys.stdin]
[print(i) if i is not False else print("NA") for i in l]

Submission status: Wrong Answer

Solution code:
import re,sys
def chk(t):
    for i in range(1,10):
        if eval(re.sub("X",str(i),t)):
            return i
    return 10

l=[chk(i.replace("=","==")) for i in sys.stdin]
[print(i) if i != 10 else print("NA") for i in l]

Submission status: Wrong Answer

Solution code:
import re,sys
def chk(t):
    for i in range(10):
        try:
            if eval(re.sub("X",str(i),t)):
                return i
        except:
            pass
    return 10

l=[chk(i.replace("=","==")) for i in sys.stdin]
[print(i) if i != 10 else print("NA") for i in l]

Submission status: Wrong Answer

Solution code:
import re,sys
def chk(t):
    for i in range(10):
        el=re.sub("X",str(i),t)
        e=list(map(int,re.split("[+=]",el)))
        if eval(str(e[0])+"+"+str(e[1])+"=="+str(e[2])):
            return i
    return 10

l=[chk(i.strip()) for i in sys.stdin]
[print(i) if i != 10 else print("NA") for i in l]

Submission status: Wrong Answer

Solution code:
import re,sys
def chk(t):
    for i in range(10):
        el=re.sub("X",str(i),t)
        e=list(map(int,re.split("[+=]",el)))
        if eval(str(e[0])+"+"+str(e[1])) == eval(str(e[2])):
            return i
    return 10

l=[chk(i.strip()) for i in sys.stdin]
[print(i) if i != 10 else print("NA") for i in l]

Submission status: Wrong Answer

Solution code:
# AOJ 0110 Alphametic
# Python3 2018.6.21 bal4u

while 1:
	try:
		ab, s = list(input().split('='))
		a, b = list(ab.split('+'))
		start = 0
		if (len(a) > 0 and a[0] == '0') or (len(b) > 0 and b[0] == '0') \
			or (len(s) > 0 and s[0] == '0'): start = 1
		f = 1
		for x in range(start, 10):
			na = a.replace('X', str(x))
			nb = b.replace('X', str(x))
			ns = s.replace('X', str(x))
			if int(na) + int(nb) == int(ns):
				print(x)
				f = 0
				break
		if f: print("NA")
	except: break

Submission status: Wrong Answer

Solution code:
# AOJ 0110 Alphametic
# Python3 2018.6.21 bal4u

while 1:
	try:
		ab, s = list(input().split('='))
		a, b = list(ab.split('+'))
		start = 0
		if (len(a) > 0 and a[0] == 'X') or (len(b) > 0 and b[0] == 'X') \
			or (len(s) > 0 and s[0] == 'X'): start = 1
		f = 1
		for x in range(start, 10):
			na = a.replace('X', str(x))
			nb = b.replace('X', str(x))
			ns = s.replace('X', str(x))
			if int(na) + int(nb) == int(ns):
				print(x)
				f = 0
				break
		if f: print("NA")
	except: break

Submission status: Wrong Answer

Solution code:
def check(temp):
    try:
        if temp[0] == 'X':
            raise FormatError('Start 0')
    except FormatError:
        return False

    plus = temp.index('+')
    equal = temp.index('=')
    a = int(temp[:plus])
    b = int(temp[plus + 1:equal])
    c = int(temp[equal + 1:])

    if a + b == c:
        return True
    else:
        return False

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    ans = 0
    for num in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
        temp = line.replace('X', num)
        if check(temp):
            ans = int(num)

    if ans > 0:
        print ans
    else:
        print 'NA'

Submission status: Wrong Answer

Solution code:
def check(temp):
    if temp[0] == '0' and len(temp) > 1:
        return False

    plus = temp.index('+')
    equal = temp.index('=')
    a = int(temp[:plus])
    b = int(temp[plus + 1:equal])
    c = int(temp[equal + 1:])

    if a + b == c:
        return True
    else:
        return False

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    if line.index('X') < 0:
        continue
    ans = 0
    for num in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
        temp = line.replace('X', num)
        if check(temp):
            ans = int(num)

    if ans > 0:
        print ans
    else:
        print 'NA'

Submission status: Wrong Answer

Solution code:
def form_check(t):
    plus = t.index('+')
    equal = t.index('=')
    if len(t[:plus]) > 1 or len(t[plus + 1:equal]) > 1 or len(t[equal + 1:]) > 1:
        return False
    return True

def check(t):
    equal = t.index('=')
    if eval(t[:equal]) == eval(t[equal + 1:]):
        return True
    else:
        return False

while True:
    try:
        line = raw_input()
    except EOFError:
        break

    if form_check(line):
        nums = range(0, 10)
    else:
        nums = range(1, 10)
    a = -1
    for num in nums:
        if check(line.replace('X', str(num))):
            a = num
    if a >= 0:
        print a
    else:
        print 'NA'

Submission status: Wrong Answer

Solution code:
while True:
    try:
        NA = True
        formula = raw_input()
        plus = formula.find('+')
        equal = formula.find('=')
        term1, term2, term3 = formula[:plus], formula[plus+1:equal], formula[equal+1:]
        for i in range(10):
            if int(term1.replace('X', str(i))) + int(term2.replace('X', str(i))) == int(term3.replace('X', str(i))):
                NA = False
                print i
                break
        if NA: print "NA"
    except (EOFError):
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        NA = True
        formula = raw_input()
        plus = formula.find('+')
        equal = formula.find('=')
        term1, term2, term3 = formula[:plus], formula[plus+1:equal], formula[equal+1:]
        for i in range(10):
            if (i == 0 and (term1[0] == 'X' or term2[0] == 'X' or term3[0] == 'X')):
                    continue
            if int(term1.replace('X', str(i))) + int(term2.replace('X', str(i))) == int(term3.replace('X', str(i))):
                NA = False
                print i
                break
        if NA: print "NA"
    except (EOFError):
        break

Submission status: Wrong Answer

Solution code:
import sys
for line in sys.stdin.readlines():
    a="NA"
    for i in xrange(10):
        exp,ans=line.strip().replace("X",str(i)).split("=")
        if reduce(lambda x,y:int(x)+int(y),exp.split("+"))==int(ans):
            a=i
    print a

Submission status: Wrong Answer

Solution code:
import re
while 1:
    try:
        ss = re.split('[+=]', raw_input())
        for i in range(10):
            ns = [int(s.replace('X', str(i))) for s in ss]
            if ns[0] + ns[1] == ns[2]:
                print i
                break
        else:
            print 'NA'
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import re
while 1:
    try:
        ss = re.split('[+=]', raw_input())
        for i in range(10):
            ns = [long(s.replace('X', str(i))) for s in ss]
            if ns[0] + ns[1] == ns[2]:
                print i
                break
        else:
            print 'NA'
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import re
while 1:
    try:
        ss = re.split('[+=]', raw_input())
        if len(ss) != 3: break
        for i in range(10):
            ns = [long(s.replace('X', str(i))) for s in ss]
            if ns[0] + ns[1] == ns[2]:
                print i
                break
        else:
            print 'NA'
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        s=raw_input()
    except EOFError:
        break
    flag=False
    a1=s.split("+")[0]
    a2,a3=s.split("+")[1].split("=")
    for i in range(10):
        t1,t2,t3=a1,a2,a3
        t1=int(t1.replace("X",str(i)))
        t2=int(t2.replace("X",str(i)))
        t3=int(t3.replace("X",str(i)))
        if t1+t2==t3:
            print i
            flag=True
            break
    if flag==False:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        s=raw_input()
    except EOFError:
        break
    flag=False
    a1=s.split("+")[0]
    a2,a3=s.split("+")[1].split("=")
    for i in range(10):
        t1,t2,t3=a1,a2,a3
        if (t1[0]=="X" or t2[0]=="X" or t3[0]=="X") and i==0:
            continue
        t1=int(t1.replace("X",str(i)))
        t2=int(t2.replace("X",str(i)))
        t3=int(t3.replace("X",str(i)))
        if t1+t2==t3:
            print i
            flag=True
            break
    if flag==False:
        print "NA"

Submission status: Wrong Answer

Solution code:


import sys


def solv(s):
    left, right = s.split('=')
    for i in range(10):
        i = str(i)
        l = left.replace('X', i)
        r = right.replace('X', i)
        l1, l2 = l.split('+')
        if l1[0] == '0' or l2[0] == '0' or r[0] == '0':
            continue
        if eval(l) == int(r):
            return i
    else:
        return 'NA'


for line in sys.stdin:
    print solv(line.rstrip('\n'))

Submission status: Wrong Answer

Solution code:

import sys


def solv(s):
    left, right = s.split('=')
    for i in range(10):
        i = str(i)
        l = left.replace('X', i)
        r = right.replace('X', i)
        l1, l2 = l.split('+')
        if i == '0' and (l1[0] == '0' or l2[0] == '0' or r[0] == '0'):
            continue
        if eval(l) == int(r):
            return i
    else:
        return 'NA'


for line in sys.stdin:
    print solv(line.rstrip('\n'))

Submission status: Wrong Answer

Solution code:

import sys


def solv(s):
    left, right = s.split('=')
    for i in range(10):
        i = str(i)
        l = left.replace('X', i)
        r = right.replace('X', i)
        l1, l2 = l.split('+')
        if i == '0' and (l1[0] == '0' or l2[0] == '0' or r[0] == '0'):
            continue
        if int(l1) + int(l2) == int(r):
            return i
    else:
        return 'NA'


for line in sys.stdin:
    print solv(line.rstrip('\n'))

Submission status: Wrong Answer

Solution code:

import sys


def solv(s):
    for i in range(10):
        i = str(i)
        s2 = s.replace('X', i)
        left, right = s2.split('=')
        l1, l2 = left.split('+')
        if i == '0' and (l1[0] == '0' or l2[0] == '0' or right[0] == '0'):
            continue
        if int(l1) + int(l2) == int(right):
            return i
    else:
        return 'NA'


for line in sys.stdin:
    print solv(line.rstrip('\n'))

Submission status: Wrong Answer

Solution code:

import sys


def solv(s):
    for i in range(10):
        i = str(i)
        s2 = s.replace('X', i)
        left, right = s2.split('=')
        l1, l2 = left.split('+')
        print l1, l2, right
        if l1[0] == '0' or l2[0] == '0' or right[0] == '0':
            continue
        if int(l1) + int(l2) == int(right):
            return i
    else:
        return 'NA'


for line in sys.stdin:
    print solv(line.rstrip('\n'))

Submission status: Wrong Answer

Solution code:

import sys


def solv(s):
    for i in range(10):
        i = str(i)
        s2 = s.replace('X', i)
        left, right = s2.split('=')
        l1, l2 = left.split('+')
        if any([x[0] == '0' for x in [l1, l2, right]]):
            continue
        if int(l1) + int(l2) == int(right):
            return i
    else:
        return 'NA'


for line in sys.stdin:
    print solv(line.rstrip('\n'))

Submission status: Wrong Answer

Solution code:
import sys
def to_ints(a,b,c,n):
    d=list(a)
    e=list(b)
    f=list(c)
    for i in range(len(d)):
        if d[i]=='X': d[i]=n
    for i in range(len(e)):
        if e[i]=='X': e[i]=n
    for i in range(len(f)):
        if f[i]=='X': f[i]=n
    return map(int,("".join(d),"".join(e),"".join(f)))

for e in sys.stdin.readlines():
    e=e.rstrip()
    i=e.index('+')
    j=e.index('=')
    a=e[:i]
    b=e[i+1:j]
    c=e[j+1:]
    s = 0
    if len(a)>1 or len(b)>1 or len(c)>1:
        s=1 if a[0]=='X' or b[0]=='X' or c[0]=='X' else 0
    ans=0
    for n in range(s,10):
        x,y,z=to_ints(a,b,c,str(n))
        print x,y,z
        if x+y==z: ans=n
    print ans if ans!=0 else 'NA'

Submission status: Wrong Answer

Solution code:
import sys
def to_ints(a,b,c,n):
    d=list(a)
    e=list(b)
    f=list(c)
    for i in range(len(d)):
        if d[i]=='X': d[i]=n
    for i in range(len(e)):
        if e[i]=='X': e[i]=n
    for i in range(len(f)):
        if f[i]=='X': f[i]=n
    return map(int,("".join(d),"".join(e),"".join(f)))

for e in sys.stdin.readlines():
    e=e.rstrip()
    i=e.index('+')
    j=e.index('=')
    a=e[:i]
    b=e[i+1:j]
    c=e[j+1:]
    s = 0
    if len(a)>1 or len(b)>1 or len(c)>1:
        s=1 if a[0]=='X' or b[0]=='X' or c[0]=='X' else 0
    ans=0
    for n in range(s,10):
        x,y,z=to_ints(a,b,c,str(n))
        if x+y==z: ans=n
    print ans if ans!=0 else 'NA'

Submission status: Wrong Answer

Solution code:
f=lambda x,y: int(x.replace("X",str(y)))
while True:
	try:
		ex = raw_input()
		a,b,c = ex[0:ex.index("+")],ex[ex.index("+")+1:ex.index("=")],ex[ex.index("=")+1:]
		for i in range(10):
			ans = i if f(a,i) + f(b,i) == f(c,i) else -1
			if ans!=-1:
				print ans
				break
		else:
			print "NA"
	except EOFError:
		break