a=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
b=["1","0","x","9","8","7","6","5","4","3","2"]
t=0
if len(s)==18:
for i in range(0,len(s)-1):
t=t+int(s[i])*a[i]
t=t%11
if b[t].lower()==s[17].lower():
print("合法")
else:
print("不合法")
else:
print("不合法")
a=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
b=["1","0","x","9","8","7","6","5","4","3","2"]
t=0
if len(s)==18:
for i in range(0,len(s)-1):
t=t+int(s[i])*a[i]
t=t%11
if b[t].lower()==s[17].lower():
print("合法")
else:
print("不合法")
else:
print("不合法")