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

Fixed submission:
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count += d[0] * d[1] * d[2]
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
elif len(d) == 5:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    # count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]

    # count += d[0] * d[4] * d[2]
    # count += d[3] * d[4] * d[2]
    count += d[0] * d[4] * d[3]
    # count += d[0] * d[3] * d[2]


print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count = 1
    for i in d:
        count *= i
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
else:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]


print(count)
Problem p03612 (python)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n-1):
    if p[i] - 1 == i:
        count += 1
        p[i] ,p[i + 1] = p[i + 1], p[i]
if p[n - 1] - 1 == n - 1:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if p[i] - 1 == i:
        count += 1
        p[i] ,p[i + 1] = p[i + 1], p[i]
print(count)
Problem p02684 (python)

Fixed submission:
n, k = map( int, input().split() )
a = [ int( i ) for i in input().split() ]

leg = [ 0 ] * n
leg[ 0 ] = 0

p = 0
city_old = 1
for x in range( k ):
    city_new = a[ city_old-1 ]
    if leg[ city_new-1 ] == 0 and city_new != 1:
        leg[ city_new-1 ] = x + 1
    else:
        loop = x + 1 - leg[ city_new-1 ]
        modk = ( k - ( x + 1 ) ) % loop
#        print( loop, modk )
        break
    city_old = city_new
    p += 1

if p == k:
    print( city_old )
    exit()


city_old = city_new
for x in range( modk ):
    city_new = a[ city_old-1 ]
    city_old = city_new

print( city_old )

Buggy submission (verdict: Runtime Error):
n, k = map( int, input().split() )
a = [ int( i ) for i in input().split() ]

leg = [ 0 ] * n
leg[ 0 ] = 1

p = 0
city_old = 1
for x in range( k ):
    city_new = a[ city_old-1 ]
    if leg[ city_new-1 ] == 0:
        leg[ city_new-1 ] += x + 1
    else:
        loop = x + 1 - leg[ city_new-1 ]
        modk = ( k - ( x + 1 ) ) % loop
        break
    city_old = city_new
    p += 1

if p == k:
    print( city_old )
    exit()


city_old = city_new
for x in range( modk ):
    city_new = a[ city_old-1 ]
    city_old = city_new

print( city_old )
Problem p02687 (python)

Fixed submission:
import numpy as np

s = input()
#print( s, w )

if s == "ABC":
    print( "ARC" )
elif s == "ARC":
    print( "ABC" )

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

s = input()
#print( s, w )

if s == "ABC":
    print( "ARC" )
else:
    print( "ABC" )
Problem p02702 (python)

Fixed submission:
import numpy as np

s = input()

d = [ int( 0 ) ] * 2019
d[ 0 ] = int( 1 )
r = int( 0 )
t = int( 1 )

for si in reversed( s ):
#    print( si )

    r = int( si ) * t + r
    r = r % 2019

    t = t * 10
    t = t % 2019

    d[ r ] = d[ r ] + 1

ans = int( 0 )
for di in d:
    ans = ans + di * ( di - 1 ) // 2

print( ans )

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

s = int( input() )
ss = str( s )
l = len( ss )
#print( s, l )

ans = int( 0 )
for i in range( l-4 ):
    for j in range( i+4, l+1 ):
        ssij = ss[ i:j ]
        sij = int( ssij )
#        print( i, j, sij )
        if sij % 2019 == 0:
#            print( "Yes" )
            ans = ans + 1

print( ans )
Problem p02603 (python)

Fixed submission:
INF = 10 ** 10
n = int(input())
a = [INF] + list(map(int, input().split())) + [-INF]
l = []
for i in range(n):
    if len(l) % 2 == 0:
        if a[i + 1] < a[i + 2]:
            l.append(a[i + 1])
    else:
        if a[i + 1] > a[i + 2]:
            l.append(a[i + 1])
t = 1000
for i in range(1, len(l), 2):
    t = t // l[i - 1] * l[i] + t % l[i - 1]
print(t)

Buggy submission (verdict: Runtime Error):
INF = 10 ** 10
n = int(input())
a = [INF] + list(map(int, input().split())) + [-INF]
l = []
for i in range(n):
    if len(l) % 2 == 0:
        if a[i] > a[i + 1] <= a[i + 2]:
            l.append(a[i + 1])
    else:
        if a[i] < a[i + 1] >= a[i + 2]:
            l.append(a[i + 1])
t = 1000
for i in range(0, len(l), 2):
    t = t // l[i] * l[i + 1] + t % l[i]
print(t)
Problem p02605 (python)

Fixed submission:
from bisect import bisect_left
import sys
input = sys.stdin.readline
M = 200001
n = int(input())
l = [None] * n
ans = 10 ** 18
for i in range(n):
    x, y, u = input().split()
    u = ('R', 'D', 'L', 'U').index(u)
    l[i] = (int(x), int(y), u)
for _ in range(3):
    l.sort(key=lambda x: x[0])
    xy = [[] for _ in range(M * 2 - 1)]
    yx = [[] for _ in range(M * 2 - 1)]
    xs = [[] for _ in range(M)]
    k = []
    for i, t in enumerate(l):
        x, y, u = t
        u %= 4
        if u == 3:
            xy[x + y].append(x)
        elif u == 1:
            yx[x - y + M - 1].append(x)
        elif u == 2:
            xs[y].append(x)
        elif u == 0:
            k.append((x, y))
        l[i] = (y, -x + M - 1, u + 1)
    for x, y in k:
        idx = bisect_left(xs[y], x)
        if idx < len(xs[y]):
            ans = min(ans, (xs[y][idx] - x) * 5)
        idx = bisect_left(xy[x + y], x)
        if idx < len(xy[x + y]):
            ans = min(ans, (xy[x + y][idx] - x) * 10)
        idx = bisect_left(yx[x - y + M - 1], x)
        if idx < len(yx[x - y + M - 1]):
            ans = min(ans, (yx[x - y + M - 1][idx] - x) * 10)
if ans == 10 ** 18:
    print('SAFE')
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
M = 200001
n = int(input())
l = [None] * n
ans = 10 ** 18
for i in range(n):
    x, y, u = input().split()
    u = ('R', 'D', 'L', 'U').index(u)
    l[i] = (int(x), int(y), u)
for _ in range(4):
    xy = [[] for _ in range(M * 2 - 1)]
    yx = [[] for _ in range(M * 2 - 1)]
    xs = [[] for _ in range(M)]
    k = []
    for i, t in enumerate(l):
        x, y, u = t
        u %= 4
        if u == 3:
            xy[x + y].append(x)
        elif u == 1:
            yx[x - y + M - 1].append(x)
        elif u == 2:
            xs[y].append(x)
        else:
            k.append((x, y))
        l[i] = (y, -x + M - 1, u + 1)
    for x, y in k:
        idx = bisect_left(xs[y], x)
        if idx < len(xs[y]):
            ans = min(ans, (xs[y][idx] - x) * 5)
        idx = bisect_left(xy[x + y], x)
        if idx < len(xy[x + y]):
            ans = min(ans, (xy[x + y][idx] - x) * 10)
        idx = bisect_left(yx[x - y + M], x)
        if idx < len(yx[x - y + M]):
            ans = min(ans, (yx[x - y + M - 1][idx] - x) * 10)
if ans == 10 ** 18:
    print('SAFE')
else:
    print(ans)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
d = [0] * n
t = x.count('1')
a = 0
b = 0


if t == 1:
    for i in range(n):
        d[i] = (a + pow(2, n - i - 1, t + 1)) % (t + 1)
    for i in range(n):
        a *= 2
        if x[i] == '1':
            a += 1
        a %= t + 1
    for i in range(n):
        if x[i] == '1':
            print(0)
        else:
            p = d[i]
            ans = 1
            while p > 0:
                p %= bin(p).count('1')
                ans += 1
            print(ans)
else:
    for i in range(n):
        a *= 2
        b *= 2
        if x[i] == '1':
            a += 1
            b += 1
        a %= t + 1
        b %= t - 1
    for i in range(n):
        if x[i] == '1':
            d[i] = (b - pow(2, n - i - 1, t - 1)) % (t - 1)
        else:
            d[i] = (a + pow(2, n - i - 1, t + 1)) % (t + 1)
    for i in range(n):
        a *= 2
        b *= 2
        if x[i] == '1':
            a += 1
            b += 1
        a %= t + 1
        b %= t - 1
    for p in d:
        ans = 1
        while p > 0:
            p %= bin(p).count('1')
            ans += 1
        print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
d = [0] * n
t = x.count('1')
a = 0
b = 0
for i in range(n):
    a *= 2
    b *= 2
    if x[i] == '1':
        a += 1
        b += 1
    a %= t + 1
    b %= t - 1
for i in range(n):
    if x[i] == '1':
        d[i] = (b - pow(2, n - i - 1, t - 1)) % (t - 1)
    else:
        d[i] = (a + pow(2, n - i - 1, t + 1)) % (t + 1)
if t == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        else:
            p = d[i]
            for p in d:
                ans = 1
                while p > 0:
                    p %= bin(p).count('1')
                    ans += 1
                print(ans)
else:
    for p in d:
        ans = 1
        while p > 0:
            p %= bin(p).count('1')
            ans += 1
        print(ans)
Problem p02765 (python)

Fixed submission:
"""
じょえちゃんねる
高評価・チャンネル登録よろしくお願いします！
https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
"""
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))

Buggy submission (verdict: Runtime Error):
"""
じょえちゃんねる
高評価・チャンネル登録よろしくお願いします！
https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
"""
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - k))
Problem p02783 (python)

Fixed submission:
h, a = map(int, input().split())
print((h - 1) // a + 1)

Buggy submission (verdict: Runtime Error):
h,a=map(int,inout().split())
print((h-1)//a+1)
Problem p02806 (python)

Fixed submission:
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x:
    flg=True
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x
    flg=True
print(ans)
Problem p02821 (python)

Fixed submission:
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = 0
    for x in a:
        res += n - bisect_left(a, m - x)
    if res >= k:
        l = m
    else:
        r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = n * n - a.searchsorted(m - a).sum()
    if res >= k:
        l = m
    else:
        r = m
b = np.array([0] * (n + 1))
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)
Problem p02824 (python)

Fixed submission:
from bisect import bisect_left
n,m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if v >= p:
    l, r = -1, n - p
    while r - l > 1:
        flg = 0
        med = (l + r) // 2
        t = (v - p) * m
        for i in range(n - p + 1):
            if a[med] + m < a[i]:
                flg = 1
                break
        for i in range(n - p + 1):
            if i == med:
                continue
            t -= min(m, a[med] + m - a[i])
        if t > 0:
            flg = 1
        if flg:
            l = med
        else:
            r = med
    print(n - r)
else:
    print(n - bisect_left(a,a[n - p] - m))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
n,m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if v >= p:
    l, r = -1, n - p - 1
    while r - l > 1:
        flg = 0
        med = (l + r) // 2
        t = (v - p) * m
        for i in range(n - p + 1):
            if a[med] + m < a[i]:
                flg = 1
                break
        for i in range(n - p + 1):
            if i == med:
                continue
            t -= min(m, a[med] + m - a[i])
        if t > 0:
            flg = 1
        if flg:
            l = med
        else:
            r = med
    print(n - r)
else:
    exit(1)
    print(n - bisect_left(a,a[n - p] - m))
Problem p02838 (python)

Fixed submission:
MOD = 10 ** 9 + 7
t = [0] * 60
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        if (a[j] >> i) & 1:
            cnt += 1
    ans += cnt * (n - cnt) * pow(2, i, MOD)
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0]*64
for i in range(n):
    c = bin(a[i])[2:]
    for j, q in enumerate(c):
        if q == '1':
            b[i] += 1
c = 0
b = b[::-1]
for i in range(64):
    c += b[i]*(n-b[i])*2**i
print(c % (10**9+7))
Problem p02848 (python)

Fixed submission:
n = int(input())
s = list(input())
for i in range(len(s)):
    s[i] = chr((ord(s[i]) - 65 + n) % 26 + 65)
print(''.join(s))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
for i in range(len(s)):
  s[i]=chr((ord(s[i])-ord('A')+n)%26+ord('A'))
print(s)
Problem p02867 (python)

Fixed submission:
class UnionFindNode(object):
    """
    Union-Find構造
    ノードのグループ併合や、所属グループ判定を高速に処理する
    """

    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.size_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})"
        return template.format(self.group_id_, self.parent_, self.value, self.size_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        parent = self.root()
        return parent.group_id_

    def size(self):
        parent = self.root()
        return parent.size_

    def unite(self, unite_node):
        parent = self.root()
        unite_parent = unite_node.root()

        if parent.group_id_ != unite_parent.group_id_:
            if parent.size() > unite_parent.size():
                unite_parent.parent_ = parent
                parent.size_ = parent.size_ + unite_parent.size_
            else:
                parent.parent_ = unite_parent
                unite_parent.size_ = parent.size_ + unite_parent.size_

    def same(self, node):
        return self.root() == node.root()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(a, b))
l.sort(key=lambda x: x[1])
a.sort()
d = dict()
for i, x in enumerate(a):
    d[x] = i
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print('No')
        exit(0)
for i in range(n - 1):
    if a[i + 1] <= b[i]:
        print('Yes')
        exit(0)
uf = [UnionFindNode(i) for i in range(n)]
al = [d[x[0]] for x in l]
for i in range(n):
    uf[i].unite(uf[al[i]])
if uf[0].root().size() == n:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(a, b))
l.sort(key=lambda x: x[1])
a.sort()
s = list(set(a))
d = dict()
for i, x in enumerate(s):
    d[x] = i
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print('No')
        exit(0)
for i in range(n - 1):
    if a[i + 1] <= b[i]:
        print('Yes')
        exit(0)
al = [d[x[0]] for x in l]
cnt = 0
t = al[0]
while t != 0:
    t = al[t]
    cnt += 1
if cnt == n - 1:
    print('No')
else:
    print('Yes')
    exit(1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(a, b))
l.sort(key=lambda x: x[1])
a.sort()
s = list(set(a))
d = dict()
for i, x in enumerate(s):
    d[x] = i
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print('No')
        exit(0)
for i in range(n - 1):
    if a[i + 1] <= b[i]:
        print('Yes')
        exit(1)
al = [d[x[0]] for x in l]
cnt = 0
t = al[0]
while t != 0:
    t = al[t]
    cnt += 1
if cnt == n - 1:
    print('No')
else:
    print('Yes')
Problem p02885 (python)

Fixed submission:
a, b = map(int, input().split())
print(max(0, a - 2 * b))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(max(0,a-2*b)
Problem p02943 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
m = min(s)
for p in range(k):
    u = s + s[::-1]
    l = []
    cnt = 0
    idx = 0
    for i in range(n * 2):
        if u[i] == m:
            if cnt == 0:
                idx = i
            cnt += 1
        else:
            if cnt > 0:
                l.append((cnt, idx))
                cnt = 0
    if cnt > 0:
        l.append((cnt, idx))
    a, j = max(l)
    if a >= n:
        print(m * n)
        exit(0)
    for c, i in l:
        if i <= n and c == a:
            s = min(s, u[i:i + n])
    s = s[::-1]
print(s[::-1])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
m = min(s)
for p in range(k):
    u = s + s[::-1]
    l = []
    cnt = 0
    idx = 0
    for i in range(n * 2):
        if u[i] == m:
            if cnt == 0:
                idx = i
            cnt += 1
        else:
            if cnt > 0:
                l.append((cnt, idx))
                cnt = 0
    if cnt > 0:
        l.append((cnt, idx))
    a, j = max(l)
    if a >= n:
        print(m * m)
        exit(0)
    for c, i in l:
        if i <= n and c == a:
            s = min(s, u[i:i + n])
    if (k - p) % 2 == 0:
        s = s[::-1]
print(s)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
m = min(s)
if k >= 20:
    print(m * n)
else:
    for p in range(k):
        u = s + s[::-1]
        l = []
        cnt = 0
        idx = 0
        for i in range(n * 2):
            if u[i] == m:
                if cnt == 0:
                    idx = i
                cnt += 1
            else:
                if cnt > 0:
                    l.append((cnt, idx))
                    cnt = 0
        a, j = max(l)
        for c, i in l:
            if i <= n and c == a:
                s = min(s, u[i:i + n])
        if (k - p) % 2 == 0:
            s = s[::-1]
    print(s)
Problem p02950 (python)

Fixed submission:
p = int(input())


def div(a, b):
    n = len(a)
    m = len(b)
    res = [0] * (n - m + 1)
    tmp = pow(b[-1], p - 2, p)
    for i in range(n - m, -1, -1):
        t = a[i + m - 1] * tmp % p
        res[i] = t
        for j in range(m):
            a[i + j] = (a[i + j] - t * b[j]) % p
    return res


a = list(map(int, input().split()))
ans = [0] * p
f = [0] * (p + 1)
f[0] = 1
for i in range(p):
    for j in range(p, 0, -1):
        f[j] += f[j - 1]
        f[j - 1] = -f[j - 1] * i
        f[j] %= p
for i in range(p):
    if a[i] == 1:
        fm = div(f[:], [-i, 1])
        t = 1
        r = 0
        for v in fm:
            r += v * t
            t = t * i % p
        t = pow(r, p - 2, p)
        for j in range(len(fm)):
            ans[j] += fm[j] * t
for i in range(p):
    ans[i] %= p
print(' '.join(map(str, ans)))

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


def div(a, b):
    n = len(a)
    m = len(b)
    res = [0] * (n - m + 1)
    for i in range(n - m, -1, -1):
        t = a[i + m - 1] * pow(b[-1], p - 2, p) % p
        res[i] = t
        for j in range(m):
            a[i + j] = (a[i + j] - t * b[j]) % p
    return res


a = list(map(int, input().split()))
ans = [0] * p
f = [0] * (p + 1)
f[0] = 1
for i in range(p):
    for j in range(p, 0, -1):
        f[j] += f[j - 1]
        f[j - 1] = -f[j - 1] * i
        f[j] %= p
for i in range(p):
    if a[i] == 1:
        fm = div(f.copy(), [-i, 1])
        t = 1
        r = 0
        for j in range(len(fm)):
            r += fm[j] * t
            t = t * i % p
        for j in range(len(fm)):
            ans[j] += fm[j] * pow(r, p - 2, p) % p
for i in range(p):
    ans[i] %= p
print(' '.join(map(str, ans)))
Problem p02997 (python)

Fixed submission:
n, k = map(int, input().split())
ans = []
c = (n - 1) * (n - 2) // 2 - k
if c < 0:
    print(-1)
    exit(0)
for i in range(1, n):
    ans.append((0, i))
cnt = 0
flg = 0
for i in range(1, n):
    if flg:
        break
    for j in range(i + 1, n):
        if cnt >= c:
            flg = 1
            break
        ans.append((i, j))
        cnt += 1
print(len(ans))
for a, b in ans:
    print(a + 1, b + 1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = []
c = (n - 1) * (n - 2) // 2 - k
if c < k:
    print(-1)
    exit(1)
for i in range(1, n):
    ans.append((0, i))
cnt = 0
flg = 0
for i in range(1, n):
    if flg:
        break
    for j in range(1, n):
        if i == j:
            continue
        ans.append((i, j))
        cnt += 1
        if cnt >= c:
            flg = 1
            break
print(len(ans))
for a, b in ans:
    print(a, b)
Problem p03029 (python)

Fixed submission:
A, P = map(int, input().split())
P += A * 3
print(P // 2)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort(key=lambda x: x[2])
for i in range(N):
    a[i] = [a[i][0] - a[i][2], a[i][1] - a[i][2], a[i][2]]
d = [int(input()) for _ in range(Q)]
idx = 0
for p in d:
    flg = 1
    while not (a[idx][0] <= p < a[idx][1]):
        if idx + 1 >= N or a[idx][1] <= p < a[idx + 1][0]:
            flg = 0
            break
        idx += 1
    print(a[idx][2] if flg else -1)
Problem p03044 (python)

Fixed submission:
def dfs(graph, start):
    stack = [(start, 0)]
    visited = set()
    li = [0] * N
    while stack:
        d = stack.pop()
        li[d[0] - 1] = d[1] % 2
        for node, w in graph[d[0]]:
            if node not in visited:
                visited.add(node)
                stack.append((node, d[1] + w))
    return li


N = int(input())
g = {i: []for i in range(1, N + 1)}
for i in range(N - 1):
    u, v, w = map(int, input().split())
    w %= 2
    g[u].append((v, w))
    g[v].append((u, w))
for c in dfs(g, 1):
    print(c)

Buggy submission (verdict: Runtime Error):
N=int(input());p=[[]for _ in range(N)]
for _ in range(N-1):u,v,w=map(int,input().split());p[u].append((v,w));p[v].append((u,w))
s=[(1,0)];l=[-1]*N
while s:
 a,w=s.pop()
 l[a-1]=w%2
 for b,c in p[a]:
  if l[b-1]==-1:s.append((b,w+c))
for i in l:print(i)