AtCoder Beginner Contest 126 - YYMM or MMYY

You have a digit sequence S of length 4. You are wondering which of the following formats S is in:
 - YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order
 - MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order
If S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.

-----Constraints-----
 - S is a digit sequence of length 4.

-----Input-----
Input is given from Standard Input in the following format:
S

-----Output-----
Print the specified string: YYMM, MMYY, AMBIGUOUS or NA.

-----Sample Input-----
1905

-----Sample Output-----
YYMM

May XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.

Difficulty: EASY

Starter code:

Solutions:
S = input()
(head, tail) = (S[:2], S[2:])
if 1 <= int(head) <= 12:
	print('AMBIGUOUS' if 1 <= int(tail) <= 12 else 'MMYY')
else:
	print('YYMM' if 1 <= int(tail) <= 12 else 'NA')


a = input()
b = int(a[0] + a[1])
c = int(a[2] + a[3])
if 1 <= b <= 12:
	if 1 <= c <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= c <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
if 1 <= int(s[:2]) <= 12 and 1 <= int(s[2:]) <= 12:
	print('AMBIGUOUS')
elif 1 <= int(s[:2]) <= 12:
	print('MMYY')
elif 1 <= int(s[2:]) <= 12:
	print('YYMM')
else:
	print('NA')


S = int(input())
L = S // 100
R = S % 100
if L > 12 or L == 0:
	if R > 12 or R == 0:
		print('NA')
	else:
		print('YYMM')
elif R > 12 or R == 0:
	print('MMYY')
else:
	print('AMBIGUOUS')


S = int(input())
up = S // 100
down = S % 100
if 0 < up < 13 and 0 < down < 13:
	print('AMBIGUOUS')
elif 0 < up < 13:
	print('MMYY')
elif 0 < down < 13:
	print('YYMM')
else:
	print('NA')


S = input()
s1 = S[0:2]
s2 = S[2:4]
li = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
if s1 not in li:
	a = False
else:
	a = True
if s2 not in li:
	b = False
else:
	b = True
if a == b == True:
	print('AMBIGUOUS')
elif a == b == False:
	print('NA')
elif a == True:
	print('MMYY')
else:
	print('YYMM')


s = input()
if 12 < int(s[:2]) or 0 == int(s[:2]):
	if 12 >= int(s[2:]) >= 1:
		print('YYMM')
	else:
		print('NA')
elif 1 <= int(s[:2]) <= 12:
	if 12 >= int(s[2:]) >= 1:
		print('AMBIGUOUS')
	else:
		print('MMYY')


S = int(input())
a = S // 100
b = S % 100
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12 and (b > 12 or b == 0):
	print('MMYY')
elif (a == 0 or a > 12) and 1 <= b <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
head = int(s[:2])
tail = int(s[2:])
is_mmyy = False
is_yymm = False
if 1 <= head <= 12:
	is_mmyy = True
if 1 <= tail <= 12:
	is_yymm = True
if is_yymm and is_mmyy:
	print('AMBIGUOUS')
elif is_yymm:
	print('YYMM')
elif is_mmyy:
	print('MMYY')
else:
	print('NA')


s = input()
(t, u) = (0 < int(s[:2]) < 13, 0 < int(s[2:]) < 13)
print('AMBIGUOUS' if t and u else 'MMYY' if t else 'YYMM' if u else 'NA')


s = input().rstrip()
a = int(s[:2])
b = int(s[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif (a == 0 or 13 <= a <= 99) and 1 <= b <= 12:
	print('YYMM')
elif 1 <= a <= 12 and (b == 0 or 13 <= b <= 99):
	print('MMYY')
else:
	print('NA')


a = input()
a_i = int(a[0:2])
b_i = int(a[2:4])
if 0 < a_i <= 12 and 0 < b_i <= 12:
	print('AMBIGUOUS')
elif 0 < b_i <= 12:
	print('YYMM')
elif 0 < a_i <= 12:
	print('MMYY')
else:
	print('NA')


S = list(input())
x = int(''.join(S[0:2]))
y = int(''.join(S[2:4]))
if 1 <= x <= 12:
	if 1 <= y <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= y <= 12:
	print('YYMM')
else:
	print('NA')
pass


S = input()
month = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
year = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09']
for i in range(10, 100):
	year.append(str(i))
if month.count(S[0:2]) == 1 and year.count(S[2:4]) == 1 and (month.count(S[2:4]) == 1) and (year.count(S[0:2]) == 1):
	print('AMBIGUOUS')
elif month.count(S[2:4]) == 1 and year.count(S[0:2]) == 1:
	print('YYMM')
elif month.count(S[0:2]) == 1 and year.count(S[2:4]) == 1:
	print('MMYY')
else:
	print('NA')


s = input()
(a, b) = (int(s[:2]), int(s[2:]))
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][(0 < a < 13) - (0 < b < 13) * 2])


s = input()
fir = int(s[:2])
sec = int(s[2:])
b = 1 <= fir <= 12
c = 1 <= sec <= 12
if b and c:
	t = 'AMBIGUOUS'
elif b:
	t = 'MMYY'
elif c:
	t = 'YYMM'
else:
	t = 'NA'
print(t)


s = int(input())
u = 1 <= s // 100 <= 12
d = 1 <= s % 100 <= 12
if u:
	if d:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif d:
	print('YYMM')
else:
	print('NA')


s = input()

def YYMM(s):
	p = int(s[2:])
	if 1 <= p <= 12:
		return True
	return False

def MMYY(s):
	p = int(s[:2])
	if 1 <= p <= 12:
		return True
	return False
if YYMM(s) and MMYY(s):
	print('AMBIGUOUS')
elif YYMM(s):
	print('YYMM')
elif MMYY(s):
	print('MMYY')
else:
	print('NA')


n = input()
(l, r) = (int(n[:2]) < 1 or int(n[:2]) > 12, int(n[2:]) < 1 or int(n[2:]) > 12)
if l and r:
	p = 'NA'
elif not (l or r):
	p = 'AMBIGUOUS'
elif l and (not r):
	p = 'YYMM'
else:
	p = 'MMYY'
print(p)


s = str(input())
a = int(s[0]) * 10 + int(s[1])
b = int(s[2]) * 10 + int(s[3])
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12:
	print('MMYY')
elif 1 <= b <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
a = int(s[:2])
b = int(s[2:])
if 0 < a < 13:
	if 0 < b < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < b < 13:
	print('YYMM')
else:
	print('NA')


s = int(input())
x = s % 100
y = s // 100
print(('AMBIGUOUS' if 0 < x < 13 else 'MMYY') if 0 < y < 13 else 'YYMM' if 0 < x < 13 else 'NA')


s = int(input())
s1 = int(s / 100)
s2 = s % 100
if 0 < s1 <= 12 and 0 < s2 <= 12:
	print('AMBIGUOUS')
elif 0 < s1 <= 12:
	print('MMYY')
elif 0 < s2 <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
print(['NA', 'YYMM', 'MMYY', 'AMBIGUOUS'][(0 < int(s[:2]) < 13) * 2 + (0 < int(s[2:]) < 13)])


S = input()
a = int(S[:2])
b = int(S[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12:
	print('MMYY')
elif 1 <= b <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
(x, y) = (int(s[:2]), int(s[2:]))
a = 1 <= x <= 12
b = 1 <= y <= 12
if a ^ b:
	print('MMYY' if a else 'YYMM')
else:
	print('AMBIGUOUS' if a else 'NA')


s = int(input())
n1 = s // 100
n2 = s % 100
if 0 < n1 <= 12 and 0 < n2 <= 12:
	print('AMBIGUOUS')
elif 0 < n2 <= 12:
	print('YYMM')
elif 0 < n1 <= 12:
	print('MMYY')
else:
	print('NA')


s = input()
ans = {(False, False): 'NA', (False, True): 'YYMM', (True, False): 'MMYY', (True, True): 'AMBIGUOUS'}
print(ans[1 <= int(s[:2]) <= 12, 1 <= int(s[2:]) <= 12])


x = int(input())
y = x // 100
m = x - y * 100
if y > 0 and y < 13:
	if m > 0 and m < 13:
		res = 'AMBIGUOUS'
	else:
		res = 'MMYY'
elif m > 0 and m < 13:
	res = 'YYMM'
else:
	res = 'NA'
print(res)


n = input()
(s, t) = (1 <= int(n[:2]) <= 12, 1 <= int(n[2:]) <= 12)
print('AMBIGUOUS' if s and t else 'YYMM' if t else 'MMYY' if s else 'NA')


S = input()
L = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
print(L[(0 < int(S[0:2]) <= 12) + 2 * (0 < int(S[2:4]) <= 12)])


S = input()
if int(S[:2]) == 0 and 0 < int(S[2:]) <= 12:
	print('YYMM')
elif int(S[2:]) == 0 and 0 < int(S[:2]) <= 12:
	print('MMYY')
elif int(S[:2]) == 0 or int(S[2:]) == 0 or (int(S[:2]) > 12 and int(S[2:]) > 12):
	print('NA')
elif int(S[:2]) > 12 and int(S[2:]) <= 12:
	print('YYMM')
elif int(S[:2]) <= 12 and int(S[2:]) > 12:
	print('MMYY')
else:
	print('AMBIGUOUS')


s = input()
(my, ym) = (0 < int(s[:2]) < 13, 0 < int(s[2:]) < 13)
if my and ym:
	print('AMBIGUOUS')
elif my:
	print('MMYY')
elif ym:
	print('YYMM')
else:
	print('NA')


s = input()
s1 = s[:2]
s2 = s[2:]
(a, b) = (0, 0)
if 1 <= int(s1) <= 12:
	a = 1
if 1 <= int(s2) <= 12:
	b = 1
print('AMBIGUOUS' if a * b == 1 else 'YYMM' if b == 1 else 'MMYY' if a == 1 else 'NA')


s = input()
c = 0
if 0 < int(s[0]) * 10 + int(s[1]) < 13:
	c += 1
if 0 < int(s[2]) * 10 + int(s[3]) < 13:
	c += 2
print('AMBIGUOUS' if c == 3 else 'YYMM' if c == 2 else 'MMYY' if c == 1 else 'NA')


s = input()
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][('01' < s < '13') - ('00' < s[2:] < '13') * 2])


s = input()
a = int(s[0]) * 10 + int(s[1])
b = int(s[2]) * 10 + int(s[3])
pp = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
c = 0
if 1 <= a <= 12:
	c += 1
if 1 <= b <= 12:
	c += 2
print(pp[c])


s = int(input())
(l, r) = (s / 100, s % 100)
if 1 <= l <= 12:
	if 1 <= r <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= r <= 12:
	print('YYMM')
else:
	print('NA')


def is_YY(S):
	N = int(S)
	if 0 <= N <= 99:
		return True
	else:
		return False

def is_MM(S):
	N = int(S)
	if 1 <= N <= 12:
		return True
	else:
		return False

def __starting_point():
	S = input()
	top = S[:2]
	bottom = S[2:]
	if is_YY(top) and is_MM(top) and is_YY(bottom) and is_MM(bottom):
		print('AMBIGUOUS')
	elif is_YY(top) and is_MM(bottom):
		print('YYMM')
	elif is_MM(top) and is_YY(bottom):
		print('MMYY')
	else:
		print('NA')
__starting_point()


a = input()
(p, q) = (int(a[:2]), int(a[2:]))
if 0 < p < 13 and 0 < q < 13:
	print('AMBIGUOUS')
elif 0 < p < 13:
	print('MMYY')
elif 0 < q < 13:
	print('YYMM')
else:
	print('NA')


s = input()
s_1 = int(s[0:2])
s_2 = int(s[2:4])
if (s_1 > 12 or s_1 < 1) and (s_2 > 12 or s_2 < 1):
	print('NA')
elif s_1 <= 12 and s_1 >= 1 and (s_2 <= 12) and (s_2 >= 1):
	print('AMBIGUOUS')
elif s_1 <= 12 and s_1 >= 1:
	print('MMYY')
else:
	print('YYMM')


s = int(input())
(pre, suf) = (0 < s // 100 <= 12, 0 < s % 100 <= 12)
print(['NA', 'YYMM', 'MMYY', 'AMBIGUOUS'][pre * 2 + suf])


s = input().strip()
a = int(s[0:2])
b = int(s[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12:
	print('MMYY')
elif 1 <= b <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
F = int(S[:2])
L = int(S[2:])
if 0 < F <= 12:
	if 0 < L <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < L <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
(a, b) = (int(s[0:2]), int(s[2:4]))
a = 0 < a < 13
b = 0 < b < 13
if a and b:
	print('AMBIGUOUS')
elif not (a or b):
	print('NA')
elif b:
	print('YYMM')
else:
	print('MMYY')


s = input()
A = int(s[:2])
B = int(s[2:])
if 0 < A < 13 and 0 < B < 13:
	print('AMBIGUOUS')
elif 0 < A < 13:
	print('MMYY')
elif 0 < B < 13:
	print('YYMM')
else:
	print('NA')


c = input()
a = int(c[:2])
b = int(c[2:])
if a in range(1, 13):
	if b in range(1, 13):
		s = 'AMBIGUOUS'
	else:
		s = 'MMYY'
elif b in range(1, 13):
	s = 'YYMM'
else:
	s = 'NA'
print(s)


S = input()
f = int(S[:2])
s = int(S[2:])
if 1 <= f <= 12:
	if 1 <= s <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= s <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
(s1, s2) = (int(s[:2]), int(s[2:]))
ans = ['NA', 'YYMM', 'MMYY', 'AMBIGUOUS']
print(ans[((1 <= s1 <= 12) << 1) + (1 <= s2 <= 12)])


import sys

def input():
	return sys.stdin.readline().strip()

def I():
	return int(input())

def LI():
	return list(map(int, input().split()))

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def S():
	return input()

def LS():
	return input().split()
INF = float('inf')

def is_yymm(f, l):
	if 1 <= l <= 12:
		return True
	return False

def is_mmyy(f, l):
	if 1 <= f <= 12:
		return True
	return False
s = S()
f = int(s[:2])
l = int(s[2:])
if is_yymm(f, l) and is_mmyy(f, l):
	print('AMBIGUOUS')
elif is_yymm(f, l) and (not is_mmyy(f, l)):
	print('YYMM')
elif not is_yymm(f, l) and is_mmyy(f, l):
	print('MMYY')
else:
	print('NA')


S = input()
first = int(S[0:2])
last = int(S[2:4])
if 0 < first < 13:
	if 0 < last < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < last < 13:
	print('YYMM')
else:
	print('NA')


s = input()
s1 = s[:2]
s2 = s[2:]
print('AMBIGUOUS' if 0 < int(s1) < 13 and 0 < int(s2) < 13 else 'MMYY' if 0 < int(s1) < 13 else 'YYMM' if 0 < int(s2) < 13 else 'NA')


s = input()
aa = int(s[0] + s[1])
bb = int(s[2] + s[3])
if aa >= 13 or aa == 0:
	print('YYMM') if 0 < bb < 13 else print('NA')
else:
	print('AMBIGUOUS') if 0 < bb < 13 else print('MMYY')


S = input()
a = int(S[0] + S[1])
b = int(S[2] + S[3])
if 0 < a < 13 and 0 < b < 13:
	print('AMBIGUOUS')
elif 0 < a < 13:
	print('MMYY')
elif 0 < b < 13:
	print('YYMM')
else:
	print('NA')


N = input()
A = int(N[:2])
B = int(N[2:])
if A >= 1 and A <= 12:
	if B >= 1 and B <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif B >= 1 and B <= 12:
	print('YYMM')
else:
	print('NA')


s = int(input())
(a, b) = (s // 100, s % 100)
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12:
	print('MMYY')
elif 1 <= b <= 12:
	print('YYMM')
else:
	print('NA')


s = int(input())
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][(9 < s < 1300) - (0 < s % 100 < 13) * 2])


import math

def isMM(num):
	if num < 13 and num > 0:
		return True
	else:
		return False

def hantei(number):
	num = math.floor(number / 100)
	ber = number % 100
	if isMM(num) is False and isMM(ber) is False:
		return 'NA'
	elif isMM(num) is True and isMM(ber) is True:
		return 'AMBIGUOUS'
	elif isMM(num) is True and isMM(ber) is False:
		return 'MMYY'
	else:
		return 'YYMM'
num = int(input())
print(hantei(num))


S = input()
(a, b) = (int(S[:2]), int(S[2:]))
ans = ['NA', 'YYMM', 'MMYY', 'AMBIGUOUS']
idx = 0
if a in range(1, 13):
	idx += 2
if b in range(1, 13):
	idx += 1
print(ans[idx])


s = input()
b = int(s[:2])
a = int(s[2:])

def yorm(i):
	flag = 'none'
	if 0 < i <= 12:
		flag = 'MM'
	elif i < 100:
		flag = 'YY'
	return flag
bf = yorm(b)
af = yorm(a)
ans = bf + af
if len(ans) != 4:
	ans = 'NA'
if ans == 'MMMM':
	ans = 'AMBIGUOUS'
if ans == 'YYYY':
	ans = 'NA'
print(ans)


s = input()
s1 = int(s[0] + s[1])
s2 = int(s[2] + s[3])
if 0 < s1 < 13 and 0 < s2 < 13:
	print('AMBIGUOUS')
elif 0 < s1 < 13:
	print('MMYY')
elif 0 < s2 < 13:
	print('YYMM')
else:
	print('NA')


print(['NA', 'YYMM', 'MMYY', 'AMBIGUOUS'][(lambda x: (0 < x // 100 < 13) * 2 + (0 < x % 100 < 13))(int(input()))])


s = int(input())
a = s // 100
b = s % 100
if 0 < a < 13 and 0 < b < 13:
	print('AMBIGUOUS')
elif 0 < a < 13:
	print('MMYY')
elif 0 < b < 13:
	print('YYMM')
else:
	print('NA')


S = input()
U = int(S[0:2])
L = int(S[2:4])
if 0 < U <= 12 and 0 < L <= 12:
	print('AMBIGUOUS')
elif 0 < U <= 12:
	print('MMYY')
elif 0 < L <= 12:
	print('YYMM')
else:
	print('NA')


s = list(input())
flag = 3
if 1 <= int(s[0]) * 10 + int(s[1]) <= 12:
	flag -= 2
if 1 <= int(s[2]) * 10 + int(s[3]) <= 12:
	flag -= 1
print(['AMBIGUOUS', 'MMYY', 'YYMM', 'NA'][flag])


S = input()
A = S[:2]
B = S[2:]
if 0 < int(A) < 13:
	if 0 < int(B) < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < int(B) < 13:
	print('YYMM')
else:
	print('NA')


S = input()
T = str(S)
A = int(T[0:2])
B = int(T[2:4])
if 1 <= A <= 12:
	if 1 <= B <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= B <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
x = int(s[:2])
y = int(s[2:])
if 1 <= x <= 12 and 1 <= y <= 12:
	a = 'AMBIGUOUS'
elif 1 <= x <= 12:
	a = 'MMYY'
elif 1 <= y <= 12:
	a = 'YYMM'
else:
	a = 'NA'
print(a)


s = str(input())
num = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
if s[:2] in num and s[2:] in num:
	print('AMBIGUOUS')
elif s[:2] in num:
	print('MMYY')
elif s[2:] in num:
	print('YYMM')
else:
	print('NA')


(a, b) = divmod(int(input()), 100)
x = 'MM' if 0 < a < 13 else 'YY'
y = 'MM' if 0 < b < 13 else 'YY'
print(x + y if x != y else 'NA' if x == 'YY' else 'AMBIGUOUS')


S = input()
ans = [0, 0]
if 1 <= int(S[:2]) and int(S[:2]) <= 12:
	ans[0] = 1
if 1 <= int(S[2:]) and int(S[2:]) <= 12:
	ans[1] = 1
if ans == [1, 1]:
	print('AMBIGUOUS')
elif ans == [0, 0]:
	print('NA')
elif ans == [0, 1]:
	print('YYMM')
elif ans == [1, 0]:
	print('MMYY')


S = input()
(l, r) = (int(S[:2]), int(S[2:]))
if 1 <= l <= 12 and 1 <= r <= 12:
	print('AMBIGUOUS')
elif 1 <= r <= 12:
	print('YYMM')
elif 1 <= l <= 12:
	print('MMYY')
else:
	print('NA')


n = int(input())
r = n // 100
l = n % 100
if r <= 12 and 1 <= r:
	if l <= 12 and 1 <= l:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif l <= 12 and 1 <= l:
	print('YYMM')
else:
	print('NA')


S = input()
l = int(S[:2])
r = int(S[2:])
a = 0
ans = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
if 0 < l and l < 13:
	a += 1
if 0 < r and r < 13:
	a += 2
print(ans[a])


S = input()
l = len(S)
Y = 0
M = 0
for i in range(l):
	if i == 3:
		if int(S[i - 1]) == 0 and 1 <= int(S[i]) <= 9:
			Y = 1
		elif int(S[i - 1]) == 1 and 0 <= int(S[i]) <= 2:
			Y = 1
for i in range(l):
	if i == 1:
		if int(S[i - 1]) == 0 and 1 <= int(S[i]) <= 9:
			M = 1
		elif int(S[i - 1]) == 1 and 0 <= int(S[i]) <= 2:
			M = 1
if Y == 1 and M == 1:
	print('AMBIGUOUS')
elif Y == 1 and M == 0:
	print('YYMM')
elif Y == 0 and M == 1:
	print('MMYY')
elif Y == 0 and M == 0:
	print('NA')


s = input()
f = 0 < int(s[:2]) < 13
s = 0 < int(s[2:]) < 13
ans = 'NA'
if f and s:
	ans = 'AMBIGUOUS'
elif s:
	ans = 'YYMM'
elif f:
	ans = 'MMYY'
print(ans)


i = input()
x = int(i[0:2])
y = int(i[2:4])

def isMM(a):
	return 1 <= a and a <= 12
r = isMM(x) * 2 + isMM(y)
print(['NA', 'YYMM', 'MMYY', 'AMBIGUOUS'][r])


from itertools import product
s = input()
y = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
yy = list((x + y for (x, y) in product(y, repeat=2)))
mm = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
ans = 'NA'
if (s[0:2] in yy and s[2:4] in mm) and (s[0:2] not in mm or s[2:4] not in yy):
	ans = 'YYMM'
elif (s[0:2] in mm and s[2:4] in yy) and (s[0:2] not in yy or s[2:4] not in mm):
	ans = 'MMYY'
elif (s[0:2] in mm and s[2:4] in yy) and (s[0:2] in yy or s[2:4] in mm):
	ans = 'AMBIGUOUS'
print(ans)


S = list(map(int, input()))
if 1 <= S[0] * 10 + S[1] <= 12 and 1 <= S[2] * 10 + S[3] <= 12:
	print('AMBIGUOUS')
elif 1 <= S[0] * 10 + S[1] <= 12 and (S[2] * 10 + S[3] > 12 or S[2] * 10 + S[3] == 0):
	print('MMYY')
elif (S[0] * 10 + S[1] > 12 or S[0] * 10 + S[1] == 0) and 1 <= S[2] * 10 + S[3] <= 12:
	print('YYMM')
elif (S[0] * 10 + S[1] > 12 or S[0] * 10 + S[1] == 0) and (S[2] * 10 + S[3] > 12 or S[2] * 10 + S[3] == 0):
	print('NA')


A = input()
(B, C) = (int(A[0:2]), int(A[2:4]))
if 1 <= B <= 12 and 1 <= C <= 12:
	print('AMBIGUOUS')
elif 1 <= B <= 12:
	print('MMYY')
elif 1 <= C <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
s1 = int(S[0:2])
s2 = int(S[2:])
if 1 <= s1 <= 12 and 1 <= s2 <= 12:
	print('AMBIGUOUS')
elif 1 <= s2 <= 12:
	print('YYMM')
elif 1 <= s1 <= 12:
	print('MMYY')
else:
	print('NA')


n = input()
a = int(n[:2])
b = int(n[2:])
if 1 <= a < 13:
	if 1 <= b < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= b < 13:
	print('YYMM')
else:
	print('NA')


S = input()
yymm = 1 <= int(S[2:]) <= 12
mmyy = 1 <= int(S[:2]) <= 12
print('AMBIGUOUS' if yymm and mmyy else 'YYMM' if yymm else 'MMYY' if mmyy else 'NA')


s = input()
s1 = s[:2]
s2 = s[2:4]
r = int(s2)
l = int(s1)
if 1 <= r <= 12 and 1 <= l <= 12:
	print('AMBIGUOUS')
elif (r > 12 or r == 0) and 1 <= l <= 12:
	print('MMYY')
elif (l >= 12 or l == 0) and 1 <= r <= 12:
	print('YYMM')
else:
	print('NA')


s = str(input())
ans = ['YYMM', 'MMYY', 'AMBIGUOUS', 'NA']
if (0 == int(s[:2]) or 13 <= int(s[:2])) and (0 == int(s[-2:]) or 13 <= int(s[-2:])):
	print(ans[3])
if 0 < int(s[:2]) <= 12 and 0 < int(s[-2:]) <= 12:
	print(ans[2])
elif 0 < int(s[:2]) <= 12:
	print(ans[1])
elif 0 < int(s[-2:]) <= 12:
	print(ans[0])


(a, b, c, d) = input()
(ym, my) = (int(a + b), int(c + d))
if 0 < ym < 13 and 0 < my < 13:
	print('AMBIGUOUS')
elif 0 < ym < 13:
	print('MMYY')
elif 0 < my < 13:
	print('YYMM')
else:
	print('NA')


S = int(input())
a = S % 100
b = (S - a) / 100
if 1 <= a <= 12:
	if 1 <= b <= 12:
		print('AMBIGUOUS')
	else:
		print('YYMM')
elif 1 <= b <= 12:
	print('MMYY')
else:
	print('NA')


S = input().strip()
a = int(S[:2])
b = int(S[2:])
aa = a < 13 and a != 0
bb = b < 13 and b != 0
if aa and bb:
	ans = 'AMBIGUOUS'
elif aa and (not bb):
	ans = 'MMYY'
elif bb and (not aa):
	ans = 'YYMM'
else:
	ans = 'NA'
print(ans)


s = input()
n1 = int(s[0:2])
n2 = int(s[2:4])
if 0 < n1 < 13:
	if 0 < n2 < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < n2 < 13:
	print('YYMM')
else:
	print('NA')


s = input()
flg1 = 1 <= int(s[:2]) <= 12
flg2 = 1 <= int(s[2:]) <= 12
l = ['NA', 'YYMM', 'MMYY', 'AMBIGUOUS']
print(l[(flg1 << 1) + flg2])


s = input()
f = int(s[:2])
g = int(s[2:])
if 0 < f < 13 and 0 < g < 13:
	print('AMBIGUOUS')
elif 0 < f < 13:
	print('MMYY')
elif 0 < g < 13:
	print('YYMM')
else:
	print('NA')


s = input()
s = [int(s[:2]), int(s[2:])]
ans = 0
if s[0] < 1 or s[0] > 12:
	ans += 1
if s[1] < 1 or s[1] > 12:
	ans += 2
p = ['AMBIGUOUS', 'YYMM', 'MMYY', 'NA']
print(p[ans])


def check_month(month):
	return 1 <= int(month) <= 12
S = input()
ls = S[:2]
rs = S[2:]
if check_month(ls) and check_month(rs):
	print('AMBIGUOUS')
elif check_month(ls) and (not check_month(rs)):
	print('MMYY')
elif not check_month(ls) and check_month(rs):
	print('YYMM')
else:
	print('NA')


s = input()
a = s[:2]
b = s[2:]
l = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
if a in l and b in l:
	print('AMBIGUOUS')
elif a in l and b not in l:
	print('MMYY')
elif a not in l and b in l:
	print('YYMM')
else:
	print('NA')


yymm = input()
if (1 <= int(yymm[0:2]) and int(yymm[0:2]) <= 12) and (1 <= int(yymm[2:4]) and int(yymm[2:4]) <= 12):
	print('AMBIGUOUS')
elif (1 <= int(yymm[0:2]) and int(yymm[0:2]) <= 12) and int(yymm[2:4]) <= 99:
	print('MMYY')
elif int(yymm[0:2]) <= 99 and (1 <= int(yymm[2:4]) and int(yymm[2:4]) <= 12):
	print('YYMM')
else:
	print('NA')


s = str(input())
ans = 'NA'
x = int(s[0:2])
y = int(s[2:4])
if x > 0 and x < 13:
	ans = 'MMYY'
if y > 0 and y < 13:
	ans = 'YYMM'
if x > 0 and x < 13 and (y > 0) and (y < 13):
	ans = 'AMBIGUOUS'
print(ans)


S = input()
s1 = int(S[0:2])
s2 = int(S[2:5])
if 1 <= s1 <= 12:
	print('AMBIGUOUS' if 1 <= s2 <= 12 else 'MMYY')
else:
	print('YYMM' if 1 <= s2 <= 12 else 'NA')


s = input()
if s == '0000' or (int(s[:2]) >= 13 and int(s[-2:]) >= 13):
	print('NA')
elif 1 <= int(s[:2]) <= 12 and 1 <= int(s[-2:]) <= 12:
	print('AMBIGUOUS')
elif 1 <= int(s[:2]) <= 12:
	print('MMYY')
elif 1 <= int(s[-2:]) <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
months = set([str(i).zfill(2) for i in range(1, 13)])
res = ''
if S[:2] in months and S[2:] in months:
	res = 'AMBIGUOUS'
elif S[:2] in months:
	res = 'MMYY'
elif S[2:] in months:
	res = 'YYMM'
else:
	res = 'NA'
print(res)


y = str(input())
ans = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
k = 0
if 1 <= int(y[:2]) <= 12:
	k += 1
if 1 <= int(y[2:]) <= 12:
	k += 2
print(ans[k])


s = list(input())
s = [int(i + j) for (i, j) in zip(s[::2], s[1::2])]
if 1 <= s[0] <= 12:
	if 1 <= s[1] <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= s[1] <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
sm = int(s[0:2])
sl = int(s[2:4])
ans = [['NA', 'MMYY'], ['YYMM', 'AMBIGUOUS']]
qm = 1 <= sm <= 12
ql = 1 <= sl <= 12
print(ans[ql][qm])


S = int(input())
L = S // 100
R = S % 100
if 1 <= L <= 12:
	if 1 <= R <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= R <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
s1 = int(s[0] + s[1])
s2 = int(s[2] + s[3])
L = []
for i in range(1, 13):
	L.append(i)
if s1 not in L and s2 not in L:
	print('NA')
elif s1 in L and s2 not in L:
	print('MMYY')
elif s1 not in L and s2 in L:
	print('YYMM')
else:
	print('AMBIGUOUS')


s = str(input())
s_ov = s[:2]
s_un = s[2:]
if int(s_ov) >= 1 and int(s_ov) <= 12:
	if int(s_un) >= 1 and int(s_un) <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif int(s_un) >= 1 and int(s_un) <= 12:
	print('YYMM')
else:
	print('NA')


S = str(input())
F = S[:2]
L = S[2:]
if F == '00' or int(F) > 12:
	if L == '00' or int(L) > 12:
		ans = 'NA'
	else:
		ans = 'YYMM'
elif int(F) <= 12:
	if int(L) >= 1 and int(L) <= 12:
		ans = 'AMBIGUOUS'
	else:
		ans = 'MMYY'
print(ans)


(a, b, c, d) = input()
(x, y) = (int(a + b), int(c + d))
if 0 < x < 13 and 0 < y < 13:
	print('AMBIGUOUS')
elif 0 < x < 13:
	print('MMYY')
elif 0 < y < 13:
	print('YYMM')
else:
	print('NA')


s = input()
a = s[0] + s[1]
b = s[2] + s[3]
p = 0
q = 0
if a == '01' or a == '02' or a == '03' or (a == '04') or (a == '05') or (a == '06') or (a == '07') or (a == '08') or (a == '09') or (a == '10') or (a == '11') or (a == '12'):
	p = 1
if b == '01' or b == '02' or b == '03' or (b == '04') or (b == '05') or (b == '06') or (b == '07') or (b == '08') or (b == '09') or (b == '10') or (b == '11') or (b == '12'):
	q = 1
if p == 1 and q == 1:
	print('AMBIGUOUS')
elif p == 1 and q == 0:
	print('MMYY')
elif p == 0 and q == 1:
	print('YYMM')
else:
	print('NA')


A = int(input())
B = int(A / 100)
C = A % 100
if 1 <= B and B <= 12:
	if 1 <= C and C <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= C and C <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
(a, b) = (int(s[:2]), int(s[2:]))
c = 1 <= a <= 12
d = 1 <= b <= 12
if c and d:
	print('AMBIGUOUS')
elif c:
	print('MMYY')
elif d:
	print('YYMM')
else:
	print('NA')


n = input()
N = int(n[0] + n[1])
M = int(n[2] + n[3])
if 0 < N < 13 and 0 < M < 13:
	print('AMBIGUOUS')
elif 0 < N < 13:
	print('MMYY')
elif 0 < M < 13:
	print('YYMM')
else:
	print('NA')


S = input()
x = int(S[:2])
y = int(S[2:])
if 0 < x < 13 and 0 < y < 13:
	print('AMBIGUOUS')
elif 0 < x < 13:
	print('MMYY')
elif 0 < y < 13:
	print('YYMM')
else:
	print('NA')


S = int(input())
A = S // 100
B = S % 100
if 0 < A <= 12 and 0 < B <= 12:
	print('AMBIGUOUS')
elif 0 < A <= 12:
	print('MMYY')
elif 0 < B <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
(A, B) = (int(S[:2]), int(S[2:]))
MMp = lambda x: 1 if x <= 12 and x != 0 else 0
print(['NA', 'YYMM', 'MMYY', 'AMBIGUOUS'][MMp(A) * 2 + MMp(B)])


s = input()
form = int(s[:2])
latt = int(s[2:])
if 0 < form <= 12:
	if 0 < latt <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < latt <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
yy = ['%02d' % i for i in range(100)]
mm = ['%02d' % i for i in range(1, 13)]
yymm = s[:2] in yy and s[2:] in mm
mmyy = s[:2] in mm and s[2:] in yy
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][yymm * 2 + mmyy])


def is_month(x):
	if 1 <= x <= 12:
		return True
	else:
		return False
S = input()
(first, latter) = (is_month(int(S[:2])), is_month(int(S[2:])))
if first and latter:
	ans = 'AMBIGUOUS'
elif not first and (not latter):
	ans = 'NA'
elif first:
	ans = 'MMYY'
else:
	ans = 'YYMM'
print(ans)


S = str(input())
L = int(S[0:2])
R = int(S[2:4])
if 1 <= L <= 12 and 1 <= R <= 12:
	print('AMBIGUOUS')
elif 1 <= L <= 12:
	print('MMYY')
elif 1 <= R <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
MM = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
if S[:2] in MM and S[2:] in MM:
	print('AMBIGUOUS')
elif S[:2] in MM:
	print('MMYY')
elif S[2:] in MM:
	print('YYMM')
else:
	print('NA')


s = input()
F = 0 < int(s[:2]) < 13
S = 0 < int(s[2:]) < 13
print('AMBIGUOUS' if F * S else 'YYMM' if S else 'MMYY' if F else 'NA')


S = input()
(l, r) = (int(S[:2]), int(S[2:]))
if 0 < l < 13 and 0 < r < 13:
	print('AMBIGUOUS')
elif 0 < l < 13:
	print('MMYY')
elif 0 < r < 13:
	print('YYMM')
else:
	print('NA')


a = int(input())
y = a // 100
m = a % 100
if 1 <= y <= 12 and 1 <= m <= 12:
	print('AMBIGUOUS')
elif 1 <= y <= 12:
	print('MMYY')
elif 1 <= m <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
(XX, YY) = (int(S[:2]), int(S[2:]))
msg = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
id = 0
if 0 < XX <= 12:
	id += 1
if 0 < YY <= 12:
	id += 2
print(msg[id])


s = input()
a1 = int(s[:2])
a2 = int(s[2:])
if a1 in range(1, 13):
	if a2 in range(1, 13):
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif a2 in range(1, 13):
	print('YYMM')
else:
	print('NA')


n = int(input())
n1 = n // 100
n2 = n % 100
if 0 < n1 < 13 and 0 < n2 < 13:
	print('AMBIGUOUS')
elif 0 < n1 < 13:
	print('MMYY')
elif 0 < n2 < 13:
	print('YYMM')
else:
	print('NA')


s = input()
ans = 'NA'
if 1 <= int(s[:2]) <= 12:
	ans = 'MMYY'
	if 1 <= int(s[2:]) <= 12:
		ans = 'AMBIGUOUS'
elif 1 <= int(s[2:]) <= 12:
	ans = 'YYMM'
print(ans)


S = input()
S_front = S[:2]
S_back = S[2:]
if 0 < int(S_front) < 13:
	if 0 < int(S_back) < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < int(S_back) < 13:
	print('YYMM')
else:
	print('NA')


import re
s = input()

def is_valid_yymm(s):
	match = re.search('^[0-9]{2}(01|02|03|04|05|06|07|08|09|10|11|12)$', s)
	return bool(match)

def is_valid_mmyy(s):
	match = re.search('^(01|02|03|04|05|06|07|08|09|10|11|12)[0-9]{2}$', s)
	return bool(match)
if is_valid_yymm(s) and is_valid_mmyy(s):
	print('AMBIGUOUS')
elif is_valid_yymm(s):
	print('YYMM')
elif is_valid_mmyy(s):
	print('MMYY')
else:
	print('NA')


import re

def answer(s: str) -> str:
	YYMM = '^[0-9]{2}(0[1-9]|1[0-2])$'
	MMYY = '^(0[1-9]|1[0-2])[0-9]{2}$'
	YYMM_result = re.match(YYMM, s)
	MMYY_result = re.match(MMYY, s)
	if YYMM_result and MMYY_result:
		return 'AMBIGUOUS'
	if YYMM_result:
		return 'YYMM'
	if MMYY_result:
		return 'MMYY'
	return 'NA'

def main():
	s = input()
	print(answer(s))

def __starting_point():
	main()
__starting_point()


s = input()
b1 = 1 <= int(s[:2]) <= 12
b2 = 1 <= int(s[2:]) <= 12
ans = ['NA', 'YYMM', 'MMYY', 'AMBIGUOUS']
print(ans[2 * b1 + b2])


i = input()
(l, m) = map(int, [i[:2], i[2:]])
my = int(1 <= l and l <= 12)
ym = int(1 <= m and m <= 12) << 1
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][my + ym])


S = input()
com = ['YYMM', 'MMYY', 'AMBIGUOUS', 'NA']
if 1 <= int(S[:2]) <= 12 and 1 <= int(S[2:]) <= 12:
	print(com[2])
elif 1 <= int(S[:2]) <= 12:
	print(com[1])
elif 1 <= int(S[2:]) <= 12:
	print(com[0])
else:
	print(com[3])


s = input()
flag = [0, 0]
if 1 <= int(s[0:2]) <= 12:
	flag[0] = 1
if 1 <= int(s[2:4]) <= 12:
	flag[1] = 1
if flag == [0, 0]:
	print('NA')
if flag == [1, 0]:
	print('MMYY')
if flag == [0, 1]:
	print('YYMM')
if flag == [1, 1]:
	print('AMBIGUOUS')


S = input()
a = int(S[:2])
b = int(S[2:])
ans = 0
lab = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
if a >= 1 and a <= 12:
	ans += 1
if b >= 1 and b <= 12:
	ans += 2
print(lab[ans])


a = input()
n = int(a[0:2])
m = int(a[2:4])
if 0 < n <= 12 and 0 < m <= 12:
	print('AMBIGUOUS')
elif 0 < n <= 12:
	print('MMYY')
elif 0 < m <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
print('AMBIGUOUS' if 0 < int(S[:2]) < 13 and 0 < int(S[2:]) < 13 else 'MMYY' if 0 < int(S[:2]) < 13 else 'YYMM' if 0 < int(S[2:]) < 13 else 'NA')


S = list(input())
month = ['0' + str(i) for i in range(1, 10)]
month.append('10')
month.append('11')
month.append('12')
First = S[:2]
Fmonthflag = 0
if ''.join(First) in month:
	Fmonthflag = 1
Latter = S[2:]
Lmonthflag = 0
if ''.join(Latter) in month:
	Lmonthflag = 1
if Fmonthflag == 1 and Lmonthflag == 0:
	print('MMYY')
elif Fmonthflag == 0 and Lmonthflag == 1:
	print('YYMM')
elif Fmonthflag == 1 and Lmonthflag == 1:
	print('AMBIGUOUS')
elif Fmonthflag == 0 and Lmonthflag == 0:
	print('NA')


YYMM = list(input())
YY = int(YYMM[0] + YYMM[1])
MM = int(YYMM[2] + YYMM[3])
YYMM = False
MMYY = False
if 1 <= MM <= 12:
	YYMM = True
if 1 <= YY <= 12:
	MMYY = True
if YYMM == True and MMYY == True:
	print('AMBIGUOUS')
elif YYMM == True and MMYY == False:
	print('YYMM')
elif YYMM == False and MMYY == True:
	print('MMYY')
elif YYMM == False and MMYY == False:
	print('NA')


S = input()
(a, b) = (S[:2], S[2:])
a_can_month = 1 <= int(a) <= 12
b_can_month = 1 <= int(b) <= 12
print([['NA', 'YYMM'], ['MMYY', 'AMBIGUOUS']][a_can_month][b_can_month])


S = str(input())
L = int(S[0]) * 10 + int(S[1])
R = int(S[2]) * 10 + int(S[3])
if 12 >= L >= 1:
	if 12 >= R >= 1:
		print('AMBIGUOUS')
		return
	print('MMYY')
	return
else:
	if 12 >= R >= 1:
		print('YYMM')
		return
	print('NA')
	return


s = list(map(int, list(input())))
a = s[0] * 10 + s[1]
b = s[2] * 10 + s[3]
if a == 0 and b == 0:
	print('NA')
	return
if 0 < a <= 12 and (b > 12 or b == 0):
	print('MMYY')
elif (a > 12 or a == 0) and 0 < b <= 12:
	print('YYMM')
elif a <= 12 and b <= 12:
	print('AMBIGUOUS')
else:
	print('NA')


S = input()
A = int(S[:2])
B = int(S[2:])
if 1 <= A <= 12:
	if 1 <= B <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= B <= 12:
	print('YYMM')
else:
	print('NA')


s = input()

def month(n):
	if 1 <= n <= 12:
		return True
	else:
		return False
if int(s[0:2]) == 0:
	if month(int(s[2:4])):
		print('YYMM')
		return
	else:
		print('NA')
		return
if int(s[2:4]) == 0:
	if month(int(s[0:2])):
		print('MMYY')
		return
	else:
		print('NA')
		return
if month(int(s[0:2])):
	if month(int(s[2:4])):
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif month(int(s[2:4])):
	print('YYMM')
else:
	print('NA')


a = int(input())
b = a % 100
a = a // 100
print(('AMBIGUOUS' if 0 < b < 13 else 'MMYY') if 0 < a < 13 else 'YYMM' if 0 < b < 13 else 'NA')


S = input()
x = int(S[:2])
y = int(S[2:])
if 1 <= x <= 12 and 1 <= y <= 12:
	print('AMBIGUOUS')
elif 1 <= x <= 12:
	print('MMYY')
elif 1 <= y <= 12:
	print('YYMM')
else:
	print('NA')


S = int(input())
XX = S // 100
YY = S % 100
if 1 <= XX <= 12 and 1 <= YY <= 12:
	print('AMBIGUOUS')
elif 1 <= YY <= 12:
	print('YYMM')
elif 1 <= XX <= 12:
	print('MMYY')
else:
	print('NA')


S = input()
a = int(S[:2])
b = int(S[2:4])
cYYMM = b > 0 and b < 13
cMMYY = a > 0 and a < 13
print([['NA', 'YYMM'], ['MMYY', 'AMBIGUOUS']][cMMYY][cYYMM])


s = input()
aa = int(s[:2])
bb = int(s[2:])
if 1 <= aa <= 12:
	print('AMBIGUOUS') if 1 <= bb <= 12 else print('MMYY')
else:
	print('YYMM') if 1 <= bb <= 12 else print('NA')


S = input()
F = int(S[:2]) > 0 and int(S[:2]) < 13
B = int(S[2:]) > 0 and int(S[2:]) < 13
print(['NA', 'YYMM', 'MMYY', 'AMBIGUOUS'][2 * F + B])


s = input()
if 1 <= int(s[0:2]) < 13:
	if 1 <= int(s[2:4]) < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= int(s[2:4]) < 13:
	print('YYMM')
else:
	print('NA')


s = input()
a = int(s[:2])
p = int(s[-2:])
if 0 < a <= 12 and 0 < p <= 12:
	print('AMBIGUOUS')
elif 0 < a <= 12:
	print('MMYY')
elif 0 < p <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
x = int(s[:2])
y = int(s[2:])
if 0 < x <= 12 and 0 < y <= 12:
	print('AMBIGUOUS')
elif 0 < x <= 12:
	print('MMYY')
elif 0 < y <= 12:
	print('YYMM')
else:
	print('NA')


S = int(input())
flag = [0, 0]
l = S // 100
r = S % 100
if 1 <= r and r <= 12:
	flag[0] += 1
if 1 <= l and l <= 12:
	flag[1] += 1
if flag == [0, 0]:
	print('NA')
elif flag == [0, 1]:
	print('MMYY')
elif flag == [1, 0]:
	print('YYMM')
elif flag == [1, 1]:
	print('AMBIGUOUS')


s = input()
s1 = int(s[0:2])
s2 = int(s[2:4])
if s1 <= 12 and s1 >= 1:
	print('AMBIGUOUS' if s2 <= 12 and s2 >= 1 else 'MMYY')
else:
	print('YYMM' if s2 <= 12 and s2 >= 1 else 'NA')


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	S = ins()
	a = int(S[:2])
	b = int(S[2:])
	am = 0 < a < 13
	bm = 0 < b < 13
	if am and bm:
		return 'AMBIGUOUS'
	elif am:
		return 'MMYY'
	elif bm:
		return 'YYMM'
	else:
		return 'NA'
print(solve())


s = input()
(sf, sl) = (int(s[:2]), int(s[2:]))
if sf >= 1 and sf <= 12:
	print('AMBIGUOUS' if sl >= 1 and sl <= 12 else 'MMYY')
else:
	print('YYMM' if sl >= 1 and sl <= 12 else 'NA')


S = input()
A = S[:2]
B = S[2:]
x = 1 * (sorted([A, '01', '12'])[1] == A)
y = 2 * (sorted([B, '01', '12'])[1] == B)
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][x + y])


s = input()
r = ''.join(['MM' if 1 <= i <= 12 else 'YY' for i in list(map(int, (s[:2], s[2:])))])
print(r if r != 'MMMM' and r != 'YYYY' else ['AMBIGUOUS', 'NA'][r == 'YYYY'])


s = input()
(a, b) = (int(s[:2]), int(s[2:]))
c = 0
if 1 <= a <= 12:
	c += 1
if 1 <= b <= 12:
	c += 2
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][c])


s = input()
(a, b) = (int(s[:2]), int(s[2:]))
r = ['AMBIGUOUS', 'YYMM', 'MMYY', 'NA']
print(r[(0 if 0 < b < 13 else 2) + (0 if 0 < a < 13 else 1)])


a = input()
if 0 < int(a[:2]) <= 12:
	if 0 < int(a[2:]) <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < int(a[2:]) <= 12:
	print('YYMM')
else:
	print('NA')


def f(y, m):
	if y in range(1, 13) and m in range(1, 13):
		return 'AMBIGUOUS'
	if m in range(1, 13):
		return 'YYMM'
	if y in range(1, 13):
		return 'MMYY'
	return 'NA'
S = input()
(y, m) = (int(S[:2]), int(S[2:]))
print(f(y, m))


S = input()
num1 = int(S[:2])
num2 = int(S[2:])
if 1 <= num1 <= 12 and 1 <= num2 <= 12:
	ans = 'AMBIGUOUS'
elif 1 <= num1 <= 12 and (num2 == 0 or 12 < num2):
	ans = 'MMYY'
elif (num1 == 0 or 12 < num1) and 1 <= num2 <= 12:
	ans = 'YYMM'
else:
	ans = 'NA'
print(ans)


S = input()
b = int(S[:2])
a = int(S[2:])
c = (b < 1) + (b > 12)
d = ((a < 1) + (a > 12)) * 2
e = c + d
print(['AMBIGUOUS', 'YYMM', 'MMYY', 'NA'][e])


s = input()
(a, b) = map(int, (s[:2], s[2:]))
print('AMBIGUOUS' if 1 <= a <= 12 and 1 <= b <= 12 else 'MMYY' if 1 <= a <= 12 and 0 <= b <= 99 else 'YYMM' if 0 <= a <= 99 and 1 <= b <= 12 else 'NA')


S = input()
mmyy = 1 <= int(S[:2]) <= 12
yymm = 1 <= int(S[2:]) <= 12
l = [['AMBIGUOUS', 'MMYY'], ['YYMM', 'NA']]
print(l[not mmyy][not yymm])


s = input()
yymm = 1 <= int(s[2:4]) <= 12
mmyy = 1 <= int(s[0:2]) <= 12
print('AMBIGUOUS' if yymm and mmyy else 'YYMM' if yymm else 'MMYY' if mmyy else 'NA')


S = input()
if 1 <= int(S[0:2]) <= 12:
	if 1 <= int(S[2:4]) <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= int(S[2:4]) <= 12:
	print('YYMM')
else:
	print('NA')


s = input()
f1 = 1 <= int(s[:2]) <= 12
f2 = 1 <= int(s[2:4]) <= 12
if f1 and f2:
	print('AMBIGUOUS')
elif not f1 and (not f2):
	print('NA')
elif f1:
	print('MMYY')
else:
	print('YYMM')


s = input()
mae = int(s[:2])
ushiro = int(s[2:])
if 1 <= mae <= 12:
	if 1 <= ushiro <= 12:
		ans = 'AMBIGUOUS'
	else:
		ans = 'MMYY'
elif 1 <= ushiro <= 12:
	ans = 'YYMM'
else:
	ans = 'NA'
print(ans)


S = int(input())
a = int(S / 100 - S % 100 / 100)
b = int(S % 100)
if 0 < a < 13 and 0 < b < 13:
	print('AMBIGUOUS')
if 0 < a < 13 and 12 < b < 100 or (0 < a < 13 and b == 0):
	print('MMYY')
if 12 < a < 100 and 0 < b < 13 or (a == 0 and 0 < b < 13):
	print('YYMM')
if 12 < a < 100 and 12 < b < 100:
	print('NA')
if a == 0 and 12 < b < 100:
	print('NA')
if 12 < a < 100 and b == 0:
	print('NA')
if a == 0 and b == 0:
	print('NA')


def YY(x):
	if 1 <= x and x <= 12:
		return True
	else:
		return False
S = input()
A = int(S[0:2])
B = int(S[2:4])
if YY(A) and YY(B):
	print('AMBIGUOUS')
elif YY(A):
	print('MMYY')
elif YY(B):
	print('YYMM')
else:
	print('NA')


data = str(input())
one = int(data[:2])
two = int(data[2:])
if 0 < one < 13 and 0 < two < 13:
	print('AMBIGUOUS')
elif 0 < one < 13:
	print('MMYY')
elif 0 < two < 13:
	print('YYMM')
else:
	print('NA')


S = input()
AA = int(S[:2])
BB = int(S[2:])
print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][(1 <= AA <= 12) + 2 * (1 <= BB <= 12)])


S = str(input())
year = int(S[0] + S[1])
month = int(S[2] + S[3])
if year <= 12 and year >= 1 and (month >= 1) and (month <= 12):
	print('AMBIGUOUS')
elif year >= 0 and year <= 99 and (month >= 1) and (month <= 12):
	print('YYMM')
elif year >= 1 and year <= 12 and (month >= 0) and (month <= 99):
	print('MMYY')
else:
	print('NA')


n = int(input())
l = n // 100
r = n % 100
yymm = 1 <= r <= 12
mmyy = 1 <= l <= 12
if yymm:
	print('AMBIGUOUS' if mmyy else 'YYMM')
else:
	print('MMYY' if mmyy else 'NA')


S = input()
Y = int(S[:2])
M = int(S[2:])
if 0 < Y < 13 and 0 < M < 13:
	print('AMBIGUOUS')
elif 0 < M < 13:
	print('YYMM')
elif 0 < Y < 13:
	print('MMYY')
else:
	print('NA')


s = input()
aa = int(s[:2])
bb = int(s[2:])
if 0 < aa <= 12 and 0 < bb <= 12:
	ans = 'AMBIGUOUS'
elif 0 < bb <= 12:
	ans = 'YYMM'
elif 0 < aa <= 12:
	ans = 'MMYY'
else:
	ans = 'NA'
print(ans)


s = input()
a = int(s[:2])
b = int(s[2:])
print('AMBIGUOUS' if 1 <= a <= 12 and 1 <= b <= 12 else 'YYMM' if 1 <= b <= 12 else 'MMYY' if 1 <= a <= 12 else 'NA')


S = input()
Sf = int(S[:2])
Sb = int(S[2:])
if 1 <= Sf <= 12:
	if 1 <= Sb <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= Sb <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
f = int(S[:2])
l = int(S[2:])
if f == 0 or f > 12:
	if l == 0 or l > 12:
		print('NA')
	else:
		print('YYMM')
elif l == 0 or l > 12:
	print('MMYY')
else:
	print('AMBIGUOUS')


S = int(input())
L = S // 100
R = S % 100
if 0 < L < 13:
	if 0 < R < 13:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 0 < R < 13:
	print('YYMM')
else:
	print('NA')


s = input()
l = 0 < int(s[:2]) < 13
r = 0 < int(s[2:]) < 13
if l == 1:
	print('AMBIGUOUS' if r == 1 else 'MMYY')
else:
	print('YYMM' if r == 1 else 'NA')


S = input()
former = int(S[:2])
latter = int(S[2:])
if (former >= 13 or former == 0) and 1 <= latter <= 12:
	print('YYMM')
if (latter >= 13 or latter == 0) and 1 <= former <= 12:
	print('MMYY')
if 1 <= former <= 12 and 1 <= latter <= 12:
	print('AMBIGUOUS')
if (former >= 13 or former == 0) and (latter >= 13 or latter == 0):
	print('NA')


s = input()
r = ('NA', 'MMYY', 'YYMM', 'AMBIGUOUS')
f = lambda x: 1 <= int(x) <= 12
print(r[f(s[:2]) + 2 * f(s[2:])])


s = int(input())
s1 = s // 100
s2 = s % 100
c = 0
l = ['NA', 'YYMM', 'MMYY', 'AMBIGUOUS']
if 1 <= s2 <= 12:
	c += 1
if 1 <= s1 <= 12:
	c += 2
print(l[c])


s = input()
if s[0:2] in '01 02 03 04 05 06 07 08 09 10 11 12':
	l = 'm'
else:
	l = 'y'
if s[2:4] in '01 02 03 04 05 06 07 08 09 10 11 12':
	r = 'm'
else:
	r = 'y'
if l + r == 'mm':
	print('AMBIGUOUS')
elif l + r == 'my':
	print('MMYY')
elif l + r == 'ym':
	print('YYMM')
else:
	print('NA')


c = input()
f = int(c[:2])
e = int(c[2:])
if 0 < f < 13 and 0 < e < 13:
	print('AMBIGUOUS')
elif 0 < f < 13:
	print('MMYY')
elif 0 < e < 13:
	print('YYMM')
else:
	print('NA')


n = list(input())
x = int(n[0] + n[1])
y = int(n[2] + n[3])
if 1 <= x and x <= 12:
	if 1 <= y and y <= 12:
		print('AMBIGUOUS')
	else:
		print('MMYY')
elif 1 <= y and y <= 12:
	print('YYMM')
else:
	print('NA')


S = input()
(my, ym) = (0 < int(S[:2]) < 13, 0 < int(S[2:]) < 13)
if my and ym:
	o = 'AMBIGUOUS'
elif my:
	o = 'MMYY'
elif ym:
	o = 'YYMM'
else:
	o = 'NA'
print(o)


s = int(input())
t = s / 100
u = s % 100
if 1 <= t <= 12 and 1 <= u <= 12:
	print('AMBIGUOUS')
elif 1 <= t <= 12:
	print('MMYY')
elif 1 <= u <= 12:
	print('YYMM')
else:
	print('NA')