peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 5] * (n)
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
        else:
            break
print(dp[n-1])
# Judge status: Accepted
# -*- coding: utf-8 -*-

A = int(input()) # 500円
B = int(input()) # 100円
C = int(input()) # 50円
X = int(input()) # 金額

ans = 0
tmp_x = 0

for i in range(0, A + 1):
    for j in range(0, B + 1):
        for k in range(0, C + 1):
            tmp_x = (500 * i) + (100 * j) + (50 * k)
            if X == tmp_x:
                ans += 1

print(ans)
# Judge status: Accepted
S=list(map(str,input().split()))
print(S[0][0],end="")
print(S[1][0],end="")
print(S[2][0])
# Judge status: Accepted
N, K = map(int, input().split())
S = input()
K -= 1
answer = S[:K] + S[K].lower() + S[K+1:]
print(answer)
# Judge status: Accepted
n = int(input())
aa = list(map(int, input().split()))
aa.sort()

a = aa[n//2-1]
b = aa[n//2]
print(b-a)
# Judge status: Wrong Answer
s = input()

while True:
  if len(s) == 0:
    print("YES")
    break
  elif len(s) < 5:
    print("NO")
    break
  else:
    if s[:5] == "dream":
      s = s.replace("dream", "", 1)
    elif s[:5] == "erase":
      s = s.replace("erase", "", 1)
    elif s[:7] == "dreamer" :
      s = s.replace("dreamer", "", 1)
    elif s[:6] == "eraser":
      s = s.replace("eraser", "", 1)
    else:
      print("NO")
      break
# Judge status: Accepted
n = int(input())
a_list = list(map(int, input().split()))
counts = {}
for a in a_list:
	if a in counts:
		counts[a] += 1
	else:
		counts[a] = 1
counts = sorted(counts.items(), reverse=True, key=lambda x: x[0])
a = 0
b = 0
for key, value in counts:
	if value > 1:
		if a == 0:
			a = key
			if value > 3:
				b = key
				break
		else:
			b = key
			break
r = a*b
print(r)
# Judge status: Wrong Answer
N,K=map(int,input().split())

print(abs(N%K))
# Judge status: Wrong Answer
N = int(input())

if (N <= 3):
    ans = 'No'
else:
    mod_4 = N % 4
    mod_7 = N % 7
    
    if (mod_4 == 0 or mod_7 == 0 or mod_7 == 4):
        ans = 'Yes'
    else:
        ans = 'No'

print(ans)
# Judge status: Wrong Answer
w,a,b=map(int,input().split())
if (w+a)<b:
  print(b-w-a)
else:
  print(0)
# Judge status: Wrong Answer
S = input()
T = input()

s = len(S)
t = len(T)

ans = 10**10
for i in range(s-t):
    mm = 0
    for j in range(t):
        if S[i+j]!=T[j]:
            mm += 1
    ans = min(ans,mm)
print(ans)
# Judge status: Wrong Answer
N = int(input())
d = list(map(int, input().split()))
d.sort()
S = sum(d)
if not d[N//2 - 1] <= S/N <= d[N//2]:
  print(0)
else:
  A = 0
  for i in range(d[N//2]-d[N//2 - 1]):
    if d[N//2 - 1] < d[N//2 - 1] + i+1 <= d[N//2]:
      A += 1  
  print(A)
# Judge status: Accepted
N = int(input())

char = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def search(arr):
  global N, char
  if len(arr) == N:
    ans = ''.join([char[x] for x in arr])
    print(ans)
    return
  else:
    for i in range(max(arr) + 2):
      arr_next = arr + [i]
      search(arr_next)

search([0])
# Judge status: Accepted
N = int(input())
meal = list(map(int, input().split()))
satis = list(map(int, input().split()))
adds = list(map(int, input().split()))
total = sum(satis)

for i in range(N-1):
    if (meal[i]+1 == meal[i+1]):
        total += adds[meal[i]-1]

print(total)
# Judge status: Wrong Answer
import sys
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(1,n):
  a[i] += a[i-1]
for i in range(1,m):
  b[i] += b[i-1]
    
ans = 0
for i in range(n, 0, -1):
  p = 0
  q = 0
  if a[i-1] <= k:
    p = a[i-1]
    q = i
  for j in range(m, 0, -1):
    if p + b[j-1] <= k:
      ans = max(ans, q + j)
    
print(ans)
# Judge status: Wrong Answer
a, b = map(int, input().split())
x = a + b
if x % 3 == 0:
  print('Possible')
else:
  print('Impossidle')
# Judge status: Wrong Answer
sx, sy, tx, ty = map(int, input().split())

dx = tx -sx
dy = ty -sy

if dx >= 0:
    mx = ["R", "L"]
else:
    mx = ["L", "R"]
    dx = -dx

if dy >= 0:
    my = ["U", "D"]
else:
    mx = ["D", "U"]
    dy = -dy

ans = mx[0]*dx + my[0]*dy
ans = ans + mx[1]*dx + my[1]*dy
ans = ans + my[1] + mx[0]*(dx + 1) + my[0]*(dy + 1) + mx[1]
ans = ans + my[0] + mx[1]*(dx + 1) + my[1]*(dx + 1) + mx[0]

print(ans)
# Judge status: Accepted
N, R= map(int, input().split())
if N>=10:
    print(R)
else:
    print(R+100*(10-N))
# Judge status: Wrong Answer
s = str(input())
int(s[0]) + int(s[1]) + int(s[2])
# Judge status: Accepted
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    x, y, a, b, c = list(map(int, input().strip().split()))
    p = sorted(list(map(int, input().strip().split())), reverse=True)
    q = sorted(list(map(int, input().strip().split())), reverse=True)
    r = sorted(list(map(int, input().strip().split())), reverse=True)
    print(sum(sorted((p[:x]+q[:y]+r), reverse=True)[:x+y]))

if __name__ == '__main__':
    main()
# Judge status: Accepted
s = list(input())
t = list(input())

if sorted(s) != sorted(t):
  print("No")
  exit(0)
else:
  for i in range(len(s)+1):
    if s == t:
      print("Yes")
      exit(0) 
    
    s.insert(0,s.pop())

print("No")
# Judge status: Wrong Answer
import sys
from math import ceil
input = sys.stdin.readline
n, h = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    aa, bb = map(int, input().split())
    a[i], b[i] = aa, bb
a_max = max(a)
b_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
ans += ceil(h/a_max)
print(ans)
# Judge status: Accepted
N,K = map(int,input().split())
D = set(map(int,input().split()))
while True:
    for i in map(int,set(str(N))):
        if i in D:
            break
    else:
        print(N)
        exit()
    N += 1
# Judge status: Accepted
import itertools

def main():
  d,t,s = list(map(int,(input().split())))
  s1 = d / t    
  if s1 <= s:
    print('Yes')
  else:
    print('No')
      
  
  
  
  
if __name__ == '__main__':
  main()
# Judge status: Accepted
N = int(input())
ABC = [tuple(map(int, input().split())) for _ in range(N)]
dp_a = [0] * (N+1)
dp_b = [0] * (N+1)
dp_c = [0] * (N+1)

for i, (a, b, c) in enumerate(ABC):
  dp_a[i+1] = a + max(dp_b[i], dp_c[i])
  dp_b[i+1] = b + max(dp_a[i], dp_c[i])
  dp_c[i+1] = c + max(dp_a[i], dp_b[i])
print(max(dp_a[N], dp_b[N], dp_c[N]))
# Judge status: Accepted
a, b, c = map(int,input().split())
if b >= a*c:
  print(c)
else:
  print(b//a)
# Judge status: Accepted
N,M=map(int,input().split())
S=[]
for i in range(N):
  a,b=map(int,input().split())
  S.append((a,b))
P=[]
for i in range(M):
  c,d=map(int,input().split())
  P.append((c,d)) 
for i in range(N):
  D=10**9
  ans=0
  for j in range(M-1,-1,-1):
    if D>=(abs(S[i][0]-P[j][0])+abs(S[i][1]-P[j][1])):
      D=(abs(S[i][0]-P[j][0])+abs(S[i][1]-P[j][1]))
      ans=j
  print(ans+1)
# Judge status: Wrong Answer
n, m = map(int,input().split())
a = [None]*n
b = [None]*m
for i in range(n):
  a[i] = input()
for j in range(m):
  b[j] = input()
r = 'No'
for i in range(n - m):
  end_yoko = i + m + 1
  a_t = [s[i:end_yoko] for s in a]
  for j in range(n - m):
    end_tate = j + m + 1
    if a_t[j:end_tate] == b:
      r = 'Yes'
print(r)
# Judge status: Accepted
s = input()
if s.count("9") > 0:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
S = input()
l = len(S)
c = 0
for i in range(l):
  if S[i] != S[l-1-i]:
    c += 1
print(c//2)
# Judge status: Wrong Answer
a, b, k = map(int, input().split())
ans = [min(a,b)]
for i in range(1, max(a, b)):
    if a % i == 0 and b % i == 0:
        ans.append(i)
ans.sort(reverse=True)
print(ans[k-1])
# Judge status: Wrong Answer
N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(1, N):
  if P[i-1] == i:
    tmp = P[i-1]
    P[i-1] = P[i]
    P[i] = tmp
    cnt += 1
print(cnt)
# Judge status: Wrong Answer
N = int(input())
d = list(map(int, input().split()))
d.sort()
S = sum(d)
if not d[N//2 - 1] < S/N <= d[N//2]:
  print(0)
else:
  A = 0
  for i in range(d[N//2]-d[N//2 - 1]):
    if d[N//2 - 1] < d[N//2 - 1] + i+1 <= d[N//2]:
      A += 1  
  print(A)
# Judge status: Wrong Answer
N,X = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
for i in range(1,N):
    if X < a[i]+a[i-1]:
        ans += a[i]+a[i-1]-X
        a[i] = X-a[i-1] if X <= a[i] else 0
print(ans)
# Judge status: Accepted
s=input()
p=[]
p.append(r'^keyence$')
p.append(r'(\D+)keyence$')
p.append(r'^k(\D+)eyence$')
p.append(r'^ke(\D+)yence$')
p.append(r'^key(\D+)ence$')
p.append(r'^keye(\D+)nce$')
p.append(r'^keyen(\D+)ce$')
p.append(r'^keyenc(\D+)e$')
p.append(r'^keyence(\D+)')
ans='NO'
import re
for pi in p:
    m=re.search(pi,s)
    if m and m.start()>-1:
        ans='YES'
        break
print(ans)
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[17]:


abcde = []
for _ in range(5):
    abcde.append(int(input()))
print(sum(-(-x//10)*10 for x in abcde) + min(x%10 if x%10 != 0 else 10 for x in abcde ) - 10)


# In[ ]:
# Judge status: Accepted
N,M=map(int,input().split())
*A,=map(int,input().split())
A=sorted(A)

while M:
    A[-1]//=2
    M-=1
    i=-2
    while M and (-N<=i and A[i]>=A[-1]):
        A[i]//=2
        M-=1
        i-=1
    A.sort()

print(sum(A))
# Judge status: Wrong Answer
def main():
  n=int(input())
  a=list(map(int,input().split()))
  dp=[0]*2
  for i in range(n):
    dp2=[max(dp[0]+a[i],dp[1]-a[i]),max(dp[0]-a[i],dp[1]+a[i])]
    dp=dp2
  print(max(dp))
main()
# Judge status: Accepted
x=[0,0,0]
for i in range(3):
    x[i]=list(map(int, input().split()))
    
l=abs(x[0][0]-x[1][0])
v=x[0][1]-x[1][1]
if l>v*x[2][0]:
    print('NO')
else:
    print('YES')
# Judge status: Accepted
from heapq import *
N,M = map(int,input().split())
L = [[] for m in range(M)]
H = []
ans = 0

for n in range(N):
  a,b = map(int,input().split())
  if a<=M:
    L[M-a]+=[b]
    
for m in range(M-1,-1,-1):
  for l in L[m][::-1]:
    heappush(H,-l)
  if 0<len(H):
    ans-=heappop(H)

print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

for a in A:
  if a % 2 == 0:
    if a % 3 != 0 and a % 5 != 0:
      print("DENIED")
      exit()
print("APPROVED")
# Judge status: Wrong Answer
a, b, x = map(int, input().split())

print(b // x - a // x + (1 if (a % x == 0) or (b % x == 0) else 0))
# Judge status: Accepted
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l, x+l
    if s >= right:
        right = t
        ans += 1
print(ans)
# Judge status: Wrong Answer


s = input()


if int(s[:2]) <= 12 or int(s[2:]) <= 12:
    if int(s[:2]) <= 12 and int(s[2:]) <= 12:
        print('AMBIGUOUS')
    elif 0 < int(s[:2]) <= 12:
        print('MMYY')
    elif 0 < int(s[2:]) <= 12:
        print('YYMM')
    else:
        print('NA')
else:
    print('NA')
# Judge status: Accepted
s = input()

for i in range(1,len(s)+1):
    if i % 2 == 1 and s[i-1] == 'L':
        print('No')
        exit()
    if i % 2 == 0 and s[i-1] == 'R':
        print('No')
        exit()
print('Yes')
# Judge status: Wrong Answer
from fractions import gcd
a,b,c,d=map(int,input().split())
cnt1,cnt2=0,0
cnt1=(a-1)//c+(a-1)//d-((a-1)*gcd(c,d))//(c*d)
cnt2=b//c+b//d-(b*gcd(c,d))//(c*d)
print(cnt2-cnt1)
# Judge status: Wrong Answer
N = int(input())

coin = [1, 6, 9, 6**2, 9**2, 6**3, 9**3, 6**4, 9**4, 6**5]
#try DP with
count = [N]*(N+1)

count[0] = 0
for c in range(len(coin)):
    for i in range(N-coin[c] + 1):
        if count[i + coin[c]] > count[i] + 1:
            count[i + coin[c]] = count[i] + 1

print(count[N])
# Judge status: Accepted
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
for i in range(n):
  ans += bisect.bisect_left(a, b[i]) * (n - bisect.bisect_right(c, b[i]))
print(ans)
# Judge status: Accepted
import itertools
import bisect

N = int(input())
LS = list(map(int,input().split()))
LS.sort()

ans = 0

for a,b in itertools.combinations(LS,2):
  a,b = min(a,b),max(a,b)
  lo = b - a
  up = a + b
  
  cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 1
  if lo < a:
    cnt -= 1
    
  if cnt <= 0:
    continue
    
  ans += cnt
  
print(ans // 3)
# Judge status: Wrong Answer
#!/usr/bin/env python

n = int(input())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
    a[i], b[i] = map(int, input().split())

ans = 0 

for i in reversed(range(n)):
    if a[i]%b[i] == 0:
        continue
    else:
        ans += (a[i]//b[i]+1)*b[i]-a[i]
        a[i-1] += ans 

print(ans)
# Judge status: Wrong Answer
a=int(input())
x=1
for i in range(1,a+1):
    x *= i %(10**9+7) 
print(x)
# Judge status: Wrong Answer
N =int(input())
A =int(input())
a = N%500
if a<A:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
a,b,c,d = map(int,input().split())

print(max(a*d,a*c,b*c,b*d))
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = list(map(int, input().split()))

length = len(a)
res = [1] * length
for i in range(n-k-1, n):
    for j in range(k):
        if i-k+1 < 0:
            break
        res[i] *= a[i-j]

for i in range(n-k-1, -1, -1):
    if res[n-i-1] > res[n-i-2]:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
a, b = (int(x) for x in input().split())
a1 = str(a)*b
b1 = str(b)*a
lis = [a1, b1]
new_lis = sorted(lis)
print(new_lis[0])
# Judge status: Accepted
def main():
    x = int(input())
    ans = "NO"
    if (x == 7 or x == 5 or x == 3):
        ans = "YES"

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = int(input())
a = []
for _ in range(2):
    a.append(list(map(int, input().split(" "))))

res = 0
for i in range(n):
    res += a[0][i]

    if i + 1 == n:
        res += a[1][i]
        break

    sum_row_1 = sum(a[0][i + 1:n])
    sum_row_2 = sum(a[1][i + 1:n])
    if sum_row_1 <= sum_row_2:
        res += sum(a[1][i:n])
        break

print(res)
# Judge status: Accepted
N = int(input())
if N%2==0: print(int(N/2))
else: print(int(N/2)+1)
# Judge status: Wrong Answer
n,d=map(int,input().split())
a=d*2+1
print(-(n//-d))
# Judge status: Accepted
H, N = map(int, input().split())

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

DP = [0] + [10**9]*H

for h in range(H):
  for damage, mp in magic:
    DP[min(h + damage, H)] = min(DP[min(h + damage, H)], DP[h] + mp)
print(DP[H])
# Judge status: Accepted
n = int(input())
list_a = [int(input()) for _ in range(n)]

ans = -1
num = 1
cnt = 0
for _ in range(n):
    num = list_a[num-1]
    cnt += 1
    if num == 2:
        ans = cnt
        break
    if cnt == n+1:
        break

print(ans)
# Judge status: Wrong Answer
def main():
    a,b,t = map(int,input().split())
    ans = 0
    for i in range(t + 1, 1):
        if i % a == 0:
            ans += b
    print(ans)
main()
# Judge status: Accepted
N=int(input())
*A,=map(int,input().split())
t=sum(A)

x=0
ans=float('inf')
for i in range(N-1):
    x+=A[i]
    ans=min(ans, abs(2*x-t))
print(ans)
# Judge status: Accepted
s=input()
l=len(s)
a=0
z=0
for i in range(l):
  if s[i]=="A":
    a=i
    break
for i in range(l):
  if s[i]=="Z":
    z=i
print(z-a+1)
# Judge status: Accepted
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans=float("inf")

for i in range(N-K+1):
    if i + K == N+1:
        break
    else:
        a = min(abs(x[K+i-1]),abs(x[i])) 
        ans = min(ans,x[K+i-1]-x[i]+a)
print(ans)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))

x2=0
x4=0
x1=0
for x in a:
  if x%2==0:
    x2+=1
  if x%4==0:
    x4+=1
  if x%2==1:
    x1+=1
    
if x4>=x1:
  print('Yes')
  
else:
  print('No')
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

p = 0
for i in range(1, N):
    p ^= A[i]

ans = [str(p)]
for i in range(1, N):
    t = A[i-1] ^ A[i]
    p = p ^ t
    ans.append(str(p))
print(" ".join(ans))
# Judge status: Accepted
n ,T = map(int, input().split())

c = [0] * n
t = [0] * n

for i in range(n):
    c[i], t[i] = map(int, input().split())

arr = []
for i in range(n):
    if t[i] <= T:
        arr.append(c[i])

if len(arr) == 0:
    print('TLE')
else:
    print(min(arr))
# Judge status: Wrong Answer
user_input = list(map(int, input().split()))
# print(user_input)
# to find the index where zero is located
indexOfZero = [x for x in range(0, 5) if user_input[x] == 0]
print(indexOfZero[0])
# Judge status: Accepted
a, b, c, d = map(int, input().split())
print("Yes" if abs(a - c) <= d or abs(a - b) <= d and abs(b - c) <= d else "No")
# Judge status: Accepted
a, b = map(str, input().split())
if a > b:
    print(b*int(a))
else:
    print(a*int(b))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    print(A.count(A[i])-1)
# Judge status: Accepted
print("Yes" if "".join(sorted(input())) < "".join(sorted(input()))[::-1] else "No")
# Judge status: Accepted
import sys
readline = sys.stdin.readline

N = int(readline())
D = list(map(int,readline().split()))

counts = [0] * (max(D) + 1)

from collections import Counter
counter = Counter(D)

for k,v in counter.items():
  counts[k] = v

if D[0] != 0 or counts[0] != 1:
  print(0)
  exit(0)
  
ans = 1
DIV = 998244353
for i in range(1, len(counts)):
  ans *= pow(counts[i - 1],counts[i],DIV)
  ans %= DIV

print(ans)
# Judge status: Wrong Answer
N = int(input())
xy=[]
try :
  while True:
    t = input().split()
    t = list(map(int,t))
    xy.append(t)
except EOFError:
  pass
loc = [0,0]
time = 0
for i in range(N):
  a = xy[i]
  time = a[0]-time
  dis = abs(loc[0]-a[1])+abs(loc[1]-a[2])
  if (time-dis)<0 :
    print("No")
    break
  elif (time-dis)%2 == 0:
    loc = [a[1],a[2]]
    
  else :
    print("No")
    break
else :
  print("Yes")
# Judge status: Accepted
import io
import sys
import math

def solve():
    A, B, H, M = list(map(int, input().split()))
    C_sq = A**2 + B**2 - 2*A*B*math.cos((H - 11/60 * M)*math.pi/6)
    C = math.sqrt(C_sq)
    print(C) 


if __name__ == "__main__":
    solve()
# Judge status: Accepted
N = int(input())
print("%.10f"%(((N+1)//2)/N))
# Judge status: Wrong Answer
n = int(input())
s = []
for i in range(n):
  if not i%3==0 and i%5==0:
       s.append(i)
print(sum(s))
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
chk = []
for i in range(n):
  a,b =  map(int,input().split())
  if a <= m:
    chk.append((a,b))
    
from operator import itemgetter
chk = sorted(chk,key=itemgetter(0),reverse=True)
chk = sorted(chk,key=itemgetter(1),reverse=True)
from collections import Counter
c = Counter()
s = 0
ss = m
ans = 0
for nn,i in enumerate(chk):
  if s == m:
    break
  a,b = i
  if c[a] <= m-a and ss >= a:
    ans += b
    c.update({a:1})
    s += 1
    ss -= a
    ss += m-1-nn
    
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
first = 0
for i in range(N):
    m = max(first,A[i])
    if A[i] < first-1:
        print("No")
        exit()

print("Yes")
# Judge status: Accepted
N = int(input())
V = list(map(int, input().split()))
while len(V) > 1:
	V = sorted(V)
	temp = (V.pop(0) + V.pop(0)) / 2
	V.append(temp)
	
print(V[0])
# Judge status: Accepted
n = int(input())
x = list(map(int, input().split()))

y = sorted(x)
a = y[len(x)//2]
b = y[(len(x)//2) - 1]

for i in range(n):
    if x[i] <= b:
        print(a)
    else:
        print(b)
# Judge status: Accepted
# https://atcoder.jp/contests/agc005/tasks/agc005_a
#
# Stackでやる

from collections import deque

stack = deque([])
X = input()

for ch in X:
    if ch == 'S':
        stack.append(ch)
    elif ch == 'T':
        if len(stack) == 0:
            stack.append(ch)
        elif stack[-1] == 'T':
            stack.append(ch)
        elif stack[-1] == 'S':
            stack.pop()

print(len(stack))
# Judge status: Accepted
a, b, c = map(int, input().split())
if a < c < b:
    print("Yes")
elif a > c > b:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n=int(input())
p=1000
a=list(map(int,input().split()))
for i in range(n-1):
    if a[i]<a[i+1]:
        p=p+(a[i+1]-a[i])*(p//a[i])
print(p)
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()

if S[K-1] == 'A': rep = 'a'
elif S[K-1] == 'B': rep = 'b'
else: rep = 'c'
  
print(S[:K] + rep + S[K+1:])
# Judge status: Accepted
def LI():
    return list(map(int, input().split()))


N = LI()
N.sort()
A, B, C = N
a = (C-A)//2
A += a*2
b = (C-B)//2
B += b*2
if A == B == C:
    ans = a+b
elif A == B:
    ans = a+b+1
else:
    ans = a+b+2
print(ans)
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def kawaisou(a, b, c):
    if a == b and a != c:
        return True
    if a == c and a != b:
        return True
    if b == c and a != b:
        return True
    return False

def main():
    a, b, c = rli()
    if kawaisou(a, b, c):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
s = input()

first = s[:int(n / 2)]
last = s[int(n / 2):]

if n % 2 != 0:
    print('No')
elif first != last:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
S, T = input().split()
A, B = map(int, input().split())
U = input()

if (U == S):
    print(A - 1, B)
else:
    print(A, B - 1)
# Judge status: Accepted
n,m = map(int, input().split())
A = [None]*n
for i in range(n):
    A[i] = list(input())
B = [None]*m
for i in range(m):
    B[i] = list(input())

def solve(i,j):
    for k in range(m):
        for l in range(m):
            if A[i+k][j+l] != B[k][l]:
                return False
    return True # match

for i in range(n-m+1):
    for j in range(n-m+1):
        if solve(i,j):
            print("Yes")
            exit()
print("No")
# Judge status: Wrong Answer
A,B = map(int,input().split())
print(2*max(A,B))
# Judge status: Accepted
from collections import defaultdict
def main():
    n = int(input())
    s =defaultdict(lambda:0)
    for i in range(n):
        s[input()] += 1
    max_s = max(s.values())
    for key, value in sorted(s.items()):
        if value == max_s:
            print(key)

if __name__ == "__main__":
    main()
# Judge status: Accepted
a, b, c = [int(i) for i in input("").split(" ")]
c-= a-b
if c > 0:
  print(c)
else:
  print(0)
# Judge status: Wrong Answer
def rolling(str , n):
    return str[n:len(str)] + str[:n]

a=input()
b=input()

for i in range(len(a)):
    if a==b:
        print('Yes')
        exit()
    a=rolling(a,i)

print('No')
# Judge status: Wrong Answer
n=int(input())
m=list(map(int,input().split()))
s=m[0]
t=m[1]
o=m[2]
ans=0
i=3
while i<len(m):
  if s<t and t<o:
    ans+=1
  s=m[0]+1
  t=m[1]+1
  o=m[2]+1
  i+=1
print(ans)
# Judge status: Accepted
N,M = list(map(int,input().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

ans = 0
divisors = make_divisors(M)
for divisor in divisors:
    if N <= M//divisor:
        ans = max(ans,divisor)

print(ans)
# Judge status: Accepted
from itertools import product as P

a, b, c, d = input()

ops = P(("+", "-"), repeat=3)
for op1, op2, op3 in ops:
    f = f"{a}{op1}{b}{op2}{c}{op3}{d}"
    if eval(f) == 7:
        print(f + "=7")
        break
# Judge status: Accepted
def answer(x: int) -> int:
    if x < 4 :
        return 1

    result = 1
    for b in range(2, x + 1):
        for p in range(2, x + 1):
            exp = pow(b, p)
            if exp <= x:
                result = max(result, exp)
            else:
                break

    return result


def main():
    x = int(input())
    print(answer(x))


if __name__ == '__main__':
    main()
# Judge status: Accepted
A,B,C,D = input()
print("Bad" if A==B or B==C or C==D else "Good")