Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03070 (python)

Fixed submission:
MOD = 998244353
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_sum = sum(a)
half = int(a_sum / 2)

dp = [[0] * (a_sum + 1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    ni = i+1
    for j in range(a_sum+1):
        if dp[i][j] != 0:
            dp[ni][j] += (dp[i][j] * 2) % MOD
            dp[ni][j+a[i]] += dp[i][j]
ans = pow(3, n, MOD)
for item in dp[n][half:]:
    ans -= item * 3
    ans %= MOD

if a_sum % 2 == 0:
    dp = [[0] * (half + 1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        ni = i+1
        for j in range(half+1):
            dp[ni][j] += dp[i][j] % MOD
            if j+a[i] < half+1:
                dp[ni][j+a[i]] += dp[i][j] % MOD
ans += dp[n][half] * 3
ans %= MOD
if ans < 0:
    ans += MOD
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 998244353
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort(reverse=True)
a_sum = sum(a)
half = int(sum(a) / 2)

dp = [[0] * (a_sum + 1) for _ in range(n+1)]
dp[0][0] = 1
for i, item in enumerate(a):
    ni = i+1
    for j in range(a_sum+1):
        if dp[i][j] != 0:
            dp[ni][j] += (dp[i][j] * 2) % MOD
            dp[ni][j+item] += dp[i][j]
total = 1
for i in range(n):
    total *= 3
    total = total % MOD
ans = total - (sum(dp[n][half:])*3)

if a_sum % 2 == 0:
    dp = [[0] * (n + 1) for _ in range(n+1)]
    dp[0][0] = 1
    for i, item in enumerate(a):
        ni = n+1
        for j in range(n):
            if dp[i][j] != 0:
                dp[ni][j] += dp[i][j] % MOD
                if j+item < n:
                    dp[ni][j+item] += dp[i][j] % MOD
ans += dp[n][half] * 3
ans = ans % MOD
if ans < 0:
    ans += MOD
print(ans)
Problem p03087 (python)

Fixed submission:
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = np.zeros(n)
for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = True

for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A":
    if item[1] != n:
      if s[item[1]] == "C":
        ans -= 1
  print(int(ans))
Problem p03089 (python)

Fixed submission:
import sys

n = int(input())

b = [int(item) for item in input().split()]

def dfs(b_sub, ans):
  if len(b_sub) == 0:
    for a in ans[::-1]:
      print(a)
    sys.exit()
  takeable = []
  for i, item in enumerate(b_sub):
    if i+1 == item:
      takeable.append(i)
  if len(takeable) == 0:
    print(-1)
    sys.exit()
  for item in takeable[::-1]:
    tmp = b_sub
    taken = tmp.pop(item)
    ans.append(taken)
    dfs(tmp, ans)
  
print(dfs(b, []))

Buggy submission (verdict: Runtime Error):
n = int(input())

b = [int(item) for item in input().split()]

def dfs(b_sub, ans):
  if len(b_sub) == 0:
    for a in ans[::-1]:
      print(a)
    return 0
  takeable = []
  for i, item in enumerate(b_sub):
    if i+1 == item:
      takeable.append(i)
  if len(takeable) == 0:
    print(-1)
    return -1
  for item in takeable[::-1]:
    tmp = b_sub
    taken = tmp.pop(item)
    ans.append(taken)
    dfs(tmp, ans)
  
print(dfs(b, []))
Problem p03091 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]

def find_single_self_loop(start, prev, n):
    if prev != -1 and len(edge[n]) != 2:
        if n == start:
            return True
        else:
            return False
    for item in edge[n]:
        if item == prev:
            continue
        ret = find_single_self_loop(start, n, item)
        if ret:
            return True
    return False

for i in range(m):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

order = [0] * (10**5 + 10)
# Must be Euler graph
for i, line in enumerate(edge):
    o = len(line)
    order[o] += 1
    if o % 2 != 0:
        print("No")
        exit()
    if o >= 4:
        index = i

# Existance of over order-6 node means graph includes over 3 circuits
if max(order[6:]) > 0:
    print("Yes")
    exit()

# only 1 order-4 up to 2 circuit
if order[4] <= 1:
    print("No")
    exit()
# over 3 order-4 includes over 3 circuits 
elif order[4] >= 3:
    print("Yes")
    exit()
# 2 order-4
else:
    ret = find_single_self_loop(index, -1, index)
    if ret:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]

def find_single_self_loop(start, prev, n):
    if prev != -1 and len(edge[n]) != 2:
        if n == start:
            return True
        else:
            return False
    for item in edge[n]:
        if item == prev:
            continue
        ret = find_single_self_loop(start, n, item)
        if ret:
            return True
    return False

for i in range(m):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

order = [0] * (10**5 + 10)
# Must be Euler graph
for i, line in enumerate(edge):
    o = len(line)
    order[o] += 1
    if o % 2 != 0:
        print("No")
        exit()
    if o >= 4:
        index = i

# Existance of over order-6 node means graph includes over 3 circuits
if max(order[6:]) > 0:
    print("Yes")
    exit()

print(order[:10])
# only 1 order-4 up to 2 circuit
if order[4] <= 1:
    print("No")
    exit()
# over 3 order-4 includes over 3 circuits 
elif order[4] >= 3:
    print("Yes")
    exit()
# 2 order-4
else:
    ret = find_single_self_loop(index, -1, index)
    if ret:
        print("Yes")
    else:
        print("No")
Problem p03106 (python)

Fixed submission:
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)

    divisors.sort()
    return divisors

input = [int(item) for item in input().split()]
a, b, k = input
divisors = make_divisors(a)

th = 0
for i, item in enumerate(divisors[::-1]):
  if b % item == 0:
    th += 1
  if th == k:
    print(item)
    break

Buggy submission (verdict: Runtime Error):
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)

    divisors.sort()
    return divisors

input = [int(item) for item in input().split()]
a, b, k = input
divisors = make_divisors(a)

th = 0
for i, item in enumerate(divisors):
  if b % item == 0:
    th += 1
  if th == k
    return th

return 0
Problem p03109 (python)

Fixed submission:
s = input()
year = int(s[0:4])
month = int(s[5:7])
 
if year >= 2019 and month >= 5:
  print("TBD")
else:
  print("Heisei")

Buggy submission (verdict: Runtime Error):
s = input()
year = int(s[0:4])
month = int(s[5:7])

if yaer >= 2019 and month >= 5:
  print("TBD")
else:
  print("Heisei")
Problem p03110 (python)

Fixed submission:
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if item[1] == "JPY":
    kingaku += float(item[0])
  else:
    kingaku += float(item[0]) * 380000.0
 
print(kingaku)

Buggy submission (verdict: Runtime Error):
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if otoshidamas[1] == "JPY":
    kingaku += float(otoshidamas[0])
  else:
    kingaku += float(otoshidamas[0]) * 380000.0
 
print(kingaku)

Buggy submission (verdict: Runtime Error):
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if otoshidamas[1] == "JPY":
    kingaku += float(otoshidamas[0])
  else:
    kingaku += float(otoshidamas[0]) * 380000.0
 
print(kingaku)

Buggy submission (verdict: Runtime Error):
n = int(input())

otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append([float(item) for item in input()])
  
for item in otoshidamas:
  if otoshidamas[1] == "JPY":
    kingaku += otoshidamas[0]
  else:
    kingaku += otoshidamas[0] * 380000.0

print(kingaku)
Problem p03112 (python)

Fixed submission:
import bisect

A, B, Q = [int(i) for i in input().split()]

s = [-10**12] + [int(input()) for i in range(A)] + [10**12]
t = [-10**12] + [int(input()) for i in range(B)] + [10**12]
x = [int(input()) for i in range(Q)]

for item in x:
    a, c = bisect.bisect_left(s, item), bisect.bisect_left(t, item)
    min_value = 10**12
    for item_a in [s[a-1], s[a]]:
        for item_c in [t[c-1], t[c]]:
            pata = abs(item_a - item) + abs(item_a - item_c)
            patb = abs(item_c - item) + abs(item_a - item_c)
            min_value = min(min_value, pata, patb)
    print(min_value)

Buggy submission (verdict: Runtime Error):
import bisect

A, B, Q = [int(i) for i in input().split()]

s = [-10**12] + [int(input()) for i in range(A)] + [10**12]
t = [-10**12] + [int(input()) for i in range(B)] + [10**12]
x = [int(input()) for i in range(Q)]

for item in x:
    b, d = bisect.bisect_left(s, item), bisect.bisect_left(t, item)
    min_value = 10**12
    for item_a in [s[a], s[a+1]]:
        for item_c in [t[c], t[c+1]]:
            pata = abs(item_a - item) + abs(item_a - item_c)
            patb = abs(item_c - item) + abs(item_a - item_c)
            min_value = min(min_value, pata, patb)
    print(min_value)

Buggy submission (verdict: Runtime Error):
import numpy as np

A, B, Q = [int(i) for i in input().split()]

s = np.array([[int(input()) for i in range(A)]])
t = np.array([[int(input()) for i in range(B)]])
x = np.array([[int(input()) for i in range(Q)]])

xtot = np.abs(x-t.T).argmin(axis=0)
xtos = np.abs(s-x.T).argmin(axis=1)

t = np.array([t[0, xtot]])
s = np.array([s[0, xtos]])

stot = np.abs(s-t.T).argmin(axis=0)
ttos = np.abs(s-t.T).argmin(axis=1)

pata = abs(x - t) + abs(t - s[0, ttos]) 
patb = abs(x - s) + abs(s - t[0, stot]) 

for i in range(Q):
    if pata[0, i] >= patb[0, i]:
        print(patb[0, i])
    else:
        print(pata[0, i])

# for i, (a, b) in enumerate(zip(xtot, xtos)):
#     pata = abs(x[0, i] - t[0, i]) + abs(t[0, i] - s[0, ttos[i]]) 
#     patb = abs(x[0, i] - s[0, i]) + abs(s[0, i] - t[0, stot[i]]) 
#     if pata <= patb:
#         print(pata)
#     else:
#         print(patb)

Buggy submission (verdict: Runtime Error):
import numpy as np

A, B, Q = [int(i) for i in input().split()]

s = np.array([[int(input()) for i in range(A)]])
t = np.array([[int(input()) for i in range(B)]])
x = np.array([[int(input()) for i in range(Q)]])

stot = np.abs(s-t.T).argmin(axis=0)
ttos = np.abs(s-t.T).argmin(axis=1)
xtot = np.abs(x-t.T).argmin(axis=0)
xtos = np.abs(s-x.T).argmin(axis=1)

for i, (a, b) in enumerate(zip(xtot, xtos)):
    pata = abs(x[0, i] - t[0, a]) + abs(t[0, a] - s[0, ttos[a]]) 
    patb = abs(x[0, i] - s[0, b]) + abs(s[0, b] - t[0, stot[b]]) 
    if pata <= patb:
        print(pata)
    else:
        print(patb)
Problem p03130 (python)

Fixed submission:
from collections import Counter
cnt = Counter()
for i in range(3):
  cnt.update([int(item) for item in input().split()])
a = list(cnt.values())
a.sort()
if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
from collections import Counter
cnt = Counter()
for i in range(3):
  cnt.update([int(item) for item in input().split()])
a = cnt.values()
a.sort()
if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
  print("YES")
else:
  print("NO")
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
h, w = [int(item) for item in input().split()]
field = []
for i in range(h):
    field.append(input().rstrip())

black = 0; white = 0
visited = [[0] * w for _ in range(h)]

def dfs(is_black, i, j):
    global black
    global white
    visited[i][j] = 1
    for x, y in [[1,0], [0,1], [0,-1], [-1,0]]:
        if i+x < 0 or i+x >= h or j+y < 0 or j+y >= w:
            continue
        if visited[i + x][j + y] != 0:
            continue
        if is_black:
            if field[i+x][j+y] == ".":
                white += 1
                dfs(False, i+x, j+y)
        if not is_black:
            if field[i+x][j+y] == "#":
                black += 1
                dfs(True, i+x, j+y)

ans = 0
for i in range(h):
    for j in range(w):
        if visited[i][j] != 0:
            continue
        if field[i][j] == "#":
            white = 0; black = 1
            dfs(True, i, j)
        else:
            white = 1; black = 0
            dfs(False, i, j)
        ans += white * black

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = [int(item) for item in input().split()]
field = []
for i in range(h):
    field.append(input().rstrip())

black = 0; white = 0
visited = [[0] * w for _ in range(h)]

def dfs(is_black, i, j):
    global black
    global white
    visited[i][j] = 1
    for x, y in [[1,0], [0,1], [0,-1], [-1,0]]:
        if i+x < 0 or i+x >= h or j+y < 0 or j+y >= w:
            continue
        if visited[i + x][j + y] != 0:
            continue
        if is_black:
            if field[i+x][j+y] == ".":
                white += 1
                dfs(False, i+x, j+y)
        if not is_black:
            if field[i+x][j+y] == "#":
                black += 1
                dfs(True, i+x, j+y)

ans = 0
for i in range(h):
    for j in range(w):
        if visited[i][j] != 0:
            continue
        if field[i][j] == "#":
            white = 0; black = 1
            dfs(True, i, j)
        else:
            white = 1; black = 0
            dfs(False, i, j)
        ans += white * black

print(ans)
Problem p03158 (python)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline

INF = 10**12
n, q = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

# Calc cumrative sum
sum_even = [0] * (n + 1)
sum_odd = [0] * (n + 1)
sum_all = [0] * (n + 1)
for i, item in enumerate(a):
    if i % 2 == 0:
        sum_odd[i+1] = sum_odd[i] + a[i]
        sum_even[i+1] = sum_even[i]
    else:
        sum_even[i+1] = sum_even[i] + a[i]
        sum_odd[i+1] = sum_odd[i]
    sum_all[i+1] = sum_all[i] + a[i]

# Iterate in query
a.append(INF)
ans = []
for i in range(q):
    # Get div of aoki - takahashi
    x = int(input())
    big = bisect.bisect_left(a, x)
    small = big - 1
    if (x - a[small]) ** 2 <= (x - a[big]) ** 2:
        l = small
    else:
        l = big
    r = n - 1
    while r - l > 1:
        m = (r + l) // 2
        rng = abs(x - a[m])
        taka = n - m
        aoki = n - taka - (bisect.bisect_left(a, x - rng))
        if taka <= aoki + 1:
            r = m
        else:
            l = m
    rng = abs(x - a[r])
    taka = n - r
    aoki = n - taka - (bisect.bisect_left(a, x - rng))
    taka_sum = sum_all[n] - sum_all[n - taka]
    aoki_sum = sum_all[r] - sum_all[r - taka]
    rest = n - taka * 2
    if rest > 0:
        if rest % 2 == 0:
            taka_sum += sum_even[rest]
            aoki_sum += sum_odd[rest]
        else:
            taka_sum += sum_odd[rest]
            aoki_sum += sum_even[rest]

    ans.append(taka_sum)
print("\n".join([str(item) for item in ans]))

Buggy submission (verdict: Runtime Error):
import bisect
n, q = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
cuma = [0] * (n+1)
bipartite_cuma = [0] * (n+2)
for i in range(0, n):
    cuma[i+1] = cuma[i] + a[i]
    bipartite_cuma[i+2] = bipartite_cuma[i] + a[i]
for i in range(q):
    x = int(input())
    small_id = bisect.bisect_left(a, x) - 1
    big_id = small_id + 1
    if x - a[small_id] <= a[big_id] - x:
        l = small_id
    else:
        l = big_id
    r = n
    l -= 1
    while r - l > 1:
        mid = (l + r) // 2
        t_turn = n - mid
        a_lower_value = x - (a[mid] - x)
        a_turn = mid - bisect.bisect_left(a, a_lower_value) + 1
        if a_turn >= t_turn:
            r = mid
        else:
            l = mid
    ll = bisect.bisect_left(a, x - (a[l] - x))
    if ll > l:
        ll = l
    if n -1 - l <= l+1 - ll:
        takahashi = cuma[n] - cuma[l+1] + bipartite_cuma[ll+1]
        aoki = cuma[l+1] - cuma[ll] + bipartite_cuma[ll]
    else:
        takahashi = cuma[n] - cuma[l+1] + bipartite_cuma[ll]
        aoki = cuma[l+1] - cuma[ll] + bipartite_cuma[ll+1]
    print(takahashi)
Problem p03176 (python)

Fixed submission:
class RMQ:
    def __init__(self, n):
        self.n = n 
        self.size = 2**(self.n - 1).bit_length()
        self.data = [0] * (2*self.size-1)

    # Update ak as x
    def update(self, k, x):
        k += self.size - 1
        self.data[k] = x
        while k > 0:
            k = (k - 1) // 2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])

    # Min value in [l, r)
    def query(self, l, r):
        L = l + self.size; R = r + self.size
        s = 0
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])
            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

n = int(input())
h = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

rmq = RMQ(2*10**5 + 10)
for i in range(n):
    beaut = rmq.query(0, h[i])
    rmq.update(h[i] - 1, beaut - a[i])
print(-rmq.data[0])

Buggy submission (verdict: Runtime Error):
INF = 10**9

class RMQ:
    def __init__(self, n):
        self.n = n 
        self.size = 2**(self.n - 1).bit_length()
        self.data = [INF] * (2*self.size-1)

    # Update ak as x
    def update(self, k, x):
        k += self.size - 1
        self.data[k] = x
        while k > 0:
            k = (k - 1) // 2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])

    # Min value in [l, r)
    def query(self, l, r):
        L = l + self.size; R = r + self.size
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])
            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

n = int(input())
h_s = [int(item) for item in input().split()]
a_s = [int(item) for item in input().split()]

rmq = RMQ(10**5 + 10)
for i, (h, a) in enumerate(zip(h_s, a_s)):
    beaut = rmq.query(0, h)
    if beaut == INF:
        rmq.update(h-1, -a)
    else:
        rmq.update(h-1, beaut - a)

print(-rmq.data[0])
Problem p03229 (python)

Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()

if n == 2:
    print(a[1] - a[0])
    exit()

ans = 0
middles = [n // 2 - 1, n // 2, n // 2 + 1]
if middles.count(0):
    middles.remove(0)
if middles.count(n-1):
    middles.remove(n-1)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[l])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            l += 1
            if l == mid:
                l += 1
            state = False
        else:
            r -= 1
            if r == mid:
                r -= 1
            state = True
    ans = max(ans, val)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[r])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            r -= 1
            if r == mid:
                r -= 1
            state = False
        else:
            l += 1
            if l == mid:
                l += 1
            state = True
    ans = max(ans, val)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()

ans = 0
middles = [n // 2 - 1, n // 2, n // 2 + 1]
if middles.count(0):
    middles.remove(0)
if middles.count(n-1):
    middles.remove(n-1)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[l])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            l += 1
            if l == mid:
                l += 1
            state = False
        else:
            r -= 1
            if r == mid:
                r -= 1
            state = True
    ans = max(ans, val)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[r])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            r -= 1
            if r == mid:
                r -= 1
            state = False
        else:
            l += 1
            if l == mid:
                l += 1
            state = True
    ans = max(ans, val)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()

ans = 0
middles = [n // 2 - 1, n // 2, n // 2 + 1]
middles.remove(0)
middles.remove(n-1)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[l])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            l += 1
            if l == mid:
                l += 1
            state = False
        else:
            r -= 1
            if r == mid:
                r -= 1
            state = True
    ans = max(ans, val)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[r])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            r -= 1
            if r == mid:
                r -= 1
            state = False
        else:
            l += 1
            if l == mid:
                l += 1
            state = True
    ans = max(ans, val)
print(ans)
Problem p03241 (python)

Fixed submission:
import math
n, m = [int(item) for item in input().split()]

ans = 0
for i in range(1, int(math.sqrt(m))+1):
  if m%i == 0:
    if m >= i*n:
      ans = max(ans, i)
    if i>= n:
      ans = max(ans, m//i)
    
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n, m = [int(item) for item in input().split()]

ans = 1
for i in range(1, int(math.sqrt(m))+1):
  if m%i == 0 
    if m >= i*n:
      ans = max(ans, i)
    else:
      ans = max(ans, m%i)
    
print(ans)
Problem p03274 (python)

Fixed submission:
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)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
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]
L = x[sep:]

for i in range(len(R)):
  R[i] = -R[i]

ans = 10**6
for i, r in enumerate(R):
  ans = min(ans, r*2+ L[K-(i+1)-1])
for i, l in enumerate(L):
  ans = min(ans, l*2+ R[K-(i+1)-1])
  
print(ans)