Harryxun/stf_run huggingface dataset:
s = input()
q = int(input())
for pi in range(q):
    command = input().split()

    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(s[a:b + 1])
    elif command[0] == 'reverse':
        s = s[:a] + reversed(s[a:b + 1][::-1]) + s[b + 1:]
    else:
        p = command[3]
        s = s[:a] + x[3] + s[b+1:]

### FIXED CODE ###

s = input()
q = int(input())
for _ in range(q):
    x = input().split()
    a, b = int(x[1]), int(x[2])
    if x[0] == 'print':
        print(s[a:b+1])
    if x[0] == 'reverse':
        s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:]
    if x[0] == 'replace':
        s = s[:a] + x[3] + s[b+1:]
X,K,D = map(int,input().split())
List = []

if abs(X) > K*D:
    print(abs(X) - K*D)
elif K == 1:
    print(min(abs(X-D),abs(X+D)))
elif K == 2:
    print(min(abs(X+D+D),abs(X-D-D),abs(X)))
elif K == 3:
    print(min(abs(X+D+D+D),abs(X+D),abs(X-D),abs(X-D-D-D)))
else:
    for i in range(3):
        if abs(X - D) >= abs(X+D):
            List.append(abs(X+D))
            X = X+D
        else:
            List.append(abs(X-D))
            X = X-D

    for i in range(K-3):
        if List[i] == List[i+2]:
            if K%2 == i%2:
                print(List[i+1])
            else:
                print(List[i])
            break
        else:
            if abs(X - D) >= abs(X+D):
                List.append(abs(X+D))
                X = X+D
            else:
                List.append(abs(X-D))
                X = X-D

    if len(List) == K:
        print(List[K-1])
    else:
        pass

### FIXED CODE ###

S = input()
count = 0

if S.count("R") == 0:
    count = 0
elif S.count("R") == 1:
    count= 1
elif S.count("R") == 2:
    if S == "RSR":
        count = 1
    else:
        count = 2
else:
    count = 3
    
print(count)
from collections import deque

H,W=map(int,input().split())
H-=1
W-=1
maze=[]
for i in range(H+1):
   S=input()
   S=[c for c in S]
   maze.append(S)

maze[0][0]="S"

count=0
for i in range(H+1):
   for j in range(W+1):
      if maze[i][j]=="#":
         count+=1

que=deque([[0,0]])
steps=[[-1]*(W+1) for i in range(H+1)]
steps[0][0]=0
flag=True

def bfs():
      global flag
      now=que.popleft()
      now_step=steps[now[0]][now[1]]
      for dx,dy in (0,-1),(1,0),(0,1),(-1,0):
            ny=now[0]+dy
            nx=now[1]+dx
            if 0<=ny<=H and 0<=nx<=W:
                  if ny==H and nx==W:
                        print((H+1)*(W+1)-(now_step+1+1)-(count))
                        flag=False
                        break
                  elif maze[ny][nx]==".":
                        maze[ny][nx]="A"
                        que.append([ny,nx])
                        steps[ny][nx]=now_step+1
                  else:
                        pass

while(flag):
      bfs()

### FIXED CODE ###

from collections import deque

H,W=map(int,input().split())
H-=1
W-=1
maze=[]
for i in range(H+1):
   S=input()
   S=[c for c in S]
   maze.append(S)

maze[0][0]="S"

count=0
for i in range(H+1):
   for j in range(W+1):
      if maze[i][j]=="#":
         count+=1

que=deque([[0,0]])
steps=[[-1]*(W+1) for i in range(H+1)]
steps[0][0]=0
flag=True

def bfs():
      global flag
      if len(que)>=1:
         now=que.popleft()
         now_step=steps[now[0]][now[1]]
         for dx,dy in (0,-1),(1,0),(0,1),(-1,0):
               ny=now[0]+dy
               nx=now[1]+dx
               if 0<=ny<=H and 0<=nx<=W:
                     if ny==H and nx==W:
                           print((H+1)*(W+1)-(now_step+1+1)-(count))
                           flag=False
                           break
                     elif maze[ny][nx]==".":
                           maze[ny][nx]="A"
                           que.append([ny,nx])
                           steps[ny][nx]=now_step+1
                     else:
                           pass
      else:
         print(-1)
         flag=False

while(flag):
      bfs()
n, k = map(int, input().split())
p = list(map(int, input().split()))
 
p.sort()
 
i = 0
while i < k:
  i += p[i]
  i ++
  
print(i)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()

i = 0
price = 0
while i < k:
  price += p[i]
  i += 1
 
print(price)
#入力した整数が５、７、５であるならばTrueを返す
# int,int,int -> True 
 
x,y,z = (int(i) for i in input().split())
if x == 7:
    if y == z and y == 5 :
        print("YES")
    else:
        print("NO")
elif y == 7:
    if x == z and x == 5:
        print("YES")
    else:
        print("NO")
elif z == 7:
    if x == y and x == 5:
        print("YES")
    else:
        print("NO")
    else:
        print("NO")

### FIXED CODE ###

# -*- coding: utf-8 -*-

input_list = input().split()

cnt7 = 0
cnt5 = 0

for n in input_list:
    if int(n) == 7:
        cnt7 += 1
    elif int(n) == 5:
        cnt5 += 1
    else:
        continue
if cnt7 == 1 and cnt5 == 2:
    print("YES")
else:
    print("NO")
from itertools import *
H, W, K = map(int, input().split())
S = [list(map(int, input())) for i in range(H)]
ans = 100000
for p in product([0,1],repeat=H-1):
    tmp_ans = sum(p)
    index = []
    for i,j in enumerate(p):
        if j == 1:
            index.append(i+1)
    count = [0] * (len(index) +1)
    for w in range(W):
        plate = [yoko[w] for yoko in S]
        tmp = [0]*(len(index)+1)
        if index == []:
            tmp[0] = sum(plate)
        else:
            tmp[0] = sum(plate[0:index[0]])
            for itr in range(len(index)):
                if itr == len(index) -1:
                    tmp[itr+1] += sum(plate[index[itr]:])
                else:
                    tmp[itr+1] += sum(plate[index[itr]:index[itr+1]])
        if max(tmp_sum) > K :
            tmp_ans = 11111111111
        tmp_sum = [x+y for (x,y) in zip(count,tmp)]
        if max(tmp_sum) > K:
            tmp_ans +=1
            count = tmp
        else:
            count = tmp_sum
    if tmp_ans < ans:
        ans = tmp_ans

print(ans)







### FIXED CODE ###

from itertools import *
H, W, K = map(int, input().split())
S = [list(map(int, input())) for i in range(H)]
ans = 100000
for p in product([0,1],repeat=H-1):
    tmp_ans = sum(p)
    index = []
    for i,j in enumerate(p):
        if j == 1:
            index.append(i+1)
    count = [0] * (len(index) +1)
    for w in range(W):
        plate = [yoko[w] for yoko in S]
        tmp = [0]*(len(index)+1)
        if index == []:
            tmp[0] = sum(plate)
        else:
            tmp[0] = sum(plate[0:index[0]])
            for itr in range(len(index)):
                if itr == len(index) -1:
                    tmp[itr+1] += sum(plate[index[itr]:])
                else:
                    tmp[itr+1] += sum(plate[index[itr]:index[itr+1]])
        if max(tmp) > K :
            tmp_ans = 11111111111
        tmp_sum = [x+y for (x,y) in zip(count,tmp)]
        if max(tmp_sum) > K:
            tmp_ans +=1
            count = tmp
        else:
            count = tmp_sum
    if tmp_ans < ans:
        ans = tmp_ans

print(ans)
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)

### FIXED CODE ###

import math
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)
N, S = map(int, input().split())
data = list(map(int, input().split()))

MOD = 998244353
# dp = [[0]*(3000+1) for _ in range(N)]
# ans = 0

# for i, num in enumerate(data):
#     dp[i][num] = 1
#     for j in range(i):
#         for k in range(S-num, 0, -1):
#             if dp[j][k] >= 1:
#                 dp[j][k+num] += dp[j][k]
#             if k == num:
#                 dp[j][num] += 1
#     for j in range(i+1):
#         ans += dp[j][S]
#     ans %= MOD

# print(ans)

ans = 0
dp = [[] for _ in range(21)]
dp[0] = [0]
for i, num in enumerate(data):
    for j in range(S-num, -1, -1):
        for item in dp[j]:
            dp[j+num] += [item+(1<<i)]

for item in dp[S]:
    for i in range(N+1):
        if item < (1<<i):
            a = N - i + 1
            break
    for i in range(N):
        if item & (1<<i) != 0:
            b = i + 1
            break
    ans = (a*b+ans)%MOD

print(ans)


### FIXED CODE ###

P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])
a=int(input())
b=[]
for i in range(5):
  b.append(int(input()))
key=min(b)
res=4
t=math.ceil(a/key)
res+=t


### FIXED CODE ###

N = int(input())
abc = [int(input()) for _ in range(5)]
ans = N//min(abc)
if N%min(abc):
    ans += 1
print(ans+4)
r = int(input(""))
g = int(input(""))
b = int(input(""))
d = r*100 + g*10 + b
D = int(d)
if D % 4 == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')
import numpy as np
def so(n):
    for i in range(3, int(np.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True
A, B = map(int, input().split())
M = np.min([A, B])
n = 1
if (A % 2 == 0) and (B % 2 == 0):
    n = 2
for i in range(3, M, 2):
    if so(i):
        if (A % i == 0) and (B % i == 0):
            n = n + 1
print(n)


### FIXED CODE ###

N = int(input())
K = int(N / 2) + N % 2
print(K / N)
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

for i in range(len(a)):
    x -= a[i]
    if x >= 0:
        ans = i + 1

print(ans)


### FIXED CODE ###

import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

if ans == N and x not in a_sum:
    ans -= 1

print(ans)
a,b,k=map(int,input().split())
l=list(range(a,b+1))
for i in sorted(set(l[:k]+l[-k:])):
  print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
if b-a+1<2*k:
  l=range(a,b+1)
else:
  l=list(range(a,a+k))+list(range(b-k+1,b+1))
for i in l:
  print(i)
A, B = map(int, input().split())
if A > B: print('GREATER')
if A < B: print('LESS')
if A == B: print('EQUAL')

### FIXED CODE ###

A = input()
B = input()
if len(A) > len(B): print('GREATER')
elif len(A) < len(B): print('LESS')
else:
	for i in range(0, len(A)):
		if A[i] > B[i]:
			print('GREATER')
			break
		if A[i] < B[i]:
			print('LESS')
			break
		if i == len(A)-1:
			print('EQUAL')
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

i = 0
j = 0
cnt = 0
while j < N:
    if x[i][0] < y[j][0] and x[i][1] < y[j][1]:
        cnt += 1
        i += 1
        j += 1
        continue
    else:
	    i += 1
    if i >= N:
      i = 0
      j += 1
print(cnt)

### FIXED CODE ###

N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
y = sorted([list(map(int, input().split())) for _ in range(N)])

cnt = 0
for c, d in y:
  for a, b in x:
    if a < c and b < d:
      x.remove([a, b])
      cnt += 1
      break

print(cnt)
import math
a, b, x = map(int, input().split())

# 台形の場合
if a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

elif a * a * b == 2 * x:
    print(90 - math.degrees(math.atan(a/b)))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

### FIXED CODE ###

import math
a, b, x = map(int, input().split())

if a * a * b == x:
    print(0)
# 台形の場合
elif a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))
n,k = map(int,input().split())
p = sorted([int(input()) for i in range(n)])
count=0
for i in range(k):
  count = count+p[i]
print(count)


### FIXED CODE ###

n,k = map(int,input().split())
p = sorted(list(map(int,input().split())))
total = 0
for i in range(k):
  total += p[i]
print(total)
import math
while t == 0:	
	try:
		n = int(input().rstrip.split(??? ???))
	except:
		break
	else:
		print(math.log10(int(n[0]) + int(n[1])) + 1)

### FIXED CODE ###

import math
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = int (math.log10(x + y) + 1)
		print(a)
N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
#>>>4
count = 0
for n in range (N):
    for nn in range(N):
        distance = 0
        for d in range(D):
            kou = (all_list[n][d] - all_list[nn][d])**2
            distance += kou
        for s in range(250):
            if distance == s**2:
                count += 1
                break
print(round((count - N) / 2))

### FIXED CODE ###

n,a,b = map(int,input().split())
if n*a <= b:
    print(n*a)
else:
    print(b)
a,b,c = map(int,input().split())
if (a<c and c<b) or (a>c and c>b):
　　print("Yes")
else:
　　print("No")


### FIXED CODE ###

a,b,c = map(int,input().split())
if (a<c and c<b) or (a>c and c>b):
       print("Yes")
else:
       print("No")
[N,K] = list(map(int,input().split()))
h = list(map(int,input().split()))

#配るdp
inf = float('inf')
dp = [inf]*N

dp[0] = 0
for i in range(1,K+1):
    dp[i] = abs(h[0] - h[i])

for i in range(1,N-K):
    for j in range(i+1,i+K+1):
        dp[j] = min(dp[i]+abs(h[i]-h[j]), dp[j])

for i in range(N-K, N-1):
    K-=1
    for j in range(i+1,i+K+1):
        dp[j] = min(dp[i]+abs(h[i]-h[j]), dp[j])


print(dp[N-1])

### FIXED CODE ###

[N,K] = list(map(int,input().split()))
h = list(map(int,input().split()))


#配るdp
inf = float('inf')
dp = [inf]*N

dp[0] = 0
for i in range(0,N-1):
    for j in range(i+1, min(i+K+1,N)):
        dp[j] = min(dp[i]+abs(h[i]-h[j]), dp[j])

print(dp[N-1])
a= int(input())
print(a + (a**2) + (a***3))

### FIXED CODE ###

a= int(input())
print(a + (a**2) + (a**3))
s=list(input())
n=len(s)
D=[s[-1]]
s.pop()
while len(s)>0:
  if len(D[-1])==2 or (D[-1]!=s[-1] and (len(s)==1 or s[-1]!=s[-2])):
    D.append(s[-1])
    s.pop()
  else:
    D.append(s[-2]+s[-1])
    s.pop()
    s.pop()

print(len(D))


### FIXED CODE ###

s=list(input())
D=[s[0]]
i=0
while i < len(s) - 1:
  if s[i+1] == D[-1]:
    D.append(s[i+1:i+3])
    i+=2
  else:
    D.append(s[i + 1])
    i+=1

print(len(D)-(1 if i == len(s) else 0))
n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    return -1
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==len(m):
      return i
    
  return -1

print(func(n, s_li_, c_li_))

### FIXED CODE ###

n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    if n==1:
      return 0
    else:
      return 10**(n-1)
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==m:
      return i
    
  return -1

print(func(n, m, s_li_, c_li_))
def knapsack(N,W,weight,value):
    #初期化
    inf=float("inf")
    dp=[[-inf for i in range(W+1)] for j in range(N+1)]
    for i in range(W+1): 
        dp[0][i]=0
    #DP
    for i in range(N):
        for w in range(W+1):
            if weight[i]<=w: #dp[i][w-weight[i]の状態にi番目の荷物が入る可能性がある
                dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
            else: #入る可能性はない
                dp[i+1][w]=dp[i][w]
    return dp[N][W]

n,w=map(int,input().split())
weight=[0]*n
value=[0]*n
for i in range(n):
    weight[i],value[i]=map(int,input().split())

print(knapsack(n,w,a,b))

### FIXED CODE ###

n,w=map(int,input().split())
a=[[int(i) for i in input().split()]for i in range(n)]
dp=[[0 for i in range(w+1)]for i in range(n+1)]
for i in range(n):
    for sum_w in range(1,w+1):
        if sum_w-a[i][0]>=0:
            dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w-a[i][0]]+a[i][1])
        else:
            dp[i+1][sum_w]=dp[i][sum_w]
print(dp[n][w])
while True:
    (m, f, r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break

    mf = m + f
    
    if m == -1 of f == -1 of mf < 30:
        print('F')
    elif mf < 50 and r < 50:
        print('D')
    elif mf < 65:
        print('C')
    elif mf < 80:
        print('B')
    else:
        print('A')

### FIXED CODE ###

while True:
    m, f, r = map(int, input().strip().split())
    if m == f == r == -1: break

    if m == -1 or f == -1 or m + f < 30:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50:
        print('C')
    elif m + f >= 30:
        print('C' if r >= 50 else 'D')
N=int(input())
L=list()
R=list()
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
k=dict()
for i in range(N-1):
  for j in range(i+1,N):
    a,b=L[i]
    c,d=L[j]
    R.append([a-c,b-d])
    n=str(a-c)+" "+str(b-d)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
    R.append([c-a,d-b])
    n=str(c-a)+" "+str(d-b)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
op=max(k.values())
print(N-op)

### FIXED CODE ###

N=int(input())
if N==1:
  print(1)
  exit()
L=list()
R=list()
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
k=dict()
for i in range(N-1):
  for j in range(i+1,N):
    a,b=L[i]
    c,d=L[j]
    R.append([a-c,b-d])
    n=str(a-c)+" "+str(b-d)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
    R.append([c-a,d-b])
    n=str(c-a)+" "+str(d-b)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
op=max(k.values())
print(N-op)
n,a,b=[int,input(),split()]
ptint(min(n*a,b))


### FIXED CODE ###

n,a,b=map(int,input().split())
print(min(n*a,b))
n=int(input())
l=[*input()]
a=l[0]
x=n
for i in range(1,n):
    if a==l[i]:
        x-=1
    a=l[i]
print(x)


### FIXED CODE ###

n=int(input())
ch=input()
a=ch[0]
x=n
for i in range(1,n):
    if a==ch[i]:
        x-=1
    a=ch[i]
print(x)
X, N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except:
  p = []


l = [0]*X

for i in range(N):
  l[abs(p[i] - X)] += 1

if N == 0:
  print(X)
else:
  for i in range(N):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(x-i)
          print(X-i)
        except:
          print(X+i)
        break

### FIXED CODE ###

X, N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except:
  p = []


l = [0]*200

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))

if N == 0:
  print(X)
else:
  for i in range(N+1):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break
import bisect

N, K = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

sep = bisect.bisect(x, 0)

R = x[:sep][::-1] + [-10**7]
L = x[sep:] + [10**7]

for i in range(len(R)):
  R[i] = -R[i]
  
ans = 10**6
if K < len(R):
  ans = min(R[K-1], ans)
if K < len(L):
  ans = min(L[K-1], ans)
  
for i in range(len(R)):
  if K-(i+1)-1 >= 0 and len(L) is not 0:
    ans = min(ans, R[i]*2 + L[K-(i+1)-1])
for i in range(len(L)):
  if K-(i+1)-1 >= 0 and len(R) is not 0:
    ans = min(ans, L[i]*2 + R[K-(i+1)-1])
  
print(ans)

### FIXED CODE ###

import bisect
n, k = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

lft_num = bisect.bisect(x, 0)
rgt_num = n - lft_num

ans = 10**10
for i in range(min(rgt_num, k)):
    r = x[lft_num + i]
    distance = abs(r)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num - (k-i-1) >= 0:
        l = x[lft_num - (k-i-1)]
        distance += abs(r - l)
        ans = min(ans, distance)
for i in range(min(lft_num, k)):
    l = x[lft_num - i - 1]
    distance = abs(l)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num + (k-i-2) < n:
        r = x[lft_num + (k-i-2)]
        distance += abs(r - l)
        ans = min(ans, distance)
    
print(ans)
N = int(input())
A = list(map(int,input().split()))
A.sort()
Q = int(input())


for _ in range(Q):
  b,c=map(int,input().split())
  time = A.count(b)
  if(b != 0):
    place = A.index(b)
    for i in range(time):
      A[place + i] = c
    A.sort()
  print(sum(A))

### FIXED CODE ###

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

num = [0]*(10**5+1)

sum = sum(A)
for i in range(N):
  num[A[i]-1] += 1

for _ in range(Q):
  b,c=map(int,input().split())
  sum += (c-b)*num[b-1]
  num[c-1] += num[b-1]
  num[b-1] = 0
  
  print(sum)
def sumDigit(n):
    s = 0
    while True:
        n, t = divmod(n, 10)
        s = s + t
        if n == 0:
            break
    return s


n = int(input())
a = int(input())
b = int(input())
total = 0
    
for i in range(1, n+1):
    sum = sumDigit(i)
    if(a<= sumDigit(i) <=b):
        total += i
    print(total)
#print(total)




### FIXED CODE ###

n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
  if a <= sum(list(map(int, list(str(i))))) <= b:
    ans += i
print(ans)
from sys import sys
n, m, *x = map(int, stdin.read().split())
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:-n]) if n < m else 0)


### FIXED CODE ###

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:m-n]) if n < m else 0)
n, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**10
dp = [inf]*n
dp[0] = 0
for i in range(1, n):
    for k in range(i-K, i):
        dp[i] = min(dp[i], dp[k]+abs(h[i]-h[k]))
print(dp[n-1])


### FIXED CODE ###

def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()
# -*- coding:utf-8 -*-
import math

def solve(X):
	# b^p = xとなるxを探す
	for x in range(X, 1, -1)
    	for b in range(2, x):
    		p = math.log(x, b)
    		if float.is_integer(p):
    			return x
    	return 1

if __name__ == "__main__":
	X = int(input())
	print(solve(X))


### FIXED CODE ###

# -*- coding:utf-8 -*-
import math

def solve(X):
	ans = X
	# b^p = ansとなるansを探す
	for b in range(2, X):
		p = math.log(ans, b) # 精度で死ぬ(log(100, 10)など)
		if float.is_integer(p):
			return ans
	return 1

def solve2(X):
	# 全探索
	for x in range(X, 1, -1):
		for p in range(2, x):
			for b in range(2, x):
				bp = b**p
				if bp == x:
					return x
				if bp >= x:
					break
	return 1

if __name__ == "__main__":
	X = int(input())
	print(solve2(X))