Harryxun/stf_run huggingface dataset:
import sys
import math

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7

def P(n, r):
    num = int(math.factorial(n) / math.factorial(n - r))
    return num



n, k = list(map(int, sys.stdin.readline().split()))
graph = [dict() for i in range(n)]
for i in range(n):
    graph[i]["eda"]=[]
for i in range(n - 1):
    a, b = list(map(int, sys.stdin.readline().split()))
    graph[a - 1]["eda"].append(b - 1)
    graph[b - 1]["eda"].append(a - 1)
ans = 1
check = [False] * n
stack = [0]
ans = 1
while len(stack) > 0:
    x = stack.pop()
    check[x] = True
    count = 0
    for i in graph[x]["eda"]:
        if not check[i]:
            count += 1
            stack.append(i)
    if x == 0:
        temp = P(k - 1, count)
        ans = (ans * temp) % INF
    else:
        temp = P(k - 2, count)
        ans = (ans * temp) % INF

print((ans * k) % INF)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF=10**9+7
def LI(): return list(map(int, sys.stdin.readline().split()))
 
def main():
    n, k = LI()
    graph=[[] for i in range(n)]
    for i in range(n-1):
        a,b=LI()
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=1
    check=[False]*n
    stack=[0]
    ans=1
    while len(stack)>0:
        x=stack.pop()
        check[x]=True
        count=0
        for i in graph[x]:
            if not check[i]:
                count+=1
                stack.append(i)
        if x==0:
            temp=1
            for i in range(count):
                temp=temp*(k-1-i)%INF
            ans=ans*temp%INF
        else:
            temp=1
            for i in range(count):
                temp=temp*(k-2-i)%INF
            ans=ans*temp%INF
    print((ans*k)%INF)
 
 
if __name__ == "__main__":
    main()
X,N=map(int,input().split() )
if(N==0 || N==100):
  print(X)

else:
  p = list(map(int,input().split() ))

  p.sort()
  q=list(range(1,max(p)+1))

  for i in p:
    q.remove(i)

  Z=1000
  ans=-1
  for i in q:
    if( abs(X-i)<Z):
      Z=abs(X-i)
      ans=i
  
  print(ans)

### FIXED CODE ###

X,N=map(int,input().split() )
if( (N==0)):
  print(X)

else:
  p = list(map(int,input().split() ))

  p.sort()
  q=list(range(-5,102))

  for i in p:
    q.remove(i)

  Z=1000
  for i in q:
    if( abs(X-i)<Z):
      Z=abs(X-i)
      ans=i
  
  print(ans)
from sys import stdin
from math import factorial

if __name__ == '__main__':

    N, K = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = 1000000007

    for r in range(K):
        r += 1
        n = N - K + 1

        ret = factorial(n) // factorial(r) // factorial(n - r)
        ret2 = factorial(K-1) // factorial(r-1) // factorial((K - 1) - (r - 1))

        print((ret * ret2) % tmp )


### FIXED CODE ###

from sys import stdin
from math import factorial

if __name__ == '__main__':

    N, K = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = 1000000007
    r = 0
    for r in range(K):
        r += 1
        n = N - K + 1

        if n - r < 0 or K - r < 0:
            print(0)
            continue

        ret = factorial(n) // factorial(r) // factorial(n - r)
        ret2 = factorial(K-1) // factorial(r-1) // factorial((K - 1) - (r - 1))

        print((ret * ret2) % tmp)
def forbidden(x,p):
    res = []
    if x==1:
        return 0
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    print(forbidden(x,p))

### FIXED CODE ###

x,n = map(int,input().split())
p = list(map(int,input().split()))
if x not in p:
    print(x)
    exit()
a,b = x,x
while True:
    a+=1
    b-=1
    if b not in p:
        print(b)
        break
    elif a not in p:
        print(a)
        break
r = input()
r = int(r)
pi = 3.14159265
print("{0:6f} {1:6f}".format((r * r * pi), (2 * r * pi)))

### FIXED CODE ###

r = input()
r = float(r)
pi = 3.14159265358979
print("{0:10f} {1:10f}".format((r ** 2 * pi), (2 * r * pi)))
S = [i for i in input().strip().split()]
S.sort()
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print("Yes")
else
  print("No")


### FIXED CODE ###

S = input()
S = sorted(S)
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print("Yes")
else:
  print("No")
import numpy　as np
N = int(input())
a = list(map(int, input().split()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 0):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

### FIXED CODE ###

import numpy as np
N = int(input())
a = list(map(int, input().split()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 0):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))
s = input()

#文字列をリスト化
s = list(s)
s = set(s)
s = sorted(s)

#print(s)

t = 'abcdefghijklmnopqrstuvwxyz'
t = list(t)
#print(t)

if s == t:
	print('None')
else:
	for i in range(len(t)):
		if s[i]!=t[i]:
			print(t[i])
			break




### FIXED CODE ###

s = input()

#文字列をリスト化
s = list(s)
s = set(s)
s = sorted(s)

#print(s)

t = 'abcdefghijklmnopqrstuvwxyz'
t = list(t)
#print(t)

if s == t:
	print('None')
else:
	for i in range(len(t)):
		#print(i)
		if i == 25:
			print(t[i])
			break
		elif s[i]!=t[i]:
			print(t[i])
			break
h,a = map(int,input().split())
print(h\\a)

### FIXED CODE ###

import math
h,a = map(int,input().split())
print(math.ceil(h/a))
n, m, d = list(map(int, input().split()))
if (d == 0):
  	ans = 1 / n
    print(ans)
else:
  ans = 2 * (n - d) / n ** 2
  print(ans)

### FIXED CODE ###

n, m, d = list(map(int, input().split()))
if (d == 0):
  ans = (m - 1) * (1 / n)
  print(ans)
else:
  ans = (m - 1) * (2 * (n - d) / n ** 2)
  print(ans)
import math
n,x = map(int,input().split())
xlist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = math.gcd(xlist[i]-x,ans)
print(ans)

### FIXED CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
n,x = map(int,input().split())
xlist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = gcd(abs(xlist[i]-x),ans)
print(ans)
import math
def lcm(a, b):
    g = math.gcd(a, b)
    return a * b // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    lcm = lcm(A[0], A[1])
    for i in range(2, N):
        lcm = lcm(lcm, A[i])

if N == 1:
    lcm = A[0]

ans = M // lcm
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)


### FIXED CODE ###

import math
def LCM(a, b):
    g = math.gcd(a, b)
    return a * b // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    lcm = LCM(A[0], A[1])
    for i in range(2, N):
        lcm = LCM(lcm, A[i])

if N == 1:
    lcm = A[0]

ans = M // lcm
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)
import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

S = input()
K = int(input())

con = list(nchars(S, 1))
#print(con)
if len(con)==1:
    print(int(len(S*K)/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[-1][0]:
        c3 = int(len(con[0]+con[-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[-1])/2)

    c4 = int(cons[-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))


### FIXED CODE ###

import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

S = input()
K = int(input())

con = list(nchars(S, 1))
#print(con)
if len(con)==1:
    print(int(len(S)*K/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[-1][0]:
        c3 = int(len(con[0]+con[-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[-1])/2)

    c4 = int(cons[-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))
D, N = map(int, raw_input().split())
if D == 0:
	if N == 100: print 101
	else: print N
if D == 2:
	if N == 100: print 1010000
	else: print str(N) + '0000'
if D == 1:
	n = ((N-1)/9)*10+(N%9)+1
	print str(n)*'00'

### FIXED CODE ###

D, N = map(int, raw_input().split())
ans = ''
if N == 100: ans = '101'
else: ans = str(N)

for i in range(0, D):
	ans = ans + '00'
print ans
import math
A, B, C, D = map(int, input().split())

def f(num, c, d):
    return num - (num // c + num // d - num // int(c * d / math.gcd(c, d)))

print (f(B, C, D) - f(A - 1, C, D))


### FIXED CODE ###

A, B, C, D = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def f(num, c, d):
    return num - (num // c + num // d - num // int(c * d / gcd(c, d)))

print (f(B, C, D) - f(A - 1, C, D))
N=input()
num=int(N[3:])

if num>999:
    print("ABD")
else:
    print("ABC")

### FIXED CODE ###

N = input()
num = int(N)
if num < 1000:
    print('ABC')
else:
    print('ABD')
N,K=map(int,input().split())
S=input()

L=[]

P=S[0]
cnt=1
for i in range(1,N):
    if S[i]==P:
        cnt+=1
    else:
        if P=="1":
            L.append(cnt)
            cnt=1
            P="0"
        else:
            L.append(cnt*-1)
            cnt=1
            P="1"
if P=="1":
    L.append(cnt)
else:
    L.append(cnt*-1)
X=[0 for i in range(len(L))]
L=X+L+X
#print(L)
ANS=[]
NUM=0
for i in range(1,2*K-1):
    NUM+=abs(L[i])
ANS=[NUM]
#print(ANS)

SUM=[0]
for i in range(1,len(L)):
    SUM.append(SUM[i-1]+abs(L[i]))

ans=0
if len(SUM)-len(X)<2*K+1:
    print(SUM[len(SUM)-1])
else:    
    for i in range(len(SUM)-len(X)):
        if L[i]<0:
            if (SUM[2*K+1+i]-SUM[i])>ans:
                ans=(SUM[2*K+1+i]-SUM[i])
        else:
            if (SUM[2*K+i]-SUM[i])>ans:
                ans=(SUM[2*K+i]-SUM[i])
            #print(i)
    print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
s=list(input())

S=[]
F="2"
cnt=0
for i in range(N):
    if F=="0":
        if s[i]=="0":
            cnt-=1
        else:
            S.append(cnt)
            F="1"
            cnt=1
    elif F=="1":
        if s[i]=="1":
            cnt+=1
        else:
            S.append(cnt)
            F="0"
            cnt=-1
    else:
        if s[i]=="0":
            F="0"
            cnt=-1
        else:
            F="1"
            cnt=1
S.append(cnt)
if S[0]<0:
    S=[0]+S+[0]
else:
    S=S+[0]

if S[0]>=0:
    if len(S)<=(2*K+1):
        ans=0
        for i in range(len(S)):
            ans+=abs(S[i])
        print(ans)
        #exit()
    else:
        ans=0
        SUM=0
        for i in range(2*K+1):
            SUM+=abs(S[i])
            ans=SUM
        #print(ans)
        for i in range(1,len(S)):
            if (2*i+2*K)>(len(S)-1):
                #print("A")
                break
            else:
                #print("B")
                SUM=SUM+abs(S[2*i+2*K-1])+abs(S[2*i+2*K])-abs(S[2*i-1])-abs(S[2*i-2])
                if SUM>ans:
                    ans=SUM
        print(ans)
        #exit()
#print(S)
import math

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
cnt = 0

for c in s:
  if len(s) == 0:
    break
  amnt = len(list(filter(lambda x: x == c, s[s.index(c)+1:])))
  cnt += amnt
  cnt += (sum(range(1, amnt)))
  s = list(filter(lambda x: x != c, s))

print(cnt)

### FIXED CODE ###

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

mp = {}
for c in s:
    if c in mp:
        mp[c] += 1
    else:
        mp[c] = 1

ans = 0
for key in mp.keys():
    ans += mp[key]*(mp[key]-1)/2
print(int(ans))
N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(b):
    for j,r in enumerate(r):
        if red[0]<blue[0] and red[1]<blue[1]:
            answer+=1
            red.pop(j)
            break

print(answer)

### FIXED CODE ###

N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(blue):
    for j,r in enumerate(red):
        if r[0]<b[0] and r[1]<b[1]:
            answer+=1
            red.pop(j)
            break

print(answer)
S = input()
Q = int(input())
query_q = [input().split() for _ in range(Q)]

for query in query_q:
    if query[0] == '1':
        S = S[::-1]
    elif query[0] == '2':
        if query[1] == '1':
            S = ''.join([query[2],*S])
        elif query[1] == '2':
            S = ''.join([*S,query[2]])

print(S)

### FIXED CODE ###

def main():

    S = input()
    Q = int(input())

    reverse = False
    head = ''
    tail = ''

    for _ in range(Q):
        query= input()
        if query == '1':
            reverse = not reverse
            head, tail = tail, head
        else:
            _, f, c = query.split()
            if f == '1':
                head = ''.join([head,c])
            else:
                tail = ''.join([tail,c])

    if reverse:
        S = S[::-1]

    print(''.join([head[::-1], S, tail]))

if __name__ == "__main__":
    main()
import itertools
N,M=map(int,input().split())
ab=list(list(map(int,input().split())) for _ in range(N))
l=list(l for l in range(1,N+1))
numlist=list(itertools.permutations(l))
ans=0
for I in numlist:
    x=0
    if I[0]==1 and all(sorted([I[j],I[j+1]]) in ab for j in range(N-1)):
        ans+=1
print(ans)

### FIXED CODE ###

import itertools
N,M=map(int,input().split())
ab=list(list(map(int,input().split())) for _ in range(M))
l=list(l for l in range(1,N+1))
numlist=list(itertools.permutations(l))
ans=0
for I in numlist:
    if I[0]==1 and all(sorted([I[j],I[j+1]]) in ab for j in range(N-1)):
        ans+=1
print(ans)
from collections import defaultdict
from functools import lru_cache

N, M = map(int, input().split())
XY = [map(int, input().split()) for _ in range(M)]

dp = [-1 for _ in range(N + 1)]

x_to_y = defaultdict(list)
for x, y in XY:
    x_to_y[x].append(y)


@lru_cache(N)
def depth(n):
    ret = -1
    for y in x_to_y[n]:
        ret = max(ret, depth(y))
    return ret + 1


        
depths = [depth(n) for n in range(1, N + 1)]
print(max(depths), default=0)


### FIXED CODE ###

from collections import defaultdict
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)


N, M = map(int, input().split())
XY = [map(int, input().split()) for _ in range(M)]

dp = [-1 for _ in range(N + 1)]

x_to_y = defaultdict(list)
for x, y in XY:
    x_to_y[x].append(y)


@lru_cache(N)
def depth(n):
    ret = -1
    for y in x_to_y[n]:
        ret = max(ret, depth(y))
    return ret + 1


        
depths = [depth(n) for n in range(1, N + 1)]
print(max(depths))
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
p=0
for i in range(n):
  p+=b[a[i-1]]
  if　a[i]-a[i-1]==1:
    p+=c[i]
print(p)
  


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
p=0
for i in range(n):
  p+=b[a[i]-1]
  if i>=1 and a[i]-a[i-1]==1:
    p+=c[a[i-1]-1]
print(p)
s = input().split()
s_new = input().split()
if s == s_new[0:len(s)]:
  if len(s) + 1 = len(s_new):
    print("Yes")
  else:
    print('No')
else:
  print("No")


### FIXED CODE ###

s = input().strip()
s_new = input().strip()
if s == s_new[0:len(s)]:
  if len(s) + 1 == len(s_new):
    print("Yes")
  else:
    print('No')
else:
  print("No")
def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

l = sorted(l, key = lambda x:(x[0],x[1]))

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

l = sorted(l, key = lambda x:x[2])

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

### FIXED CODE ###

N, M = map(int, input().split())
l = []
for i in range(M):
  	l.append(list(map(int, input().split())))

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

l = sorted(l, key = lambda x:(x[0],x[1]))

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 = l[i][0]

l = sorted(l, key = lambda x:x[2])

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))
while True :
 h,w = map(int, raw_input().split())
 if h+w == 0 : break
 for y in xrange(h):
 print ('#' * w)


### FIXED CODE ###

while True :
 h,w = map(int, raw_input().split())
 if h+w == 0 : break

 for y in xrange(h):
  print ('#' * w)
 print
l=[input() for i in range()]
print("YES" if l[0][0]==l[1][2] and l[0][1]==l[1][1] and l[0][2]==l[1][0] else "NO")

### FIXED CODE ###

l=[input() for i in range(2)]
print("YES" if l[0][0]==l[1][2] and l[0][1]==l[1][1] and l[0][2]==l[1][0] else "NO")
N,T=map(int,input().split())
res=1001

for _ in range(N):
	c,t=map(int,input().split())
	if t<=T:
		res=min(res,c)

if res=1001:
	print("TLE")
else:
	print(res)

### FIXED CODE ###

N,T=map(int,input().split())
res=1001

for _ in range(N):
	c,t=map(int,input().split())
	if t<=T:
		res=min(res,c)

if res==1001:
	print("TLE")
else:
	print(res)
n=int(input())
readints = lambda: list(map(int,input().split(' ')))
a=readints()
a.sort()
mid = n//2
x=a[mid]
y=a[mid+1]
print(y-x)

### FIXED CODE ###

n=int(input())
readints = lambda: map(int,input().split(' '))
a=list(readints())
a.sort()
mid = n//2
x=a[mid-1]
y=a[mid]
print(y-x)
import numpy as np
WH='.'
BK='#'
x=input()
x=x.split()
H=int(x[0])
W=int(x[1])
a=[[] for i in range(H)]
num=[]
numnum=0
for i in range(H):
    x=input()
    for j in range(W):
        a[i].append(x[j])
for i in range(H):
    flag=0
    for j in range(W):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==W:
        num.append(i)
        numnum=numnum+1
for i in range(numnum):
    a.pop(num[i])
H=H-numnum
a_n=np.array(a)
tr=a_n.T
num=[]
numnum=0
for i in range(W):
    flag=0
    for j in range(H):
        if tr[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==H:
        num.append(i)
        numnum=numnum+1
for i in range(numnum):
    a=np.delete(tr,num[i],0)
a=a.T
print(a)

### FIXED CODE ###

import numpy as np
WH='.'
BK='#'
x=input()
x=x.split()
H=int(x[0])
W=int(x[1])
a=[[] for i in range(H)]
num=[]
numnum=0
for i in range(H):
    x=input()
    for j in range(W):
        a[i].append(x[j])
for i in range(H):
    flag=0
    for j in range(W):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==W:
        num.append(i)
        numnum=numnum+1
for i in range(numnum):
    a.pop(num[i]-i)
H=H-numnum
a_n=np.array(a)
tr=a_n.T
a=tr.tolist()
num=[]
numnum=0
num_num=0
for i in range(W):
    flag=0
    for j in range(H):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==H:
        num.append(i)
        numnum=numnum+1
        flag=0
    else:
        flag=0
for i in range(numnum):
    a.pop(num[i]-i)
W=W-numnum
a_n=np.array(a)
a=a_n.T
for i in range(H):
    ans=''
    for j in range(W):
        ans=ans+a[i][j]
    print(ans)
def ismonth(month):
    return 0 < month < 13


S = input()

former = int(S[:2])
latter = int(S[2:])

if former < 1 or latter < 1:
    ans = "NA"

elif ismonth(former) and ismonth(latter):
    ans = "AMBIGUOUS"

elif ismonth(former):
    ans = "MMYY"

elif ismonth(latter):
    ans = "YYMM"

print(ans)


### FIXED CODE ###

from datetime import datetime

S = input()
former = int(S[:2])
latter = int(S[2:])
YYMM = False
MMYY = False

try:
    datetime(former + 2000, latter, 1)
    YYMM = True
except:
    pass

try:
    datetime(latter + 2000, former, 1)
    MMYY = True
except:
    pass

if YYMM and MMYY:
    print("AMBIGUOUS")
elif YYMM:
    print("YYMM")
elif MMYY:
    print("MMYY")
else:
    print("NA")
S = input()
slst = [[] for _ in range(len(S))]
tmp = '<'
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

ans = 0
for i in range(1, len(S), 2):
    if slst[i] == []:
        break
    tmp = ((slst[i][1]) * ((slst[i][1] - 1))) // 2
    ans += tmp
    if slst[i][1] >= slst[i - 1][1]:
        ans += tmp + 1
    else:
        ans += ((slst[i - 1][1] + 1) * ((slst[i - 1][1]))) // 2

print(ans)

### FIXED CODE ###

S = input()
slst = [[] for _ in range(len(S) + 1)]
tmp = S[0]
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

dp = [0] * (len(S) + 1)
if slst[0][0] == '<':
    dp[0] = 0
else:
    dp[0] = slst[0][1]

index = 1
for i in range(len(S)):
    if slst[i] == []:
        break

    if slst[i][0] == '>':
        dp[index] = dp[index - 1] + ((slst[i][1]) * ((slst[i][1] - 1))) // 2
        index += 1
    else:
        if slst[i + 1] == []:
            dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
            index += 1
        else:
            if slst[i][1] < slst[i + 1][1]:
                tdp = slst[i + 1][1]
                for k in range(1, slst[i][1]):
                    tdp += k
                dp[index] = dp[index - 1] + tdp
                index += 1

            else:
                dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
                index += 1


print(dp[index - 1])
s = list(input())
year = int(s[:4])
manth = int(s[5:7])
day = int(s[9:])
if year > 2019:
  print('TBD')
elif year < 2019:
  print('Heisei')
else:
  if month > 4:
    print('TBD')
  elif month < 4:
    print('Heisei')
  else:
    if day > 30:
      print('TBD')
    else:
      print('Heisei')

### FIXED CODE ###

s = input()
year = int(s[:4])
month = int(s[5:7])
day = int(s[9:])
if year > 2019:
  print('TBD')
elif year < 2019:
  print('Heisei')
else:
  if month > 4:
    print('TBD')
  elif month < 4:
    print('Heisei')
  else:
    if day > 30:
      print('TBD')
    else:
      print('Heisei')
alphabet = "abcdefghijklmnopqrstuvwxyz"
dictionary = {}
for character in alphabet:
    dictionary[character] = 0

for character in raw_input():
    if character.lowercase() in dictionary:
        dictionary[character.lowercase()] += 1

for character in alphabet:
    print(character + ' ' + dictionary[character])

### FIXED CODE ###

import sys
alphabet = "abcdefghijklmnopqrstuvwxyz"
dictionary = {}
for character in alphabet:
    dictionary[character] = 0

for line in sys.stdin:
    for character in line.strip():
        if character.lower() in dictionary:
            dictionary[character.lower()] += 1

for character in alphabet:
    print(character + ' : ' + str(dictionary[character]))