Harryxun/stf_run huggingface dataset:
def main():
    n,x,m=map(int,input().split())
    visited=[0]*m
    visit_sum=[0]*m
    i=1
    sm=x
    visited[x]=1
    visit_sum[x]=x
    work=x
    while i < n:
        work**=2
        work%=m
        sm+=work
        i+=1
#        print(sm,work)
        if not visited[work]:
            visited[work]=i
            visit_sum[work]=sm
        else :
            break
    else :
        print(sm)
        exit()
    loop_sum=sm-visit_sum[work]
    loop_num=i-visited[work]
    initial_sum=visit_sum[visited.index(visited[work]-1)]

    out=initial_sum
#    print(out)
    out+=(n-visited[work]+1)//loop_num*loop_sum
#    print(out)
    work_num=(n-visited[work]+1)%loop_num
    if work_num>0:
        out+=visit_sum[visited.index(visited[work]-1+work_num)]-initial_sum
    print(out)

main()

### FIXED CODE ###

def main():
    n,x,m=map(int,input().split())
    visited=[0]*m
    visit_sum=[0]*m
    i=1
    sm=x
    visited[x]=1
    visit_sum[x]=x
    work=x
    while i < n:
        work**=2
        work%=m
        sm+=work
        i+=1
#        print(sm,work)
        if not visited[work]:
            visited[work]=i
            visit_sum[work]=sm
        else :
            break
    else :
        print(sm)
        exit()
    loop_sum=sm-visit_sum[work]
    loop_num=i-visited[work]
    if visited[work]!=1: 
        initial_sum=visit_sum[visited.index(visited[work]-1)]
    else :
        initial_sum=0

    out=initial_sum
#    print(out)
    out+=(n-visited[work]+1)//loop_num*loop_sum
#    print(out)
    work_num=(n-visited[work]+1)%loop_num
    if work_num>0:
        out+=visit_sum[visited.index(visited[work]-1+work_num)]-initial_sum
        
    print(out)

main()
from function import gcd
n,x=map(int,input().split())
s=list(map(int,input().split()))
b=s[0]
t=abs(b-x)
for i in range(1,n):
    t=gcd(t,abs(s[i]-x))   
print(t)    

### FIXED CODE ###

from fractions import gcd 
n,x=map(int,input().split())
s=list(map(int,input().split()))
b=s[0]
t=abs(b-x)
for i in range(1,n):
    t=gcd(t,abs(s[i]-x))   
print(t)
from functools import lru_cache

MOD = pow(10, 9) + 7

H, W = map(int, input().split())
A = [input() for _ in range(H)]

@lru_cache(maxsize=H*W)
def calc(h, w):
    if h == H -1 and w == W -1:
        return 1
    count = 0
    # right
    if w + 1 < W  and A[h][w + 1] == ".":
        count += calc(h, w + 1)
        count %= MOD

    if h + 1 < H  and A[h + 1][w] == ".":
        count += calc(h + 1, w)
        count %= MOD

    return count % MOD


print(calc(0,0))


### FIXED CODE ###

from functools import lru_cache

MOD = pow(10, 9) + 7

H, W = map(int, input().split())
A = [input() for _ in range(H)]
dp = [ [0 for j in range(W + 1)] for i in range(H + 1)]

for w in range(1, W + 1):
    for h in range(1, H + 1):
        if w == 1 and h == 1:
            dp[1][1] = 1
            continue
 
        if A[h-1][w-1] == '.':
            dp[h][w] = (dp[h-1][w] + dp[h][w-1]) % MOD
            continue
        if A[h-1][w-1] == '#':
            dp[h][w]  = 0



print(dp[H][W])
n = int(input())
A = []
B = []
for _ in range(n):
    A[i], B[i] = map(int, input().split())

if n / 2 == 0:
    Am = (A[N / 2] + A[(N / 2) + 1]) / 2
    Bm = (B[N / 2] + B[(N / 2) + 1]) / 2
    print((Bm - Am) * 2 + 1)
else:
    Am = A[(N + 1) / 2]
    Bm = B[(N + 1) / 2]
    print(Bm - Am + 1)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())

am = np.median(A)
bm = np.median(B)

if N % 2 == 0:
    print(int((bm - am) * 2 + 1))
else:
    print(int((bm - am) + 1))
# cook your dish here
D,g = map(int,input().split())
p = []
c = []

for i in range(D):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)

#print(p)

d = [0]
cnt = 0

while d[-1] < g:
    while p[-1] == 0:
        p.pop(len(p)-1)
        c.pop(len(p)-1)
    k = -1
    
    r = d[-1] + (len(p))*100
    for i in range(len(p)):
        if len(d) >= p[i] and p[i] != 0:
            w = d[len(d)-p[i]] + 100*(i+1)*p[i] + c[i]
 #           print(p[i],i,c[i],len(d),w)
            if w > r:
                r = w
                k = i
    if k == -1:
        cnt += 1
        
    else:
        p[-1] += cnt
        p[k] = 0
        
    d.append(r)

#print(d)
print(len(d)-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline

d,g = map(int,input().split())
p = []
s = []
for i in range(d):
    x,y = map(int,input().split())
    p.append(x)
    s.append(100*(i+1)*x+y)

ans = 10**10
for i in range(1<<(d+1)):
    cnt = 0
    res = 0
    tank = []
    for j in range(d):
        if (i>>j)&1 == 1:
            cnt += s[j]
            res += p[j]
        else:
            tank.append([100*(j+1),p[j]])
    if cnt >= g:
        ans = min(ans,res)
    else:
        while cnt < g and tank[-1][1] > 0:
            cnt += tank[-1][0]
            tank[-1][1] -= 1
            res += 1
        if cnt >= g:
            ans = min(ans,res)
print(ans)
import math

input_nums = list(map(int, input().split()))
num1 = input_nums[0]
num2 = input_nums[1]

print(num1 * num2 // math.gcd(num1, num2))

### FIXED CODE ###

input_nums = list(map(int, input().split()))
num1 = input_nums[0]
num2 = input_nums[1]

def gcd(num1, num2):
    a = max(num1, num2)
    b = min(num1, num2)
    r = a%b
    while(r != 0):
        a = b
        b = r
        r = a%b
    return b
    

print(num1 * num2 // gcd(num1, num2))
a,b=map(str,input().split())
if int(a)<=int(b):
  s=a
  for _ in range(b-1):
    s+=a
  print (s)
else:
  s=b
  for _ in range(a-1):
    s+=b
  print(s)
  


### FIXED CODE ###

a,b=map(str,input().split())
if int(a)<=int(b):
  s=a
  for i in range(int(b)-1):
    s+=a
  print (s)
else:
  s=b
  for j in range(int(a)-1):
    s+=b
  print(s)
X=list(map(int, input()))
t=0
for i in range(len(X)):
  if X[i]==1:
    t+=300000
  elif X[i]==2:
    t+=200000
  elif X[i]==3:
    t+=100000
if X[0]==X[1] and X[0]==1:
  t+=400000
print(t)


### FIXED CODE ###

X=list(map(int, input().split()))
t=0
for i in range(len(X)):
  if X[i]==1:
    t+=300000
  elif X[i]==2:
    t+=200000
  elif X[i]==3:
    t+=100000
if X[0]==X[1] and X[0]==1:
  t+=400000
print(t)
def foo(x,y,z):
    return x*(x+y) + y*(y+z) + z*(z+x)

N = int(input())

F = [0 for i in range(N)]

for i in range(1,N//6+1):
    for j in range(1,N//6+1):
        for k in range(1,N//6+1):
            X = foo(i,j,k)
            F[X] += 1

for i in F:
    print(i)


### FIXED CODE ###

def foo(x,y,z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

N = int(input())

A = [0 for i in range(10050)]

for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            tmp = foo(i,j,k)
            if tmp < 10050:
                A[tmp] += 1

for i in range(1,N+1):
    print(A[i])
# 入力
N=int(input())
tl=list(map(int,input().split()))
M=int(input())

# 和
sm=sum(tl)

al=[]
for i in range(N):
  P,X=map(int,input().split())

  # 変更した場合の変化量を求める
  a=X-tl[P-1]

  # 解答を保存
  al.append(sm+a)

# 出力
for x in al:
  print(x)

### FIXED CODE ###

n=int(input())
t=list(map(int,input().split()))
m=int(input())
s=sum(t)
l=[]
for i in range(m):
  p,x=map(int,input().split())

  l.append(s-t[p-1]+x)
for i in l:
  print(i)
n,k=map(int,input().split())
s=list(input())
point=s[0]
count=1
while k!=0:
    if s[count]!=point:
        while True:
            if s[count]!=point:
                s[count]=point
                count +=1
            else:break
        k -=1
    else:count +=1

ans=0
for i in range(n-1,0,-1):
    if s[i]==s[i-1]:
        ans +=1
print(ans)

### FIXED CODE ###

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

s = input()

S = list(s)

num = 0
for i in range(N-1):

    if S[i] == S[i+1]:
        num += 1

print (min(N-1,num + 2*K))
N = int(input())
*H, = map(int, input().split())
st = [(0, -1)]
ans = 0
for i in range(N):
    h = H[i]
    base = i
    while h <= st[-1][0]:
        h0, j = st.pop()
        ans = max(ans, (i-j)*h0)
        base = j
    st.append((h, base))
while st:
    h0, j = st.pop()
    ans = max(ans, (N-j)*h0)
print(ans)

### FIXED CODE ###

N = int(input())
*H, = map(int, input().split())
st = [(0, -1)]
ans = 0
for i in range(N):
    h = H[i]
    base = i
    while st and h <= st[-1][0]:
        h0, j = st.pop()
        ans = max(ans, (i-j)*h0)
        base = j
    st.append((h, base))
while st:
    h0, j = st.pop()
    ans = max(ans, (N-j)*h0)
print(ans)
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = SS()
    K = I()

    ans = ''
    S_k = S[K]
    for i in S:
        if i == S_k:
            ans += i
        else:
            ans += '*'

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = SS()
    K = I()

    ans = ''
    S_k = S[K-1]
    for i in S:
        if i == S_k:
            ans += i
        else:
            ans += '*'

    print(ans)

if __name__ == '__main__':
    resolve()
N = int(input())

N_str = str(N)

N_length = len(N_str)
tmp_str = ""
ans = 0

if N_length%2 == 1:
  for i in range(len(N_str)-1):
    if i%2 == 0:
      tmp_str+="0"
    else:
      tmp_str+="9"
  if N_length-1 != 0:
    ans += N - (10 ** (N_length-1))
  else:
    ans += N
else:
  for i in range(len(N_str)-1):
    if i%2 == 0:
      tmp_str+="9"
    else:
      tmp_str+="0"

print(ans + int(tmp_str))


### FIXED CODE ###

N = int(input())

N_length = len(str(N))
ans = 0

for i in range(1,N+1):
  if len(str(i))%2 == 1:
    ans += 1

print(ans)
from heapq import heappush, heappop

N,M = map(int, input().split())
a = [int(i) for i in input().split()]

hq = heapq.heapify(a)

for i in range(N):
    heappush(hq, -a[i])

for i in range(M):
    tmp = -heappop(hq) // 2
    heappush(hq, -tmp)

print(-sum(hq)) 

### FIXED CODE ###

from heapq import heappush, heappop

N,M = map(int, input().split())
hq = []
a = [int(i) for i in input().split()]
for i in range(N):
    heappush(hq, -a[i])

for i in range(M):
    tmp = -heappop(hq) // 2
    heappush(hq, -tmp)

print(-sum(hq))
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ap,Az,Am=[],[],[]
for i in range(n):
  if A[i]>0:
    Ap.append(A[i])
  elif A[i]==0:
    Az.append(A[i])
  else:
    Am.append(-A[i])
Ap.sort()
Am.sort()
pp,mm=Ap.pop(),Am.pop()
heapq.heapify(Ap)
heapq.heapify(Am)
Ans=[]
while len(Am)>=1:
  am=heapq.heappop(Am)
  Ans.append([pp,-am])
  pp+=am
while len(Ap)>=1:
  ap=heapq.heappop(Ap)
  Ans.append([-mm,ap])
  mm+=ap
Ans.append([pp,-mm])
print(pp+mm)
for i in range(len(Ans)):
  print(*Ans[i])

### FIXED CODE ###

import heapq
n=int(input())
Ans=[]
A=[int(i) for i in input().split()]
A.sort()
if A[0]>=0:
  Ans=[]
  heapq.heapify(A)
  for i in range(n-2):
    a1=heapq.heappop(A)
    a2=heapq.heappop(A)
    Ans.append([a1,a2])
    heapq.heappush(A,a1-a2)
  a1=heapq.heappop(A)
  a2=heapq.heappop(A)
  Ans.append([a2,a1])
  print(a2-a1)
  for i in range(n-1):
    print(*Ans[i])

elif A[-1]<=0:
  Ans=[]
  AA=[]
  for i in range(n):
    AA.append(-A[i])
  heapq.heapify(AA)
  for i in range(n-2):
    a1=heapq.heappop(AA)
    a2=heapq.heappop(AA)
    Ans.append([-a1,-a2])
    heapq.heappush(AA,-(a2-a1))
  a1=heapq.heappop(AA)
  a2=heapq.heappop(AA)
  Ans.append([max(-a2,-a1),min(-a2,-a1)])
  print(max(-a2,-a1)-min(-a2,-a1))
  for i in range(n-1):
    print(*Ans[i])
else:    
  Ap,Az,Am=[],[],[]
  for i in range(n):
    if A[i]>0:
      Ap.append(A[i])
    elif A[i]==0:
      Az.append(A[i])
    else:
      Am.append(-A[i])
  Ap.sort()
  Am.sort()
  pp,mm=Ap.pop(),Am.pop()
  heapq.heapify(Ap)
  heapq.heapify(Am)

  while len(Am)>=1:
    am=heapq.heappop(Am)
    Ans.append([pp,-am])
    pp+=am
  while len(Ap)>=1:
    ap=heapq.heappop(Ap)
    Ans.append([-mm,ap])
    mm+=ap
  for i in range(len(Az)):
    Ans.append([pp,0])
  Ans.append([pp,-mm])
  print(pp+mm)
  for i in range(len(Ans)):
    print(*Ans[i])
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = [iss() for _ in range(N)]
    B = [iss() for _ in range(M)]

    for i in range(N):
        for j in range(N):
            for b in B:
                if A[i][j:] == b: i += 1
                else:break
            else:
                print('Yes')
                exit()
    else:
        print('No')




if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = [iss() for _ in range(N)]
    B = [iss() for _ in range(M)]

    for i in range(N - M + 1):
        for j in range(N - M + 1):
            t = i
            for b in B:
                # if t > M: break
                # if j + M > N: break
                if A[t][j:j+M] == b:
                    t += 1
                else:
                    break
            else:
                print('Yes')
                exit()
    else:
        print('No')


if __name__ == '__main__':
    main()
a=input()
b=input()
c=input()
if b-a==c-b:
  print "YES"
else:
  ptint"NO"

### FIXED CODE ###

a,b,c=map(int,raw_input().split())
if b-a==c-b:
  print "YES"
else:
  print"NO"
#!/usr/bin/env python3
import sys
import collections
import itertools
 
def main():
    input = sys.stdin.readline
    h, w = map(int, input().split())
    ch, cw = map(lambda x:int(x) - 1, input().split())
    dh, dw = map(lambda x:int(x) - 1, input().split())
    s = [list(input().rstrip()) for _ in range(h)]
    
    que = collections.deque()
    que.append((ch, cw))
    cost = [[float("INF")] * w for _ in range(h)]
    cost[ch][cw] = 0
    
    while que:
        py, px = que.popleft()
        for dy, dx in itertools.product(range(-2, 3), repeat = 2):
            ny, nx = py + dy, px + dx
            if 0 <= ny < h and 0 <= nx < w and s[ny][nx] == ".":
                if dy == dx == 0:
                    continue
                if (dy, dx) in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
                    if cost[ny][nx] > cost[py][px]:
                        cost[ny][nx] = cost[py][px]
                        que.appendleft((ny, nx))
                else:
                    if cost[ny][nx] > cost[py][px] + 1:
                        cost[ny][nx] = cost[py][px] + 1
                        que.append((ny, nx))
                        
    if cost[dh][dw] == float("INF"):
        print(-1)
    else:
        print(cost[dh][dw])
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

N, X, T = [int(i) for i in input().split()]
tmp = N // X
if N%X > 0:
    tmp += 1
print(tmp * T)
import sys
import os

def file_input():
    f = open('/input.txt', 'r')
    sys.stdin = f

def main():
    # file_input()
    # int(input())
    A,B,C,K=int(map(int, input().split()))

    sum=0
    for i in K:
        if A!=0:
            A-=1
            sum+=1
        elif B!=0:
            B-=1
        elif C!=0:
            C-=1
            sum-=1
    print(sum)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    A,B,C,K=map(int, input().split())

    sum=0
    if K>A:
        sum+=A
        K-=A
        if K>B:
            K-=B
            sum-=K        
    else:
        sum+=K

    print(sum)

if __name__ == '__main__':
    main()
"""
https://abc065.contest.atcoder.jp/tasks/abc065_b
"""
n=int(input())
a="S"
for i in range(n):
    a=a+input()
#print(a)
t=1
c=0
for i in range(n):
    t=int(a[t])
    c=c+1
    if t==2:
        print(c)
        break
if t!=2:
    print(-1)


### FIXED CODE ###

n = int(input())
a = {}
for i in range(n):
  a[i+1] = int(input())

p = 1
ok = 0

for i in range(n):
  p = a[p]
  if p == 2:
    ok = 1
    break

if ok == 1:
  print(i+1)
else:
  print(-1)
n, k = map(int, input().split(" "))
ab = [tuple(map(int, input().split(" "))) for i in range(n)]

d = dict()
for ab_i in ab:
	a, b = ab_i
	if a not in d:
		d[a] = 0
	d[a] += b

print(sum([[d_a] * d_b for d_a, d_b in sorted(d.items())], [])[k-1])

### FIXED CODE ###

n, k = map(int, input().split(" "))
ab = [tuple(map(int, input().split(" "))) for i in range(n)]

count = 0
for ab_num, ab_count in sorted(ab):
	count += ab_count
	if k <= count:
		print(ab_num)
		exit()
import sys

ary=[]
ans=[]
def solve(a,b,c,d,e,f):
    x=round((c-b*f/e)/(a-b*d/e),3)
    y=round((c-a*f/d)/(b-a*e/d),3)
    return [x,y]

for i in sys.stdin:
    ary.append(list(map(int,i.split())))
    ans.append(solve(*ary[-1]))

for i in range(len(ans)):
    print('{0:.3f} {1:.3f}'.format(*ans[i]))

### FIXED CODE ###

import sys

ary=[]
ans=[]
def solve(a,b,c,d,e,f):
    if c*e-b*f==0:
        x=0
    else:
        x=(c*e-b*f)/(a*e-b*d)
    if c*d-a*f==0:
        y=0
    else:
        y=(c*d-a*f)/(b*d-a*e)
    return [x,y]

for i in sys.stdin:
    ary.append(list(map(int,i.split())))
    ans.append(solve(*ary[-1]))

for i in range(len(ans)):
    print('{0:.3f} {1:.3f}'.format(round(ans[i][0],3),round(ans[i][1],3)))
N = int(input())
S = input()
K = int(input())
a = list(S)
for i in range(0, N):
    if a[i] != a[K-1]:
        a[i] = "*"
        b = "".join(a)
print(b)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
a = list(S)
for i in range(0, N):
    if a[i] != a[K-1]:
        a[i] = "*"
b = "".join(a)
print(b)
def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

n, x = map(int, input().split())
town = map(int, input().split())

distance = (abs(x-y) for y in town)
print(distance)
for d in distance:
    res = gcd(next(d), next(d))

print(res)


### FIXED CODE ###

from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)
N = int(input())
ans = 0
for i in range(1, N + 1):
	if len(str(i)) % 2 == 1:
	ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N + 1):
	if len(str(i)) % 2 == 1:
		ans += 1
print(ans)
i = 0
def printcase(n):
    i = i + 1
    print("Case ", i, n)

if __name__ == "__main__":
    ret = printcase(input())


### FIXED CODE ###

def printcase():
    i = 1
    n = int(input())
    while n != 0:
        print("Case %d: %d" %(i ,n))
        n = int(input())
        i = i + 1
    return 0

if __name__ == "__main__":
    ret = printcase()
date=input()
yr=slice(int[0:4])
mn=slice(int[5:7])
dy=slice(int[8:10])
if yr <2019:
  print("Heisei")
elif yr >2019:
  print("TBD")
else:
  if mn<4:
    print("Heisei")
  elif mn>4:
    print("TBD")
  else:
    print("Heisei")

### FIXED CODE ###

yr,mn,dy=map(int,input().split('/'))
if yr <2019:
  print("Heisei")
elif yr >2019:
  print("TBD")
else:
  if mn<4:
    print("Heisei")
  elif mn>4:
    print("TBD")
  else:
    print("Heisei")
def add_edge(node, adj_lst, adj_rev, s1, s2):
  ind = 0
  max_len = min(len(s1), len(s2))
  while ind < max_len and s1[ind] == s2[ind]:
    ind += 1
  if ind == max_len:
    if max_len < len(s1):
      return True
    return False
  c1 = ord(s1[ind]) - ord("a")
  c2 = ord(s2[ind]) - ord("a")
  adj_lst[c1].add(c2)
  adj_rev[c2].add(c1)
  node.add(c1)
  node.add(c2)
  return False
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    
    lst = [input() for _ in range(n)]
    node = set()
    adj_lst = [set() for _ in range(26)]
    adj_rev = [set() for _ in range(26)]
    blank_flag = False
    for i in range(n):
      for j in range(i + 1, n):
        blank_flag = blank_flag or add_edge(node, adj_lst, adj_rev, lst[i], lst[j])
    
    L = []
    visited = [False] * 26
    cycle_flag = False
  
    def visit(n):
      global cycle_flag
      if cycle_flag: return
      if visited[n] == 2:
        cycle_flag = True
      elif visited[n] == 0:
        visited[n] = 2
        for to in adj_lst[n]:
          visit(to)
        visited[n] = 1
        L.append(n)
    
    L = []
    for n in node:
      visit(n)
    if cycle_flag or blank_flag:
      print("no")
    else:
      print("yes")

main()


### FIXED CODE ###

def add_edge(node, adj_lst, s1, s2):
  ind = 0
  max_len = min(len(s1), len(s2))
  while ind < max_len and s1[ind] == s2[ind]:
    ind += 1
  if ind == max_len:
    return max_len < len(s1)

  c1 = ord(s1[ind]) - ord("a")
  c2 = ord(s2[ind]) - ord("a")
  adj_lst[c1].add(c2)
  node.add(c1)
  node.add(c2)
  return False

def visit(n, visited, adj_lst):
  ret = False
  if visited[n] == 2:
    return True
  elif visited[n] == 0:
    visited[n] = 2
    for to in adj_lst[n]:
      ret = ret or visit(to, visited, adj_lst)
    visited[n] = 1
  return ret
 
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    
    lst = [input() for _ in range(n)]
    node = set()
    adj_lst = [set() for _ in range(26)]
    blank_flag = False
    for i in range(n):
      for j in range(i + 1, n):
        blank_flag = blank_flag or add_edge(node, adj_lst, lst[i], lst[j])
    if blank_flag:
      print("no")
      continue
    
    visited = [0] * 26
    cycle_flag = False
  
    for n in node:
      cycle_flag = cycle_flag or visit(n, visited, adj_lst)
    if cycle_flag:
      print("no")
    else:
      print("yes")

main()
print(a*b,2*a+2*b)

### FIXED CODE ###

ab = input()
num_ab = ab.split()
a = int(num_ab[0])
b = int(num_ab[1])
print(a*b,2*(a+b))
n = int(input())
a,t = map(int,input().split())
s = 0
t = 1
for i in range(1,n+1):
    h = int(input())
    if a-t-h*0.006 <= s:
        t = i 
print(i)   

### FIXED CODE ###

n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
s = []

for i in h:
    s.append(abs(t-i*0.006-a))

print(s.index(min(s))+1)
N = int(input())
S = input()
print(max(len(set(S[:i])&set(S[i:])) for i in range(N))

### FIXED CODE ###

N = int(input())
S = list(input())
s = set(S)
count = 0
maxx = 0
for i in range(N): #切断場所
    for k in range(i):
        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
            count += 1
    maxx = max(maxx, count)
    count = 0
print(maxx)