Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

rgb = []
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            rgb.append((r,g,tmp//B))

print(len(set(rgb)))

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

rgb = []
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp >= 0 and tmp%B == 0:
            rgb.append((r,g,tmp//B))

print(len(set(rgb)))

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

rgb = []
s = set([x*B for x in range(N) if x*B <= N])
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        if N-r*R-g*G in s:
            rgb.append((r,g,(N-r*R-g*G)//B))

print(len(set(rgb)))

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

rgb = []
s = set([x*B for x in range(N) if x*B <= N])
for r in range(N//R + 1):
    for g in range(N//G + 1):
        if N-r*R-g*G in s:
            rgb.append((r,g,(N-r*R-g*G)//B))

print(len(set(rgb)))

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

rgb = []
for r in range(N+1):
    for g in range(N+1):
        if N-r*R-g*G >= 0 and (N-r*R-g*G)%B == 0:
            rgb.append((r,g,(N-r*R-g*G)//B))

print(len(set(rgb)))

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

rgb = []
for r in range(N+1):
    for g in range(N+1):
        if N-r*R-g*G >= 0 and (N-r*R-g*G)%B == 0:
            rgb.append((r,g,(N-r*R-g*G)//B))

print(len(set(rgb)))

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x

# 1つの数値を順に取り除いて、残りの最大公約数を求める
gcd_list = []

for i in range(N):
    A_rest = A.copy()
    A_rest.remove(A_rest[i])
    pre = A_rest[0]
    for j in range(1,N-1):
        gcd_tmp = gcd(pre,A_rest[j])
        pre = gcd_tmp
    gcd_list.append(pre)

print(max(gcd_list))

Fixed submission:
import copy

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

def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x

# 1つの数値を順に取り除いて、残りの最大公約数を求める
l_gcd_list = [A[0]]
r_gcd_list = [A[-1]]
gcd_list = []

# 左右端を抜く場合は後で計算
for i in range(1,N-1):
    l_gcd_list.append(gcd(l_gcd_list[-1], A[i]))
    r_gcd_list.append(gcd(r_gcd_list[-1], A[-i-1]))

# 左右端以外のi番目の数値を抜いた場合
for i in range(1,N-1):
    gcd_list.append(gcd(l_gcd_list[i-1],r_gcd_list[-i-1]))

# 左右どちらかの端の数値を抜いたとき
gcd_list.append(l_gcd_list[-1])
gcd_list.append(r_gcd_list[-1])
    
print(max(gcd_list))

Buggy python submission (verdict: Runtime Error):
import math,copy

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

# 1つの数値を順に取り除いて、残りの最大公約数を求める
gcd_list = []

for i in range(N):
    A_rest = A.copy()
    A_rest.remove(A_rest[i])
    pre = A_rest[0]
    for j in range(1,N-1):
        gcd_tmp = math.gcd(pre,A_rest[j])
        pre = gcd_tmp
    gcd_list.append(pre)

print(max(gcd_list))

Fixed submission:
import copy

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

def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x

# 1つの数値を順に取り除いて、残りの最大公約数を求める
l_gcd_list = [A[0]]
r_gcd_list = [A[-1]]
gcd_list = []

# 左右端を抜く場合は後で計算
for i in range(1,N-1):
    l_gcd_list.append(gcd(l_gcd_list[-1], A[i]))
    r_gcd_list.append(gcd(r_gcd_list[-1], A[-i-1]))

# 左右端以外のi番目の数値を抜いた場合
for i in range(1,N-1):
    gcd_list.append(gcd(l_gcd_list[i-1],r_gcd_list[-i-1]))

# 左右どちらかの端の数値を抜いたとき
gcd_list.append(l_gcd_list[-1])
gcd_list.append(r_gcd_list[-1])
    
print(max(gcd_list))
Buggy python submission (verdict: Runtime Error):
S = list(input())
ok = ["A", "C", "G", "T"]

len_list = []
tmp = 0

for l in S:
    if l in ok:
        tmp += 1
    else:
        len_list.append(tmp)
        tmp = 0

print(max(len_list))

Fixed submission:
S = list(input())
ok = ["A", "C", "G", "T"]

len_list = []
tmp = 0

for l in S:
    if l in ok:
        tmp += 1
    else:
        len_list.append(tmp)
        tmp = 0
    
len_list.append(tmp)
        
print(max(len_list))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)

N = int(input())
S = input()
MOD = 10**9 + 7

def dp(i, a, used):
    if i == N-1:
        if S[i] in used:
            return a % MOD
        else:
            return (2*a) % MOD
    else:
        if S[i] in used:
            return dp(i+1, a, used) % MOD
        else:
            return (dp(i+1, a, used) + dp(i+1, a, used|set(S[i]))) % MOD

print(dp(0, 1, set())-1)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
MOD = 10**9 + 7

c = Counter(S)
ans = 1

for v in c.values():
    ans *= v+1
    ans %= MOD

print((ans-1)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)

N = int(input())
S = input()
MOD = 10**9 + 7

def dp(i, a, used):
    if i == N-1:
        if S[i] in used:
            return a
        else:
            return 2*a
    else:
        if S[i] in used:
            return dp(i+1, a, used)
        else:
            return dp(i+1, a, used) + dp(i+1, a, used|set(S[i]))

print(dp(0, 1, set())-1)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
MOD = 10**9 + 7

c = Counter(S)
ans = 1

for v in c.values():
    ans *= v+1
    ans %= MOD

print((ans-1)%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = list(set(A))
    A = [x%min(A) if x%min(A) != 0 else min(A) for x in A]
    
print(A[0])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = list(set(A))
    min_A = min(A)
    A = [x%min_A if x%min_A != 0 else min_A for x in A]
    
print(A[0])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = [x%min(A) if x%min(A) != 0 else min(A) for x in A]

print(A[0])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = list(set(A))
    min_A = min(A)
    A = [x%min_A if x%min_A != 0 else min_A for x in A]
    
print(A[0])
Buggy python submission (verdict: Runtime Error):
# D - Match Matching

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

n_match = [-1,2,5,5,4,5,6,3,7,6]

dp = [-1] * (N+1) # dp[i]はちょうどi本のマッチ棒で作れる最も桁数の多い整数の桁数

dp[0] = 0
for idx in range(1,N+1):
    tmp = []
    for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
    if tmp:
        dp[idx] = max(tmp)

ans = ""
rest_match = N
while len(ans) <= N//2 and rest_match > 0:
    for x in A:
        if dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
            
print(ans)

Fixed submission:
# D - Match Matching

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

n_match = [-1,2,5,5,4,5,6,3,7,6]

dp = [-1] * (N+1) # dp[i]はちょうどi本のマッチ棒で作れる最も桁数の多い整数の桁数

dp[0] = 0
for idx in range(1,N+1):
    tmp = []
    for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
    if tmp:
        dp[idx] = max(tmp)

ans = ""
rest_match = N
while len(ans) <= N//2 and rest_match > 0:
    for x in A:
        if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
            
print(ans)
Buggy python submission (verdict: Runtime Error):
# D - Various Sushi

import sys

N, K = map(int, sys.stdin.buffer.readline().split())
td = []
for _ in range(N):
    tmp1, tmp2 = map(int, sys.stdin.buffer.readline().split())
    td.append([tmp1-1, tmp2, -1])

td = sorted(td, key = lambda x: x[1], reverse = True)
t_counter = [0]*N
for idx in range(N):
    t_counter[td[idx][0]] += 1
    td[idx][2] = t_counter[td[idx][0]]

t_set = set([td[idx][0] for idx in range(K)])
ans_list = []
ans = sum([td[idx][1] for idx in range(K)]) + len(t_set)**2
ans_list.append(ans)

a = 0
b = 0
for add_kind in range(1, len([x for x in t_counter if x > 0]) - len(t_set) + 1):
    while 1:
        if td[K - 1 - a][2] >= 2:
            ans -= td[K - 1 - a][1]
            a += 1
            break
        a += 1
    while 1:
        if td[K + b][0] not in t_set:
            ans -= len(t_set)**2
            t_set.add(td[K + b][0])
            ans += td[K + b][1] + len(t_set)**2
            b += 1
            break
        b += 1
    ans_list.append(ans)

print(max(ans_list))

Fixed submission:
# D - Various Sushi

import sys

N, K = map(int, sys.stdin.buffer.readline().split())
td = []
for _ in range(N):
    tmp1, tmp2 = map(int, sys.stdin.buffer.readline().split())
    td.append([tmp1-1, tmp2, -1])

td = sorted(td, key = lambda x: x[1], reverse = True)
t_counter = [0]*N
for idx in range(N):
    t_counter[td[idx][0]] += 1
    td[idx][2] = t_counter[td[idx][0]]

t_set = set([td[idx][0] for idx in range(K)])
ans_list = []
ans = sum([td[idx][1] for idx in range(K)]) + len(t_set)**2
ans_list.append(ans)

a = 0
b = 0
while 1:
    while K - 1 - a >= 0:
        if td[K - 1 - a][2] >= 2:
            ans -= td[K - 1 - a][1]
            a += 1
            break
        a += 1
    if K-1-a < 0:
        break
    while K + b <= N-1:
        if td[K + b][0] not in t_set:
            ans -= len(t_set)**2
            t_set.add(td[K + b][0])
            ans += td[K + b][1] + len(t_set)**2
            b += 1
            break
        b += 1
    ans_list.append(ans)
    if K+b == N:
        break

print(max(ans_list))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

start_black = [[False]*W for _ in range(H)]
bl = []
for row in range(H):
    for col in range(W):
        if s[row][col] == "#":
            start_black[row][col] = True
            bl.append([row, col])

ans = 0
for b in bl:
    if start_black[b[0]][b[1]]:
        d = deque([[b[0], b[1]]])
        passed_black = 1
        passed_white = 0
        visited = [[False]*W for _ in range(H)]
        visited[b[0]][b[1]] = True
        while d:
            b_row, b_col = d.popleft()
            for new_row, new_col in [[b_row+1, b_col], [b_row-1, b_col], [b_row, b_col+1], [b_row, b_col-1]]:
                if 0 <= new_row <= H-1 and 0 <= new_col <= W-1 and s[b_row][b_col] != s[new_row][new_col] and not visited[new_row][new_col]:
                    start_black[new_row][new_col] = False
                    d.append([new_row, new_col])
                    visited[new_row][new_col] = True
                    if s[new_row][new_col] == ".":
                        passed_white += 1
                    else:
                        passed_black += 1
        ans += passed_black * passed_white

print(ans)

Fixed submission:
from collections import deque

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

visited = [[False]*W for _ in range(H)]
ans = 0

for row in range(H):
    for col in range(W):
        if not visited[row][col]:
            visited[row][col] = True
            d = deque([[row, col]])
            if s[row][col] == ".":
                passed_black, passed_white = 0, 1
            else:
                passed_black, passed_white = 1, 0

            while d:
                now_row, now_col = d.popleft()
                visited[now_row][now_col] = True
                for new_row, new_col in [[now_row+1, now_col], [now_row-1, now_col], [now_row, now_col+1], [now_row, now_col-1]]:
                    if 0 <= new_row <= H-1 and 0 <= new_col <= W-1 and s[now_row][now_col] != s[new_row][new_col] and not visited[new_row][new_col]:
                        d.append([new_row, new_col])
                        visited[new_row][new_col] = True
                        if s[new_row][new_col] == ".":
                            passed_white += 1
                        else:
                            passed_black += 1

            ans += passed_black * passed_white

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0] + [float("inf")] * (N-1)

for i in range(1, N):
    for back in range(1, K+1):
        try:
            cost[i] = min(cost[i], cost[i-back] + abs(h[i] - h[i-back]))
        except IndexError:
            break

print(cost[-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0] + [float("inf")] * (N-1)

for i in range(1, N):
    for back in range(1, K+1):
        try:
            cost[i] = min(cost[i], cost[i-back] + abs(h[i] - h[i-back]))
        except IndexError:
            break

print(cost[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [0] * (W+1)

for _ in range(N):
    w, v = map(int, input().split())
    for dp_w in reversed(range(W+1)):
        dp_v = dp[dp_w]
        if (dp_w == 0 or dp_v > 0) and dp_w + w <= W:
            dp[dp_w + w] = max(dp[dp_w + w], dp[dp_w] + v)

print(max(dp))

Fixed submission:
N, W = map(int, input().split())
dp = [0] * (W+1)

for _ in range(N):
    w, v = map(int, input().split())
    for dp_w in reversed(range(W+1)):
        dp_v = dp[dp_w]
        if (dp_w == 0 or dp_v > 0) and dp_w + w <= W:
            dp[dp_w + w] = max(dp[dp_w + w], dp[dp_w] + v)

print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

N = int(input())
a = list(map(int, input().split()))

dp_memo = [[float("inf")]*(N+1) for _ in range(N+1)]
for i in range(N+1):
    dp_memo[i][i] = 0

def dp(i,j):
    if dp_memo[i][j] < float("inf"):
        return dp_memo[i][j]
    elif (j-i)%2 == N%2: # 先手番
        tmp = max(a[i] + dp(i+1, j), a[j-1] + dp(i,j-1))
        dp_memo[i][j] = tmp
        return tmp
    else: # 後手番
        tmp = min(-a[i] + dp(i+1, j), -a[j-1] + dp(i,j-1))
        dp_memo[i][j] = tmp
        return tmp

print(dp(0, N))

Fixed submission:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

N = int(input())
a = list(map(int, input().split()))

dp = [[float("inf")]*(N+1) for _ in range(N+1)]

for shift_i in range(N+1):
    for i in range(N+1):
        if i+shift_i >= N+1:
            continue
        if shift_i == 0:
            dp[i][i] = 0
        elif ((i+shift_i)-i)%2 == N%2: # 先手番
            dp[i][(i+shift_i)] = max(a[i] + dp[i+1][(i+shift_i)], a[(i+shift_i)-1] + dp[i][(i+shift_i)-1])
        else:
            dp[i][(i+shift_i)] = min(-a[i] + dp[i+1][(i+shift_i)], -a[(i+shift_i)-1] + dp[i][(i+shift_i)-1])

print(dp[0][N])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

MOD = 10**9 + 7

B = 2**N
dp = [0]*B
dp[B-1] = 1

bit = [[] for _ in range(N+1)]
for v in list(itertools.product([0,1], repeat=N)):
    s = sum(v)
    b = int("".join(list(map(str, v))), 2)
    bit[s].append(b)

for not_matched_woman in reversed(range(1,N+1)):
    for b in bit[not_matched_woman]:
        for i in [i for i in range(N) if A[not_matched_woman-1][i]]:
            if b & (1 << i):
                dp[b ^ (1 << i)] += dp[b]
                dp[b ^ (1 << i)] %= MOD

print(dp[0])

Fixed submission:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7

memo = [-1] * 2**N
memo[0] = 1

def dfs(bit_state, matched):
    if memo[bit_state] != -1:
        return memo[bit_state]
    r = 0
    for i in range(N):
        if bit_state & (1 << i) and A[matched][i]: # bitでi桁目の女性未マッチング かつ 男性がi桁目の女性に対し相性OK
            r += dfs(bit_state ^ (1 << i), matched+1) # i桁目の女性をマッチング済にして遷移
    r %= MOD
    memo[bit_state] = r
    return r

print(dfs(2**N-1, 0))
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
D = int(input())
MOD = 10**9 + 7

dp = [[[0]*D for _ in range(2)] for _ in range(int(len(str(K)))+1)]
dp[0][0][0] = 1

for digit in range(int(len(str(K)))):
    for smaller_flg in [0,1]:
        for mod_d in range(D):
            lim = 9 if smaller_flg else int(str(K)[digit])
            for digit_num in range(lim+1):
                dp[digit+1][smaller_flg or digit_num < lim][(mod_d + digit_num)%D] += dp[digit][smaller_flg][mod_d]
                dp[digit+1][smaller_flg or digit_num < lim][(mod_d + digit_num)%D] %= MOD

print((dp[int(len(str(K)))][1][0] + dp[int(len(str(K)))][0][0] - 1) % MOD)

Fixed submission:
K = int(input())
D = int(input())
MOD = 10**9 + 7

dp = [[[0]*D for _ in range(2)] for _ in range(int(len(str(K)))+1)]
dp[0][0][0] = 1

for digit in range(int(len(str(K)))):
    for smaller_flg in [0,1]:
        lim = 9 if smaller_flg else int(str(K)[digit])
        for digit_num in range(lim+1):
            new_smaller_flg = smaller_flg or digit_num < lim
            for mod_d in range(D):
                new_mod_d = (mod_d + digit_num)%D
                dp[digit+1][new_smaller_flg][new_mod_d] += dp[digit][smaller_flg][mod_d]
                dp[digit+1][new_smaller_flg][new_mod_d] %= MOD

print((dp[int(len(str(K)))][1][0] + dp[int(len(str(K)))][0][0] - 1) % MOD)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]

A.sort()
A = deque(A)

X = A.copy()

B = deque([X.pop()])
flg = True
while X:
    if flg:
        B.append(X.popleft())
        if X:
            B.appendleft(X.popleft())
    else:
        B.append(X.pop())
        if X:
            B.appendleft(X.pop())
    flg = not flg

X = A.copy()
C = deque([X.popleft()])
flg = True
while X:
    if flg:
        C.append(X.pop())
        if X:
            C.appendleft(X.pop())
    else:
        C.append(X.popleft())
        if X:
            C.appendleft(X.popleft())
    flg = not flg

print(max(sum([abs(B[i]-B[i-1]) for i in range(1,N)]), sum([abs(C[i]-C[i-1]) for i in range(1,N)])))

Fixed submission:
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]

A.sort()

X = deque(A.copy())

B = deque([X.pop()])
flg = True
while X:
    if flg:
        B.append(X.popleft())
        if X:
            B.appendleft(X.popleft())
    else:
        B.append(X.pop())
        if X:
            B.appendleft(X.pop())
    flg = not flg

X = deque(A.copy())
C = deque([X.popleft()])
flg = True
while X:
    if flg:
        C.append(X.pop())
        if X:
            C.appendleft(X.pop())
    else:
        C.append(X.popleft())
        if X:
            C.appendleft(X.popleft())
    flg = not flg

print(max(sum([abs(B[i]-B[i-1]) for i in range(1,N)]), sum([abs(C[i]-C[i-1]) for i in range(1,N)])))
Buggy python submission (verdict: Time Limit Exceeded):
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す

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

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

x = M//N

while 1:
    if M % x == 0:
        ans = x
        break
    x -= 1
    
print(ans)

Fixed submission:
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す

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

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

x = M//N

while 1:
    if M % x == 0:
        ans = x
        break
    x -= 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す

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

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

x = 1
while x * N <= M:
    if M % x == 0:
        ans = x
    x += 1
    
print(ans)

Fixed submission:
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す

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

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

x = M//N

while 1:
    if M % x == 0:
        ans = x
        break
    x -= 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す

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

x = 1

while x * N <= M:
    if M % x == 0:
        ans = x
    x += 1
    
print(ans)

Fixed submission:
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す

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

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

x = M//N

while 1:
    if M % x == 0:
        ans = x
        break
    x -= 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list_even = []
abc_list_odd = []

for a in range(1, N+1):
    if (2*a)%K == 0:
        if ((2*a)//K)%2 == 0:
            abc_list_even.append(a)
        else:
            abc_list_odd.append(a)

print(len(list(itertools.product(abc_list_even, repeat=3))) + len(list(itertools.product(abc_list_odd, repeat=3))))

Fixed submission:
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list_even = []
abc_list_odd = []

for a in range(1, N+1):
    if (2*a)%K == 0:
        if ((2*a)//K)%2 == 0:
            abc_list_even.append(a)
        else:
            abc_list_odd.append(a)

print(len(abc_list_even)**3 + len(abc_list_odd)**3)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list = []
for a in range(1, N+1):
    if (2*a)%K == 0:
        abc_list.append(a)

abc_list_even = []
abc_list_odd = []

for a in abc_list:
    if ((2*a)//K)%2 == 0:
        abc_list_even.append(a)
    else:
        abc_list_odd.append(a)


print(len(list(itertools.product(abc_list_even, repeat=3))) + len(list(itertools.product(abc_list_odd, repeat=3))))

Fixed submission:
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list_even = []
abc_list_odd = []

for a in range(1, N+1):
    if (2*a)%K == 0:
        if ((2*a)//K)%2 == 0:
            abc_list_even.append(a)
        else:
            abc_list_odd.append(a)

print(len(abc_list_even)**3 + len(abc_list_odd)**3)