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

Fixed submission:
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

now = 1
path = [1]

for i in range(N + 2):
    now = A[now]
    path.append(now)

if i >= K:
    print(path[K])
    quit()

now = path.pop()
lo_start = i - 1
while path[lo_start] != now:
    lo_start -= 1

loop = path[lo_start:]

ans = loop[(K - path.index(now)) % len(loop)]

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

now = 1
path = [1]

for i in range(N + 2):
    now = A[now]
    path.append(now)

if i >= K:
    print(path[K])
    quit()

now = path.pop()
lo_start = i - 1
while path[lo_start] != now:
    lo_start -= 1

lo_len = i - lo_start
loop = path[lo_start:]

ans = loop[(K - path.index(lo_start)) % lo_len]

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

now = 1
path = [1]

for i in range(N + 2):
    now = A[now]
    i += 1
    if now in path: break
    path.append(now)

if i >= K:
    print(path[K])
    quit()

lo_start = path.index(now)
lo_len = i - lo_start
loop = path[lo_start:]

ans = loop[(K - lo_start) % lo_len]

print(ans)
Problem p02690 (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

x = input()
X = int(x)

div = make_divisors(X)

for item in div:
    for A in range(-1000,1000):
        B = A - item

        if A**5 - B**5 == X:
            print(str(A) + " " + str(B))
            break
        else:
            continue
        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

x = input()
X = int(x)

div = make_divisors(X)

for item in div:
    for A in range(-1000,1000):
        B = A - item

        if A^5 - B^5 == X:
            print(A + " " + B)
Problem p02702 (python)

Fixed submission:
S = list(map(int, list(input())))

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi = (10 * digi) % 2019

    cnt[pops] += 1

ans = 0

for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
count = [0]*2019
mod = 0

for i in range(len(S))
	mod = int(S[-i]) % 2019
	count[mod] += 1

answer = 0

for k in range(2019)
	answer = answer + count[k]

print(answer)

Buggy submission (verdict: Runtime Error):
S = input()
answer = 0
for i in range(int(S)//2019 + 1):
    f = 2019 * i
    if f in S:
        answer += 1

print(answer)

Buggy submission (verdict: Runtime Error):
S = input()
answer = 0
for i in range(int(int(S))//2019 + 1):
    f = 2019 * i
    if f in S:
        answer += 1

print(answer)

Buggy submission (verdict: Runtime Error):
S = input()
answer = 0
for i in range(-int(-int(S))//2019):
    f = 2019 * i
    if f in S:
        answer += 1
        
print(answer)
Problem p02705 (python)

Fixed submission:
R = input()
print(2*int(R)*3.14159265)

Buggy submission (verdict: Runtime Error):
R = input()
print(2*R*3.14159265)
Problem p02713 (python)

Fixed submission:
import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)

Buggy submission (verdict: Runtime Error):
import fractions

K = input()

Sum = 0

for A in range(K):
    a = A + 1
    for B in range(K):
        b = B + 1
        for C in range(K):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)
Problem p02714 (python)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            mean = (max[r, g, b] + min[r, g, b])/2
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

Buggy submission (verdict: Runtime Error):
l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            mean = (max[r, g, b] + min[r, g, b]/2)
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(110000) #再帰上限はデフォルトで1000回までなので，増やす。

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

graph = [[] for _ in range(110000)]

for _ in range(M):
    x, y = map(int, input().split())

    graph[x].append(y)

dp_memo = [-1] * 110000

def dp(v):
    if dp_memo[v] != -1:
        return dp_memo[v]

    ret = 0
    for item in graph[v]:
        ret = max(ret, dp(item) + 1)

    dp_memo[v] = ret
    return ret

ans = 0

for i in range(1, N+1):
    ans = max(ans, dp(i))

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

graph = [[] for _ in range(110000)]

for _ in range(M):
    x, y = map(int, input().split())

    graph[x].append(y)

dp_memo = [-1] * 110000

def dp(v):
    if dp_memo[v] != -1:
        return dp_memo[v]

    ret = 0
    for item in graph[v]:
        ret = max(ret, dp(item) + 1)

    dp_memo[v] = ret
    return ret

ans = 0

for i in range(1, N+1):
    ans = max(ans, dp(i))

print(ans)
Problem p03168 (python)

Fixed submission:
import numpy as np

N = int(input())
p = [0] + list(map(float, input().split()))

dp = np.zeros((3100, 3100))
#dp[i, j] = i枚目までのコインを投げて，表の個数がj枚である確率
#pythonのlistだと遅いので，numpyにおけるベクトル漸化式としてdpを埋めていく

dp[1, 0] = 1-p[1]
dp[1, 1] = p[1]

for i in range(2, N + 1):
    dp[i] = np.roll(dp[i-1], 1) * p[i] + dp[i-1] * (1-p[i])
    #dp[i][j] = i-1枚目までで表がj-1かつi回目で表　＋　i-1回目までで表がj枚かつi回目で裏（MECE）
    #つまり，dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i])
    #numpyを使ってベクトル漸化式と見ることで，for_loopを一層分解消。
    #print(i, j, dp[i][j])

ans = 0

for k in range(-(-N//2), N+1):
    ans += dp[N, k]

print(ans)

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

N = int(input())
p = [0] + list(input().split())

for i in range(1, N+1):
    item = p[i].replace('0.', '')
    p[i] = int(item)

#print(p)

dp = np.zeros((3100, 3100))
#dp[i, j] = i枚目までのコインを投げて，表の個数がj枚である確率 * (10**(2*i))
#pythonのlistだと遅いので，numpyにおけるベクトル漸化式としてdpを埋めていく

dp[1, 0] = 100-p[1]
dp[1, 1] = p[1]

for i in range(2, N + 1):
    dp[i] = (np.roll(dp[i-1], 1) * p[i] + dp[i-1] * (100-p[i])) // 10**max(0, i-10)
    #dp[i][j] = i-1枚目までで表がj-1かつi回目で表　＋　i-1回目までで表がj枚かつi回目で裏（MECE）
    #つまり，dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i])
    #numpyを使ってベクトル漸化式と見ることで，for_loopを一層分解消。
    #print(i, j, dp[i][j])
    #プログラムの仕組み上，iが一つ進むと，100 * 100 = 10**4　ずつスケールが大きくなっていく。10**10で打ち切る。


ans = 0

for k in range(-(-N//2), N+1):
    ans += dp[N, k]

dig = min(2*N, 10)

print(ans/10**dig)

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

N = int(input())
p = [0] + list(input().split())

for i in range(1, N+1):
    item = p[i].replace('0.', '')
    p[i] = int(item)

#print(p)

dp = np.zeros((3100, 3100))
#dp[i, j] = i枚目までのコインを投げて，表の個数がj枚である確率 * (10**(2*i))
#pythonのlistだと遅いので，numpyにおけるベクトル漸化式としてdpを埋めていく

dp[1, 0] = 100-p[1]
dp[1, 1] = p[1]

for i in range(2, N + 1):
    dp[i] = (np.roll(dp[i-1], 1) * p[i] + dp[i-1] * (100-p[i]))
    #dp[i][j] = i-1枚目までで表がj-1かつi回目で表　＋　i-1回目までで表がj枚かつi回目で裏（MECE）
    #つまり，dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i])
    #numpyを使ってベクトル漸化式と見ることで，for_loopを一層分解消。
    #print(i, j, dp[i][j])
    #プログラムの仕組み上，iが一つ進むと，100 * 100 = 10**4　ずつスケールが大きくなっていく。


ans = 0

for k in range(-(-N//2), N+1):
    ans += dp[N, k]

dig = min(2*N, 10)

print(ans/10**(2*N))
Problem p02536 (python)

Fixed submission:
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_dsu_code = """
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
"""

atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)
dsu = atcoder.dsu

#c
# from atcoder import dsu
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ds = dsu.DSU(n)
for i in ab:
    ds.merge(i[0]-1,i[1]-1)
    
s = ds.groups()

print(len(s)-1)

Buggy submission (verdict: Runtime Error):
from atcoder import dsu
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ds = dsu.DSU(n)
for i in ab:
    ds.merge(i[0]-1,i[1]-1)
    
s = ds.groups()
ans = 0
for i in s:
    if len(i)==1:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
#c
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ds = dsu.DSU(n)
for i in ab:
    ds.merge(i[0]-1,i[1]-1)
    
s = ds.groups()
ans = 0
for i in s:
    if len(i)==1:
        ans+=1
print(ans)
Problem p02554 (python)

Fixed submission:
n = int(input())
mod = (10**9)+7
n_all = 10**(n) % mod
bad_0 = 9**(n)%mod
bad_9 = 9**(n)%mod
bad_18 = 8**(n)%mod

print((n_all-bad_0-bad_9+bad_18)%mod)

Buggy submission (verdict: Runtime Error):

n = int(input())
n_all = 10**(n) % mod
bad_0 = 9**(n)%mod
bad_9 = 9**(n)%mod
bad_18 = 8**(n)%mod

print(n_all-bad_0-bad_9+bad_18)
Problem p02612 (python)

Fixed submission:
n = int(input())
while n>1000:
    n-=1000
print(1000-n)

Buggy submission (verdict: Runtime Error):
#a
n = int(input())
ans = n//1000
print(n%(ans*1000))

Buggy submission (verdict: Runtime Error):
#a
n = int(input())
print(n%((n//1000)*1000))
Problem p02678 (python)

Fixed submission:
#d
n,m=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop(0)
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
            

            
print("Yes")
for i in answer[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
#d
m,n=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop()
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
print("Yes")
for i in answer[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
#d
m,n=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop()
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
print("yes")
for i in answer[1:]:
    print(i)
Problem p02690 (python)

Fixed submission:
import sys

x = int(input())
for a in range(1,1000):
    a_5 = a**5
    if a_5 > x:
        b = 1
        s = x+1
        while s > x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b += 1
            
    elif a_5 < x:
        b = -1
        s = x-1
        while s < x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b -= 1
    else:
        print(a,0)
        sys.exit()

Buggy submission (verdict: Runtime Error):

x = int(input())
for a in range(1,100):
    a_5 = a**5
    
    if a_5 > x:
        b = 1
        s = 0
        while s > x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b += 1
            
    elif a_5 < x:
        b = -1
        s = 0
        while s < x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b -= 1
    else:
        print(a,0)
        sys.exit()
Problem p02713 (python)

Fixed submission:
n = int(input())
answer = 0

def gcd(i, j):
    while j:
        i, j = j, i % j
    return i

for a in range(1,n+1):
    for b in range(1,n+1):
        d = gcd(a,b)
        for c in range(1, n+1):
            answer += gcd(c, d)
print(answer)

Buggy submission (verdict: Runtime Error):
n = int(input())
result = [0]*n**3
for a in range(n):
    for b in range(n):
        for c in range(n):
            if a > b:
                result[n*n*a +n*b + c]= result[n*n*b +n*a + c]
            elif b > c:
                result[n*n*a +n*b + c]= result[n*n*a +n*c + b]
            else:
                result[n*n*a +n*b + c] = gcd(a+1, gcd(b+1,c+1))
print(sum(result))
Problem p02741 (python)

Fixed submission:
target = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(target[int(input()) - 1])

Buggy submission (verdict: Runtime Error):
print(target[int(input()) - 1])
Problem p02742 (python)

Fixed submission:
a,b=map(int, input().split()) 
if a ==1 or b == 1:
    print(1)
    exit()
if a%2 != 0:
    if b%2 != 0:
        if a > b:
            print(int((-(-a//2))+(a*(b-1)/2)))
        else:
            print(int((-(-a//2))+(a*(b-1)/2)))
    else:
        print(int(a*b/2))
else:
    print(int(a*b/2))

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split()) 
if a =1 or b = 1:
    print(1)
    exit()
if a%2 != 0:
    if b%2 != 0:
        if a > b:
            print(int((-(-a//2))+(a*(b-1)/2)))
        else:
            print(int((-(-a//2))+(a*(b-1)/2)))
    else:
        print(int(a*b/2))
else:
    print(int(a*b/2))
Problem p03043 (python)

Fixed submission:
n,k=map(int, input().split())
prob = 0
#サイコロの確率(1/n) 

for i in range(1,n+1):
    if i < k: #サイコロを振った時点で勝っているか？
        a = 1
        while i * (2**a) < k:
            a += 1
        prob += (1/n) * ((1/2) ** a)
    else:
        prob += (1/n)
print(prob)

Buggy submission (verdict: Runtime Error):
prob = 0
#サイコロの確率(1/n) 

for i in range(1,n+1):
    if i < k: #サイコロを振った時点で勝っているか？
        a = 1
        while i * (2**a) < k:
            a += 1
        prob += (1/n) * ((1/2) ** a)
    else:
        prob += (1/n)
print(prob)
Problem p02579 (python)

Fixed submission:
from collections import *

def main():
    H,W = map(int, input().split())
    ch,cw = map(int, input().split())
    dh,dw = map(int, input().split())
    s = ["#"*(W+4)]
    s.append("#"*(W+4))
    for i in range(H):
        s.append("##"+input()+"##")
    s.append("#"*(W+4))
    s.append("#"*(W+4))
    
    ans = [[-1]*(W+4) for _ in range(H+4)]
    for i in range(H+4):
        for j in range(W+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ch += 1; cw += 1
    dh += 1; dw += 1
    ans[ch][cw] = 0
    
    move = [[-1,0],[1,0],[0,-1],[0,1]]
    magic = [
        [-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],\
        [-1,-2],[-1,-1],[-1,0],[-1,1],[-1,2],\
        [0,-2],[0,-1],[0,0],[0,1],[0,2],\
        [1,-2],[1,-1],[1,0],[1,1],[1,2],\
        [2,-2],[2,-1],[2,0],[2,1],[2,2]
        ]
    
    mylist = deque([[ch,cw]])
    mylist2 = deque([])
    while len(mylist) > 0:
        x,y = mylist.popleft()
        mylist2.append([x,y])
        for p,q in move:
            v1,v2 = x+p,y+q
            if ans[v1][v2] == -1:
                mylist.append([v1,v2])
                ans[v1][v2] = ans[x][y]
        if len(mylist) == 0:
            while len(mylist2) > 0:
                x2,y2 = mylist2.popleft()
                for v1,v2 in magic:
                    i,j = x2+v1,y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        mylist.append([i,j])
    print(ans[dh][dw])
 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import *
H,W = map(int,input().split())
CH,CW = map(int,input().split())
DH,DW = map(int,input().split())
S = [(W+4)*["#"]]+[(W+4)*["#"]]+[2*["#"]+list(input())+2*["#"] for h in range(H)]+[(W+4)*["#"]]+[(W+4)*["#"]]
S[CH+1][CW+1] = 0
P = []
Q = deque([[CH+1,CW+1]])
ans = 0

for n in range(1000):
  while Q:
    y,x = Q.popleft()
    P+=[[y,x]]
    for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
      if S[y+dy][x+dx]==".":
        S[y+dy][x+dx] = S[y][x]
        Q+=[[y+dy,x+dx]]

  if S[DH+1][DW+1]==".":
    for x,y in P:
      for dy,dx in [[2,2],[2,1],[2,0],[2,-1],[2,-2],[1,2],[1,1],[1,-1],[1,-2],[0,2],[0,-2],[-1,2],[-1,1],[-1,-1],[-1,-2],[-2,2],[-2,1],[-2,0],[-2,-1],[-2,-2]]:
        if S[y+dy][x+dx]==".":
          S[y+dy][x+dx] = ans+1
          Q+=[[y+dy,x+dx]]
    ans+=1

if S[DH+1][DW+1]==".":
  print(-1)
else:
  print(S[DH+1][DW+1])
Problem p02774 (python)

Fixed submission:
from numpy import *
N,K = map(int,input().split())
A = array(sorted(list(map(int,input().split()))))
nega = A[A<0]
zera = A[A==0]
posa = A[0<A]

def cnt(x):
  y = 0
  if x>=0:
    y+=N*len(zera)
  y+=searchsorted(A,x//posa,side="right").sum()
  y+=N*len(nega)-searchsorted(A,-(-x//nega)).sum() 
  y-=len(A[A*A<=x])
  return y//2

r = 10**18
l = -r-1

while r-l>1:
  c=(r+l)//2
  if K<=cnt(c):
    r=c
  else:
    l=c

print(r)

Buggy submission (verdict: Runtime Error):
from numpy import *
N,K = map(int,input().split())
A = array(sorted(list(map(int,input().split()))))
nega = A[A<0]
zera = A[A==0]
posa = A[0<A]

def cnt(x):
  y = 0
  if x>=0:
    y+=n*len(zera)
  y+=searchsorted(A,x//posa,side="right").sum()
  y+=N*len(nega)-searchsorted(A,-(-x//nega)).sum() 
  y-=len(A[A*A<=x])
  return y//2

r = 10**18
l = -r-1

while r-l>1:
  c=(r+l)//2
  if K<=cnt(c):
    r=c
  else:
    l=c

print(r)
Problem p02928 (python)

Fixed submission:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
a = N*[0]
b = N*[0]

for i in range(N):
  for j in range(N):
    if i<j and A[i]>A[j]:
      a[i]+=1
    if i<j and A[i]<A[j]:
      b[i]+=1

print((sum(a)*K*(K+1)//2+sum(b)*K*(K-1)//2)%(10**9+7))

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
a = N*[0]

for i in range(N):
  for j in range(N):
    if i<j and A[i]>A[j]:
      a[i]+=1

c = [i*K*(K+1)//2 for i in a]
print(sum(c))%(10**9+7)
Problem p02983 (python)

Fixed submission:
a = list(map(int,input().split()))
b = []

if a[1]-a[0]>=2019:
  print(0)
else:
  for i in range(a[0],a[1]+1):
    for j in range(a[0],i):
      c = (i*j)%2019
      b.append(c)
  else:
    print(min(b))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
b = []
d = [a[0]%2019, (a[1]+1)%2019]
e = sorted(d)

for i in range(d[0],d[1]):
  for j in range(d[0],i):
    c = (i*j)%2019
    b.append(c)
else:
  print(min(b))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
b = []

for i in range(a[0]%2019,(a[1]+1)%2019):
  for j in range(a[0]%2019,i):
    c = (i*j)%2019
    b.append(c)
else:
  print(min(b))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
b = []

for i in range((a[1]-a[0])%2019):
  for j in range(i):
    c = ((i+a[0])%2019)*((j+a[0])%2019)
    b.append(c)
else:
  print(min(b))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
b = []

for i in range(min(a[1]-a[0],2100)):
  for j in range(i):
    c = ((i+a[0])%2019)*((j+a[0])%2019)
    b.append(c)
else:
  print(min(b))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
b = []

for i in range(min(a[1]-a[0],2020)):
  for j in range(i):
    c = ((i+a[0])%2019)*((j+a[0])%2019)
    b.append(c)
else:
  print(min(b))
Problem p02999 (python)

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

if a[0]<a[1]:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
if int(input())<int(input()):
  print(0)
else:
  print(10)
Problem p03109 (python)

Fixed submission:
a = input()

if int(a[5:7])<=4:
  print("Heisei")
else:
  print("TBD")

Buggy submission (verdict: Runtime Error):
a = input()

if int(a[6:8])<=4:
  print("Heisei")
else:
  print("TBD")
Problem p03125 (python)

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

if a[1]%a[0]==0:
  print(a[0]+a[1])
else:
  print(a[1]-a[0])

Buggy submission (verdict: Runtime Error):
a = list(map(int,input()))

if a[1]%a[0]==0:
  print(a[0]+a[1])
else:
  print(a[1]-a[0])
Problem p03238 (python)

Fixed submission:
a = int(input())

if a == 1:
  print("Hello World")
else:
  print(int(input())+int(input()))

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

if a == 1:
  print("Hello World")
else:
  print(int(input()+int(input())))
Problem p03281 (python)

Fixed submission:
a = int(input())
b = 0

for i in range(1,a+1,2):
  c = 0
  for j in range(1,a+1,2):
    if i%j==0:
      c+=1
  else:
    if c==8:
      b+=1
else:
  print(b)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = 0

for i in range(1,1+N,2):
  b = 0
  for j in range(1,1+i,2):
    if i%j==0:
      b+=1
    if n==8:
      a+=1

print(a)
Problem p03284 (python)

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

if a[0]%a[1]==0:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a = list(map(int,input()))

if a[0]%a[1]==0:
  print(0)
else:
  print(1)