Harryxun/stf_run huggingface dataset:
import sys
from collections import deque
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
v = nl()
d = deque(v)
ans = 0
for m in range(k + 1):
    lis = d.copy()
    neg = []
    summ = 0
    for i in range(m):
        lis = d.copy()
        neg = []
        summ = 0
        if len(lis) != 0:
            l = lis.popleft()
            summ += l
            if l < 0:
                neg.append(l)
            for j in range(m - i):
                if len(lis) != 0:
                    l = lis.pop()
                    summ += l
                    if l < 0:
                        neg.append(l)
            neg.sort()
            for o in range(k - m):
                if o < len(neg):
                    summ -= neg[o]
                else:
                    break
    ans = max(ans, summ)
print(ans)


### FIXED CODE ###

import sys
from collections import deque
import copy
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
v = nl()
d = deque(v)
ans = 0
for m in range(k + 1):
    for p in range(m + 1):
        lis = copy.copy(d)
        neg = []
        summ = 0
        for i in range(p):
            if len(lis) == 0:
                break
            l = lis.popleft()
            summ += l
            if l < 0:
                neg.append(l)
        for j in range(m - p):
            if len(lis) == 0:
                break
            l = lis.pop()
            summ += l
            if l < 0:
                neg.append(l)
        neg.sort()
        for o in range(k - m):
            if o < len(neg):
                summ -= neg[o]
            else:
                break
        ans = max(ans, summ)
print(ans)
n = int(input())
a = [int(input()) for i in range(n)]
a_copy = a
for j in range(0,n):
  if max(a) = a[j]:
    a_copy.remove(a_copy[j])
    print(max(a_copy))
  else:
    print(max(a))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b_max = sorted(a)[-2]
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)
s = input()
k = input()
M = 5000000000000000
nlen = 0
i = 0
if s[i] != "1":
    print(s[i])
else:
    while s[i] == "1":
        i += 1
        nlen += 1
        if nlen == (int(k)-1):
            break
    print(s[i])

### FIXED CODE ###

s = input()
k = input()
nlen = 0
i = 0
if s[i] != "1":
    print(s[i])
else:
    while s[i] == "1":
        if nlen == (int(k)-1):
            break
        i += 1
        nlen += 1
    print(s[i])
from random import random
n = int(input())
x = randint(1,n)
if n % 2 ==0:
  print(0.5)
else:
  count = (1+n)*n*0.5
  counts = count//2
  print(counts/count)

### FIXED CODE ###

import random
n = int(input())
x = random.randint(1,n)
if n % 2 ==0:
  print(0.5)
else:
  count = n//2
  print((n-count)/n)
from itertools import accumulate
from collections import Counter

p = int(input().split()[1])
a = list(map(int, input())
if 10 % p == 0:
  r = sum(i for i, x in enumerate(a, 1) if x % p == 0)
else:
  a = accumulate(x * pow(10, i, p) for i, x in enumerate(reversed(a), 1))
  c = Counter(x % p for x in a) 
  c[0] += 1
  r = sum(i * (i - 1) // 2 for i in c.values())
print(r)


### FIXED CODE ###

from itertools import accumulate
from collections import Counter

p = int(input().split()[1])
a = list(map(int, input()))
if 10 % p == 0:
  r = sum(i for i, x in enumerate(a, 1) if x % p == 0)
else:
  a = accumulate(x * pow(10, i, p) for i, x in enumerate(reversed(a), 1))
  c = Counter(x % p for x in a) 
  c[0] += 1
  r = sum(i * (i - 1) // 2 for i in c.values())
print(r)
N=int(input())
X=list(input())

def calc(n,count):
    popcount=bin(n).count("1")
    next_n=n%popcount
    #print(next_n)
    if next_n==0:
        return count+1
    else:
        return calc(next_n, count+1)


for i in range(N):
    if X[i]=="1":
        change="0"
    else:
        change="1"
    X_copy=X.copy()
    X_copy[i]=change
    nowbin="".join(X_copy)
    #print(int(nowbin, 2))
    print(calc(int(nowbin, 2),0))

### FIXED CODE ###

N=int(input())
X=input()
def calc(n,count):
    if n==0:
        return count
    popcount=bin(n).count("1")
    next_n=n%popcount
    #print(next_n)
    if next_n==0:
        return count+1
    else:
        return calc(next_n, count+1)

popcount=X.count("1")
if popcount==1:
    plus=0
    for i in range(N):
        x=X[i]
        if x=="1":
            plus+=pow(2,N-i-1,popcount+1)
    for i in range(N):
        x=X[i]
        if x=="1":
            print(0)
        else:
            ans=plus+pow(2,N-i-1,popcount+1)
            ans%=(popcount+1)
            print(calc(ans,1))
    exit()


plus=0
minus=0
for i in range(N):
    x=X[i]
    if x=="1":
        plus+=pow(2,N-i-1,popcount+1)
        minus+=pow(2,N-i-1,popcount-1)
        plus%=(popcount+1)
        minus%=(popcount-1)

for i in range(N):
    x=X[i]
    if x=="1":
        ans=minus-pow(2,N-i-1,popcount-1)
        ans%=(popcount-1)
        print(calc(ans,1))

    else:
        ans=plus+pow(2,N-i-1,popcount+1)
        ans%=(popcount+1)
        print(calc(ans,1))
import numpy as np
n , k = map(int,input().strip().split())
if k == 2:
    n = bin(n)[2:]
    print(len(n))
elif k==8:
    n = oct(n)[2:]
    print(len(n))
elif k == 3:
    n = np.base_repr(n, base=3)
    print(len(n))
elif k == 10:
    print(len(n))

### FIXED CODE ###

import numpy as np
n , k = map(int,input().strip().split())
n = np.base_repr(n, base=k)
print(len(n))
a = int(input())
b = int(input())
print(str(a*b) + " " + str((a + b) * 2))

### FIXED CODE ###


a, b = map(int, input().split())
print(a*b, a*2 + b*2)
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 14 10:14:13 2018
ALDS1_11_D
@author: maezawa
"""
import sys
sys.setrecursionlimit(10000)

n, m = list(map(int, input().split()))
v = [-1 for _ in range(n)]
stack = []
adj = [[] for _ in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    adj[s].append(t)
    adj[t].append(s)
#print(*adj, sep='\n')
def dfs(u, color):
    if v[u] > 0:
        return 0
    v[u] = color
    #print(u, current, stack)
    for k in adj[u]:
        if v[k] > 0:
            continue
        dfs(k, color)
    return 1

color = 1
for start in range(n):
    if dfs(start, color) == 1:
        color += 1
#for i in range(n):        
#    print('color:{} for node:{}'.format(i, v[i]))

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    if v[s] == v[t]:
        print('yes')
    else:
        print('no')


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Jul 14 10:14:13 2018
ALDS1_11_D
@author: maezawa
"""
import sys
sys.setrecursionlimit(1000000)

n, m = list(map(int, input().split()))
v = [-1 for _ in range(n)]
stack = []
adj = [[] for _ in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    adj[s].append(t)
    adj[t].append(s)
#print(*adj, sep='\n')
def dfs(u, color):
    if v[u] > 0:
        return 0
    v[u] = color
    #print(u, current, stack)
    for k in adj[u]:
        if v[k] > 0:
            continue
        dfs(k, color)
    return 1

color = 1
for start in range(n):
    if dfs(start, color) == 1:
        color += 1
#for i in range(n):        
#    print('color:{} for node:{}'.format(i, v[i]))

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    if v[s] == v[t]:
        print('yes')
    else:
        print('no')
a=[1,2,4,8,16,32,64,128]
n=int(input())
i=0
while a[i]<=n:
    i+=1
print(a[i-1] if i>0 else 0)


### FIXED CODE ###

print('ABC'+input())
N = int(input())
l = []
for _ in range(N):
    l.append(input())
from collections import Countor as C
l = dict(C(l))
for x in range(1,N+1):
    print(l.get(x))

### FIXED CODE ###

N = int(input())
from collections import Counter as C
l = dict(C((int(x) for x in input().split())))
for x in range(1,N+1):
    print(l.get(x,0))
import fractions
import numpy as np
import math

N, M = map(int, input().split())
a = np.array(list(map(int, input().split()))) // 2

def lcm(a, b):
    return a * b // fractions.gcd(a, b)
    
def check_two(num):
    count = 0
    while num % 2 == 0:
        num //= 2
        count += 1
    return count

two_nums = [check_two(i) for i in a]
if len(set(two_nums)) > 1:
    print(0)
    exit()

my_lcm = lcm(a[0], a[1])
for i in range(2, len(a)):
    my_lcm = lcm(my_lcm, a[i])
    if my_lcm > N:
        print(0)
        exit()
    
ans = M // my_lcm
print(math.ceil(ans / 2))

### FIXED CODE ###

import fractions
import math
 
N, M = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]
 
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
    
def check_two(num):
    count = 0
    while num % 2 == 0:
        num //= 2
        count += 1
    return count

two_num = check_two(a[0])

for i in range(1, len(a)):
    if two_num != check_two(a[i]):
        print(0)
        exit()
 
my_lcm = a[0]
for i in range(1, len(a)):
    my_lcm = lcm(my_lcm, a[i])
    if my_lcm > M:
        print(0)
        exit()
    
ans = M // my_lcm
print(math.ceil(ans / 2))
from sys import stdin
import numpy as np
def main():

    input = stdin.readline

    N,K = map(int,input().split())
    p_list = np.asarray(list(map(int,input().split())))

    max_sum = 0
    listN = list(range(N))
    for i in listN:
        tmp_sum = np.sum(p_list[i:i+K])
        if(max_sum < tmp_sum):
            max_sum = tmp_sum
            ichi = i

    kitaichi = ((p+1)/2 for p in p_list[ichi:ichi+K])

    print(sum(kitaichi))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())
    p_list = [(p+1)/2 for p in list(map(int,input().split()))]

    # Sを計算
    S = [0]
    for p in p_list:
        S.append(S[-1] + p)
        # print(S)

    # i:i+kを計算

    maxs = 0
    for i in range(N-K+1):
        p_num = S[i+K] - S[i]
        if(maxs < p_num):
            maxs = p_num
    
    print(maxs)

if __name__ == "__main__":
    main()
n = map(int, input())
a = map(int, input())
if n%500 < a:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

n = int(input())
a = int(input())
if n % 500 <= a:
  print("Yes")
else:
  print("No")
#!/usr/bin/python

import sys


def main():
  args = input()
  print(args)
  length = 6
  elements = [5, 2, 4, 6, 1, 3]
  print(" ".join(elements))
  elements = [str(i) for i in elements]

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

### FIXED CODE ###

#!/usr/bin/python

import sys


def main():
  length = int(input())
  elements = list(map(int, input().split()))
  print(" ".join(str(i) for i in elements))

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

  return 0

if __name__ == '__main__':
  main()
import sys
from collections import deque
input = sys.stdin.readline

MOD = 1000000007

class Node:
    def __init__(self):
        self.check = False
        self.link = []

    def color(self, K):
        self.check = True
        ret = 1
        # 子の塗り分け方を計算
        for i in range(len(self.link)-1):
            ret *= (K - 2) - i
            ret %= MOD
        # 子の子の塗り分け方を掛ける
        for node in self.link:
            if not node.check:
                ret *= node.color(K)
                ret %= MOD
        return ret

def main():
    N, K = map(int, input().split())
    if N == 1:
        print(K)
    else:
        nodes = [Node() for i in range(N+1)]
        for i in range(N-1):
            a, b = map(int, input().split())
            a -= 1; b -= 1;
            nodes[a].link.append(nodes[b])
            nodes[b].link.append(nodes[a])
        root = nodes[0]
        root.check = True
        ans = K
        for i in range(1, len(root.link)+1):
            ans *= (K-i)
            ans %= MOD
        for node in root.link:
            ans *= node.color(K)
            ans %= MOD
        print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(1000000007)
input = sys.stdin.readline

MOD = 1000000007

class Node:
    def __init__(self):
        self.check = False
        self.link = []

    def color(self, K):
        self.check = True
        ret = 1
        # 子の塗り分け方を計算
        for i in range(len(self.link)-1):
            ret *= (K - 2) - i
            ret %= MOD
        # 子の子の塗り分け方を掛ける
        for node in self.link:
            if not node.check:
                ret *= node.color(K)
                ret %= MOD
        return ret

def main():
    N, K = map(int, input().split())
    if N == 1:
        print(K)
    else:
        nodes = [Node() for i in range(N+1)]
        for i in range(N-1):
            a, b = map(int, input().split())
            a -= 1; b -= 1;
            nodes[a].link.append(nodes[b])
            nodes[b].link.append(nodes[a])
        root = nodes[0]
        root.check = True
        ans = K
        for i in range(1, len(root.link)+1):
            ans *= (K-i)
            ans %= MOD
        for node in root.link:
            ans *= node.color(K)
            ans %= MOD
        print(ans)

if __name__ == "__main__":
    main()
s = input()

if s == "AAA" or s -- "BBB":
    print("No")
else:
    print("Yes")

### FIXED CODE ###

s = input()

if s == "AAA" or s == "BBB":
    print("No")
else:
    print("Yes")
n,k = map(int , input().split())
p = list(map(int , input()).split())
 
p.sort()
 
temp = 0
for i in p[:k] :
  temp += i
print(temp)

### FIXED CODE ###

n,k = map(int , input().split( ))
p = list(map(int , input().split( )))
 
p.sort()
 
temp = 0
for i in p[:k] :
  temp += i
print(temp)
N = input().strip()
N = int(N)
dic = collections.defaultdict(lambda: 0)

for i in range(N):
    x,y = input().strip().split(" ")
    x = int(x)
    y = int(y)

    dic[y] += x

prev_time = 0
result = "Yes"

for k,v in dic.items():
    if v > k:
        result = "No"
        break
    prev_time += v

print(result)

### FIXED CODE ###

import collections

N = input().strip()
N = int(N)
dic = collections.defaultdict(lambda: 0)

for i in range(N):
    x,y = input().strip().split(" ")
    x = int(x)
    y = int(y)

    dic[y] += x

prev_time = 0
result = "Yes"

for k,v in sorted(dic.items(),key=lambda x:x[0]):
    if v+prev_time > k:
        result = "No"
        break
    prev_time += v

print(result)
def main():
    A, B, X = list(map(int, input().split()))
    if A >= X or B >= X:
        N = 0
    else:
        for d in range(len(str(X)), 0, -1):
            if d * B < X:
                break
        if d > 0:
            d = min(X // A, pow(10, d))
            for N in range(d, 0, -1):
                if afford(A, B, N, X):
                    break
            else:
                N = 0
        else:
            N = 0
    print(N if N < 1e9 else int(1e9))


def afford(a, b, n, x):
    c = a * n
    if c >= x:
        return False
    y = c + b * len(str(n))
    return y <= x


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    dow = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
    s = input()
    i = dow.index(s) + 1
    print(i)


if __name__ == "__main__":
    main()
int n = input()
print("ABC" if n < 1000 else "ABD")

### FIXED CODE ###

n = int(input())
print("ABC" if n<1000 else "ABD")
from heapq import heapify, heappop, heappush
N=int(input())
A=list(map(int, input().split()))

class MaxHeap:
    def __init__(self, li):
        self.hp = []
        for e in li:
            heappush(self.hp, -e)

    def push(self, x):
        heappush(self.hp, -x)

    def pop(self):
        ret = heappop(self.hp)
        ret *= -1
        return ret

    def seak(self):
        return -self.hp[0]

    def sum(self):
        return -sum(self.hp)

A1=A[:N]
A2=A[N:2*N]
A3=A[2*N:]

heapify(A1)
A1_sum=sum(A1)
A1_li=[A1_sum]
for a in A2:
  heappush(A1, a)
  p=heappop(A1)
  A1_sum+=a-p
  A1_li.append(A1_sum)
  
A3=MaxHeap(A3)
A3_sum=sum(A3)
A3_li=[A3_sum]
for a in A3[::-1]:
  A3.heappush(a)
  A3_sum+=a
  p=A3.heappop()
  A3_sum-=p
  A3_li.append(A3_sum)
  
A3_li=A3_li[::-1]  
ans=False
for a1, a3 in zip(A1_li, A3_li):
  if not ans:
    ans=a1-a3
  else:
    ans=max(ans, a1-a3)
print(ans)

### FIXED CODE ###

from heapq import heapify, heappop, heappush
N=int(input())
A=list(map(int, input().split()))

class MaxHeap:
    def __init__(self, li):
        self.hp = []
        for e in li:
            heappush(self.hp, -e)

    def push(self, x):
        heappush(self.hp, -x)

    def pop(self):
        ret = heappop(self.hp)
        ret *= -1
        return ret

    def seak(self):
        return -self.hp[0]

    def sum(self):
        return -sum(self.hp)

A1=A[:N]
A2=A[N:2*N]
A3=A[2*N:]

heapify(A1)
A1_sum=sum(A1)
A1_li=[A1_sum]
for a in A2:
  heappush(A1, a)
  p=heappop(A1)
  A1_sum+=a-p
  A1_li.append(A1_sum)
  
A3_sum=sum(A3)
A3=MaxHeap(A3)

A3_li=[A3_sum]
for a in A2[::-1]:
  A3.push(a)
  A3_sum+=a
  p=A3.pop()
  A3_sum-=p
  A3_li.append(A3_sum)
  
A3_li=A3_li[::-1]  
ans=False
for a1, a3 in zip(A1_li, A3_li):
  if not ans:
    ans=a1-a3
  else:
    ans=max(ans, a1-a3)
print(ans)
N,T = map(int,input().split())
food = list(list(map(int,input().split()))for i in range(N))
DP = [[0]*(T) for i in range(N+1)]
for i in range(N):
    a,b = food[i]
    for j in range(a):
        DP[i+1][j] = DP[i][j]
    for j in range(a,T):
        DP[i+1][j] = max(DP[i][j],DP[i][j-a]+b)
ans = 0
i = N
j = T-1
while i > 0 and j > 0:
    if DP[i][j] == DP[i][j-1]:
        j -= 1
    elif DP[i][j] == DP[i-1][j]:
        i -= 1
    else:
        food[i-1][1] = 0
        j -= food[i-1][0]
        i -= 1
food.sort(reverse=True,key= lambda x:x[1])
print(DP[-1][-1]+food[0][1])

### FIXED CODE ###

N,T = map(int,input().split())
food = list(list(map(int,input().split()))for i in range(N))
DP = [[0]*(T) for i in range(N+1)]
for i in range(N):
    a,b = food[i]
    for j in range(min(a,T)):
        DP[i+1][j] = DP[i][j]
    for j in range(a,T):
        DP[i+1][j] = max(DP[i][j],DP[i][j-a]+b)
ans = 0
i = N
j = T-1
while i > 0 and j > 0:
    if DP[i][j] == DP[i][j-1]:
        j -= 1
    elif DP[i][j] == DP[i-1][j]:
        i -= 1
    else:
        food[i-1][1] = 0
        j -= food[i-1][0]
        i -= 1
food.sort(reverse=True,key= lambda x:x[1])
print(DP[-1][-1]+food[0][1])
n,m=map(int,input().split())
prev=[];ord=[[]for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  prev.append([a,b])
  ord[a].append(b)
for i in range(n+1):
  if i!=[]:ord[i]=sorted(ord[i])
for [x,y] in prev:
  ind=ord[x].index(y)+1
  print("%06d"%x+"%06d"%ind)
  

### FIXED CODE ###

print(eval(input().replace(" ","+")+"//2"))
N, Y = map(int, input().split())
count = 0
for b in range(N+1):
    for a in range(0, b):
        total = 1000a + 5000(b-a) + 10000(N-b)
        if total == Y:
            print(a,b-a,N-b)
            break
    count += 1
if count == N+1:
    print('-1 -1 -1')

### FIXED CODE ###

N, Y = map(int, input().split())
def otoshidama(n,y):
  No = -1
  for b in range(n+1):
    if b == 0:
      total = 10000*n
      if total == y:
        print('{} 0 0'.format(n))
        return
    for a in range(0, b+1):
      total = 1000*a + 5000*(b-a) + 10000*(n-b)
      if total == y:
        print(n-b,b-a,a)
        return
  print('-1 -1 -1')
  return
otoshidama(N,Y)
import numpy as np
N,M=map(int,input().split())
A=np.zeros(N)
ans=0
for i in range(M):
  s,t=map(int,input().split())
  if s==1 and t==0:
    ans=1
  elif t==0:
    A[s-1]="o"
  else:
    if A[s-1]==0:
      A[s-1]=t
    elif A[s-1]==t:
      A[s-1]=t
    else:
      ans=1
if N!=1:      
  if A[0]==0:
    A[0]=1

if ans==1:
  print(-1)
else:
  for i in range(N):
    if A[i]=="o":
      A[i]=0
    ans+=A[i]*(10**(2-i))
  print(int(ans))
  

### FIXED CODE ###

import numpy as np
N,M=map(int,input().split())
A=np.zeros(N)
ans=0
for i in range(M):
  s,t=map(int,input().split())
  if s==1 and t==0 and N!=1:
    ans=1
  elif t==0:
    A[s-1]=99
  else:
    if A[s-1]==0:
      A[s-1]=t
    elif A[s-1]==t:
      A[s-1]=t
    else:
      ans=1
if N!=1:      
  if A[0]==0:
    A[0]=1

if ans==1:
  print(-1)
else:
  for i in range(N):
    if A[i]==99:
      A[i]=0
    ans+=A[i]*(10**(N-i-1))
  print(int(ans))
a,b=list(map(int,input().split(" ")))
if a>=13:
  pass
elif a>=6:
  b=b//2
else
  b=0
  
print(b)
 

### FIXED CODE ###

a,b=list(map(int,input().split(" ")))
if a>=13:
  pass
elif a>=6:
  b=b//2
else:
  b=0
  
print(b)
A,B=map(int,input().split())
C=[A+A-1, B+B-1, A+B]
print(max(c))

### FIXED CODE ###

a,b=map(int,input().split())
c=[a+a-1,b+b-1,a+b]
print(max(c))
from itertools import product
from collections import OrderedDict

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

m = M//N

# def prime_factors(n):
#     i = 2
#     factors = OrderedDict()
#     while i * i <= n:
#         if n % i:
#             i += 1
#         else:
#             n //= i
#             if i in factors:
#               factors[i] += 1
#             else:
#               factors[i] = 1
#     if n > 1:
#       if n in factors:
#         factors[n] += 1
#       else:
#         factors[n] = 1
#     return factors

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

fct = factorize(M)
current_n = 1

for div in divisorize(fct):
    n = num(div)
    if n <= m and current_n < n:
      current_n = n

print(current_n)

# for x in range(m, 0, -1):
#   if M % x == 0:
#     print(x)
#     break



### FIXED CODE ###

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

m = M//N

# def prime_factors(n):
#     i = 2
#     factors = OrderedDict()
#     while i * i <= n:
#         if n % i:
#             i += 1
#         else:
#             n //= i
#             if i in factors:
#               factors[i] += 1
#             else:
#               factors[i] = 1
#     if n > 1:
#       if n in factors:
#         factors[n] += 1
#       else:
#         factors[n] = 1
#     return factors

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

if M == 1:
  print(1)
  exit()

fct = factorize(M)
current_n = 1

for div in divisorize(fct):
    n = num(div)
    if n <= m and current_n < n:
      current_n = n

print(current_n)

# for x in range(m, 0, -1):
#   if M % x == 0:
#     print(x)
#     break