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

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

for i in range(n):
    a[i] -= 1

memo = [0] * n

index = 0
memo_index = 0
cnt_k = 1
while 1:
    tmp_move_to = a[index]
    if not memo[tmp_move_to]:
        memo[tmp_move_to] = 1
        index = tmp_move_to
        if cnt_k == k:
            print(tmp_move_to + 1)
            exit()
        cnt_k += 1
    else:
        break
k -= cnt_k

kaburi = tmp_move_to
circle = [kaburi]

index = kaburi
while 1:
    if kaburi == a[index]:
        break
    else:
        circle.append(a[index])
        index = a[index]
# print(circle)
print(circle[k % len(circle)] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

n, k = map(int, input().split())
a = deque(list(map(int, input().split())))

r = deque(['1'])

fhinish_roop = 0
index = 0
while not fhinish_roop:
    if str(a[index]) not in r:
        r.append(str(a[index]))
        index = a[index] - 1
    else:
        fhinish_roop = 1
        r_2 = "".join(r)
# print(r, index)
roop_l = r_2.find(str(a[index]))
# print(roop_l)
roop_len = len(r) - roop_l
roop_start_index = roop_l
# print(roop_len)

if k < roop_start_index:
    print(a[k - 1])

else:
    ans = (k - roop_start_index) % roop_len
    # print('ans={}'.format(ans))
    print(r[roop_start_index + ans])

Buggy submission (verdict: Runtime Error):
from _collections import deque

n, k = map(int, input().split())
a = deque(list(map(int, input().split())))

r = deque(['1'])

fhinish_roop = 0
index = 0
while not fhinish_roop:
    if str(a[index]) not in r:
        r.append(str(a[index]))
        index = a[index] - 1
    else:
        fhinish_roop = 1
        r_2 = "".join(r)
# print(r, index)
roop_l = r_2.find(str(a[index]))
# print(roop_l)
roop_len = len(r) - roop_l
roop_start_index = roop_l
# print(roop_len)

if k < roop_start_index:
    print(a[k - 1])

else:
    ans = (k - roop_start_index) % roop_len
    # print('ans={}'.format(ans))
    print(r[roop_start_index + ans])
Problem p02768 (python)

Fixed submission:
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def choose(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, mod-2, mod)
    return x * y % mod


ans = pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod)

while ans < 0:
    ans += mod
print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def choose(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, -2, mod)
    return x * y % mod


ans = pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod)

while ans < 0:
    ans += mod
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ki[a].append([b, i])
ans = [-1] * (n - 1)


# print(ki)


def d(index, color):
    cnt = 1
    for (t, jid) in ki[index]:
        if cnt == color:
            cnt += 1
        ans[jid] = cnt
        d(t, cnt)
        cnt += 1


d(0, 0)
print(max(ans))
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ki[a].append([b, i])
ans = [-1] * (n - 1)


# print(ki)


def d(index, color):
    cnt = 1
    for (t, jid) in ki[index]:
        if cnt == color:
            cnt += 1
        ans[jid] = cnt
        d(t, cnt)
        cnt += 1


d(0, 0)
print(max(ans))
for i in ans:
    print(i)
Problem p02865 (python)

Fixed submission:
n=int(input())
print((n-1)//2)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
d = list(map(int, input().split()))
e = collections.Counter(d)

if d[0] != 0:
    print(0)
    exit()

cntsum = 1
judge_cnt = 0

if e[1] == 0:
    print(0)
    exit()

m = max(e)
e2 = dict(sorted(e.items()))
e3 = list(e2.values())
e4 = list(e2.keys())
#print(e2)
#print(e3)
#print(e4)

tmp=0
for i in e4:
    if i-tmp>=2:
        print(0)
        exit()
    tmp=i
    
cntsum = 1
for i in range(1, len(e3)):
    cntsum *= e3[i - 1] ** e3[i]
print(cntsum)
Problem p02900 (python)

Fixed submission:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def prime_factorize(n):
    p = []
    while n % 2 == 0:
        if 2 not in p:
            p.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in p:
                p.append(f)
            n //= f
        else:
            f += 2
    if n != 1 and n not in p:
        p.append(n)
    return p


a, b = map(int, input().split())
q = prime_factorize(gcd(a, b))
# print(q)
print(len(q) + 1)

Buggy submission (verdict: Runtime Error):
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(x, x % y)


def prime_factorize(n):
    p = []
    while n % 2 == 0:
        if 2 not in p:
            p.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in p:
                p.append(f)
                p //= f
        else:
            f += 2
    if n != 1 and n not in p:
        p.append(n)
    return p


a, b = map(int, input().split())
q = prime_factorize(gcd(a, b))
print(len(q) + 1)
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

ki = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[a].append(b)
    ki[b].append(a)
# print(ki)

cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x


# print(cnt)


def d(y, parent):
    for i in ki[y]:
        if i == parent:
            continue
        cnt[i] += cnt[y]
        d(i, y)


d(1, -1)
print(*cnt[1:])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())

ki = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[a].append(b)
    ki[b].append(a)
# print(ki)

cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x
# print(cnt)


def d(y, parent):
    for k in ki[y]:
        if k == parent:
            continue
        cnt[k] += cnt[y]
        d(k, y)


d(1, -1)
print(*cnt[1:])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())

ki = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[a].append(b)
    ki[b].append(a)
# print(ki)

cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x
# print(cnt)


def d(y, parent):
    for i in ki[y]:
        if i == parent:
            continue
        cnt[i] += cnt[y]
        d(i, y)


d(1, -1)
print(*cnt[1:])
Problem p02972 (python)

Fixed submission:
N = int(input())
c = [0]
a = list(map(int, input().split()))
b = [0 for _ in range(N + 1)]

d = c + a

for i in range(N, 0, -1):
    s = 0
    for j in range(2 * i, N + 1, i):
        s ^= b[j]

    b[i] = (s ^ d[i])

# print(b)
print(b.count(1) if b.count(1) else 0)
if len(b):
    for i in range(1, len(b)):
        if b[i] != 0:
            print(i, end=' ')
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
c = [0]
d = c + a
s = [0 for _ in range(n + 1)]
 
for i in range(n, 0, -1):
    w = 0
    for j in range(2 * i, n + 1, i):
        w ^= s[j]
    s[i] = w ^ d[i]
    
print(b.count(1) if b.count(1) else 0)
for i in range(1, n + 1):
    if s[i] != 0:
        print(s[i], end=' ')
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())
a = []

data = 2019

if r - l + 1 >= 2019:
    print(0)
    exit()

else:
    for i in range(l, r + 1):
        for j in range(i+1, r + 1):
            data = min(data, i * j % 2019)

print(data)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
a = []
if r - l >= 2019:
    print(0)
else:
    for i in range(r - l + 1):
        a.append((l + i) % 2019)
# print(a)
a.sort()
print(a[0] * a[1])
Problem p03049 (python)

Fixed submission:
N = int(input())
a = [str(input()) for i in range(N)]
cnt = 0
tBeA = 0
tBeNA = 0
tNBeA = 0
for i in range(N):
    flag = False
    if a[i][0] == "B":
        if a[i][-1] == "A":
            tBeA += 1
        else:
            tBeNA += 1
    else:
        if a[i][-1] == "A":
            tNBeA += 1

    for j in range(len(a[i])):
        # print(a[i][j])
        if a[i][j] == "B" and flag:
            cnt += 1
        flag = False

        if a[i][j] == "A":
            flag = True

print(
    cnt + min(tBeNA, tNBeA) if tBeA == 0 else cnt + min(tBeNA, tNBeA) + tBeA if tNBeA + tBeNA > 0 else cnt + min(tBeNA,
                                                                                                                 tNBeA) + tBeA - 1)

Buggy submission (verdict: Runtime Error):
tBeA = 0
tBeNA = 0
tNBeA = 0
for i in range(N):
    flag = False
    if a[i][0] == "B":
        if a[i][-1] == "A":
            tBeA += 1
        else:
            tBeNA += 1
    else:
        if a[i][-1] == "A":
            tNBeA += 1

    for j in range(len(a[i])):
        # print(a[i][j])
        if a[i][j] == "B" and flag:
            cnt += 1
        flag = False

        if a[i][j] == "A":
            flag = True

print(
    cnt + min(tBeNA, tNBeA) if tBeA == 0 else cnt + min(tBeNA, tNBeA) + tBeA if tNBeA + tBeNA > 0 else cnt + min(tBeNA,
                                                                                                                 tNBeA) + tBeA - 1)
Problem p03086 (python)

Fixed submission:
S = input()

cnt = 0
a = []
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':
        cnt += 1
        if i == len(S) - 1:
            a.append(cnt)
    else:
        lenflag = False
        a.append(cnt)
        cnt = 0
print(max(a))

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

cnt = 0
a = []
for i in S:
    if i == 'A' or i == 'T' or i == 'G' or i == 'C':
        cnt += 1
    else:
        a.append(cnt)
        cnt = 0
print(max(a))
Problem p03238 (python)

Fixed submission:
N=int(input())
if N == 1:
    print("Hello World")
if N == 2:
    A=int(input())
    B=int(input())
if N == 2:
    print(A+B)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
C=A+B
if N == 1:
    print('Hello World')
if N == 2:
    print(C)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
C=A+B
if N==1:
    print("Hello World")
if N==2:
    print(C)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
if N==1:
    print("Hello World")
else:
    print(A+B)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
if N==1:
    print("Hello World")
else:
    print(A+B)
Problem p03324 (python)

Fixed submission:
D,N=map(int,input().split())
S=0
if N==100:
    S=1
print(100**D*(N+S))

Buggy submission (verdict: Runtime Error):
D,N=map(int,input().split())
S=0
if D==0:
    if N=100:
        S=1
    print(N+S)
elif D==1:
    print(100*N)
else:
    print(10000*N)
Problem p03337 (python)

Fixed submission:
A,B=map(int,input().split())
C=[]
C.append(A+B)
C.append(A-B)
C.append(A*B)
print(max(C))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(input())
ans=0
for i in range(N-1):
    a=set(S[:i+1])
    b=set(S[i+1:])
    ans=max(ans,len(a&b))
print(ans)
Problem p03338 (python)

Fixed submission:
N=int(input())
S=list(input())
ans=0
for i in range(N-1):
    a=set(S[:i+1])
    b=set(S[i+1:])
    ans=max(ans,len(a&b))
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(input())
for i in range(N-1):
    a=set(S[:i+1])
    b=set(S[i+1:])
    ans=max(ans,len(a&b))
print(ans)
Problem p03407 (python)

Fixed submission:
A,B,C=map(int,input().split())
print('Yes'if A+B>=C else "No")

Buggy submission (verdict: Runtime Error):
N=int(input())
s = [input() for i in range(N)]
M=int(input())
t = [input() for i in range(M)]
tmp=[0]
for i in range(N):
    point=0
    point+=s.count(s[i])
    point-=t.count(s[i])
    tmp.append(point)
print(max(tmp))
Problem p03415 (python)

Fixed submission:
a=['']*3
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Buggy submission (verdict: Runtime Error):
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Buggy submission (verdict: Runtime Error):
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Buggy submission (verdict: Runtime Error):
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
x=[int(i) for i in input().split()]
cnt=0
while(1):
    for i in range(N):
        if x[i]%2 != 0:
            print(cnt)
            sys.exit()
    tmp=[i//2 for i in x]
    x=tmp
    cnt+=1
Problem p03501 (python)

Fixed submission:
N,A,B=map(int,input().split())
print(B if N*A>B else N*A )

Buggy submission (verdict: Runtime Error):
N=(input())
print("Yes"if int(N)%(int(N[0])+int(N[1]))==0 else"No")
Problem p03502 (python)

Fixed submission:
N=(input())
sum=0
for i in range(len(N)):
    sum+=int(N[i])

print("Yes"if int(N)%sum==0 else"No")

Buggy submission (verdict: Runtime Error):
N=(input())
print("Yes"if int(N)%(int(N[0])+int(N[1]))==0 else"No")

Buggy submission (verdict: Runtime Error):
N=(input())
print("Yes"if int(N)%(int(N[0])+int(N[1]))==0 else"No")
Problem p03605 (python)

Fixed submission:
a=input()
print('Yes'if "9"in a else 'No')

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
a = [int(input()) for _ in range(n)]
b = collections.Counter(a)

cnt = 0
for v in b.values():
    if v % 2 == 1:
        cnt += 1

print(cnt)
Problem p03672 (python)

Fixed submission:
s=list(input())
while(1):
    t=int(len(s)/2)
    if len(s)==1:
        print(s)
        break
    s.pop(-1)
    if s[:t]==s[t:]:
        print(len(s))
        break

Buggy submission (verdict: Runtime Error):
s=list(input())
while(1):
    if len(s)==1:
        print(s)
        break
    s.pop(-1)
    if s[:t]==s[t:]:
        print(len(s))
        break
    t=int(len(s)/2)
Problem p03679 (python)

Fixed submission:
x,a,b=map(int,input().split())
if b<=a:
    print("delicious")
elif b-a<=x:
    print("safe")
else:
    print("dangerous")

Buggy submission (verdict: Runtime Error):
import math

n, m = map(int, input().split())
w = 10 ** 9 + 7
if n + 1 == m or m + 1 == n:
    print(math.factorial(min(n, m)) ** 2 * max(n, m) % w)
elif n == m:
    print(2 * math.factorial(n) ** 2 % w)
else:
    print(0)
Problem p03998 (python)

Fixed submission:
a=list(input())
b=list(input())
c=list(input())
read=a[0]

while(1):
    if read=='a':
        try:
            read=a.pop(0)
        except:
            f='A'
            break
    if read=='b':
        try:
            read=b.pop(0)
        except:
            f='B'
            break
    if read=='c':
        try:
            read=c.pop(0)
        except:
            f='C'
            break
print(f)

Buggy submission (verdict: Runtime Error):
a=list(input())
b=list(input())
c=list(input())
read=a[0]
a.pop(0)

while(1):
    if read=='a':
        if len(a)==0:
            break
        read=a[0]
        f='A'
        a.pop(0)
        
    elif read=='b':
        if len(b)==0:
            break
        read=b[0]
        f='B'
        b.pop(0)
        
    elif read=='c':
        if len(c)==0:
            break
        read=c[0]
        f='C'
        c.pop(0)
        
print(f)
Problem p03109 (python)

Fixed submission:
x, y, z=list(map(int, input().split("/")))
if y>=5:
  print("TBD")
else:
  print("Heisei")

Buggy submission (verdict: Runtime Error):
x, y, z=list(map(int, input().split(/)))
if y>=5:
  print("TBD")
else:
  print("Heisei")
Problem p03359 (python)

Fixed submission:
x=list(map(int,input().split()))
a=x[0]
b=x[1]
if a<=b:
  print(a)
else:
  print(a-1)

Buggy submission (verdict: Runtime Error):
x=list(map(int,input().split()))
a=x[0]
b=x[1]
if a<=b:
  print(a)
else:
  priint(a-1)
Problem p02642 (python)

Fixed submission:
from collections import Counter
n = int(input())
A = sorted(map(int, input().split()))
M = A[-1]
c = Counter(A)
s = set()
ans = 0
for a in A:
    if a in s:
        continue
    if c[a] == 1:
        ans += 1
    i = 1
    while a * i <= M:
        s.add(a * i)
        i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    import sympy
    from collections import Counter
    n = int(input())
    A = list(map(int, input().split()))
    s = set(A)
    c = Counter(A)
    cnt = 0
    for a in A:
        if c[a] > 1:
            continue
        else:
            d = set(sympy.divisors(a))
            if len(d & s) == 1:
                cnt += 1
    print(cnt)
main()
Problem p02647 (python)

Fixed submission:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(k):
        imos = [0] * (n + 1)
        for i in range(n):
            imos[max(0, i - a[i])] += 1
            imos[min(n, i + a[i] + 1)] -= 1
        for i in range(1, n):
            imos[i] += imos[i-1]
        imos.pop()
        a = imos
        if min(a) == n:
            break 
    print(*a)
main()

Buggy submission (verdict: Runtime Error):
def main():
    n, K = map(int, input().split())
    a = list(map(int, input().split()))
    cnt = a.count(n)
    for k in range(min(k, 100)):
        an = [0] * n
        for i in range(n):
            if an[i] < n:
                an[i] += 1
            for j in range(1, a[i]+1):
                if i - j >= 0 and an[i-j] < n:
                    an[i-j] += 1
                    if an[i-j] == n:
                        cnt += 1
                if i + j < n and an[i+j] < n:
                    an[i+j] += 1
                    if an[i+j] == n:
                        cnt += 1
        else:
            a = an
            if cnt == n:
                break
    print(*a)
main()
Problem p02665 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    if a[0] == 1:
        print(1)
    else:
        print(-1)
else:
    req = [0] * n
    req[-1] = a[-1]
    for i in range(2, n+1):
        req[-i] = req[-(i-1)] + a[-i]
    l = [0] * (n + 1)
    l[0] = 1
    for i in range(1, n+1):
        M = (l[i-1] - a[i-1]) * 2
        l[i] = min(M, req[i-1])
    if l[-1] < a[-1]:
        print(-1)
    else:
        print(sum(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
req = [0] * n
req[-1] = a[-1]
for i in range(2, n+1):
    req[-i] = req[-(i-1)] + a[-i]
l = [0] * (n + 1)
l[0] = 1
for i in range(1, n+1):
    M = (l[i-1] - a[i-1]) * 2
    l[i] = min(M, req[i-1])
if l[-1] < a[-1]:
    print(-1)
else:
    print(sum(l))
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(m)]
N = [None] * n
for s, c in L:
    if N[s - 1] is None:
        N[s - 1] = c
    elif N[s - 1] == c:
        continue
    else:
        print(-1)
        exit()

if n == 1:
    if N[0] is None:
        N[0] = 0
    print(*N)
    exit()
elif N[0] == 0:
    print(-1)
    exit()

for i in range(n):
    if i == 0 and N[0] is None:
        N[0] = 1
    elif N[i] is None:
        N[i] = 0
print(*N, sep='')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
N = [None] * n
for s, c in L:
    if N[s - 1] is None:
        N[s - 1] = c
    elif N[s - 1] == c:
        continue
    else:
        print(-1)
        exit()
for i in range(n):
    if N[i] is None:
        N[i] = 0
if N[0] == 0:
    print(-1)
else:
    print(*N, sep='')
Problem p02797 (python)

Fixed submission:
n, k, s = map(int, input().split())
L = [0] * n
for i in range(n):
    if i < k:
        L[i] = s
    else:
        if s != 10 ** 9:
            L[i] = s + 1
        else:
            L[i] = s - 1
print(*L)

Buggy submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
L = [0] * n
for i in range(n):
    if i < k:
        L[i] = s
    else:
        if s != 10 ** 9
            L[i] = s + 1
        else:
            L[i] = s - 1
print(*L)
Problem p02838 (python)

Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

Buggy submission (verdict: Runtime Error):
n = int(input())
dig = 50
A = list(map(lambda x:bin(int(x))[2:].zfill(dig), input().split()))
MOD = 10 ** 9 + 7
ans = 0
d = {i: [0, 0] for i in range(dig)}
for a in A:
    for i in range(len(a)):
        if a[-(i+1)] == '0':
            d[i][0] += 1
        else:
            d[i][1] += 1
for i in range(dig):
    ans += d[i][0] * d[i][1] * (2 ** i)
    ans %= MOD
print(ans)
Problem p02845 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
C = [0] * (n + 1)
C[0] = 3
ans = 1
for i in a:
    ans = ans * C[i] % MOD
    C[i] -= 1
    C[i+1] += 1
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
C = [0] * n
C[0] = 3
ans = 1
for i in a:
    ans = ans * C[i] % MOD
    C[i] -= 1
    C[i+1] += 1
print(ans % MOD)
Problem p02850 (python)

Fixed submission:
n = int(input())
L = []
d = {}
for _ in range(n-1):
    a, b = map(int, input().split())
    L.append((a, b))
    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)
k = 0
for i in d.keys():
    tmp_k = len(d[i]) if i == 1 else len(d[i]) + 1
    k = max(k, tmp_k)
print(k)
key = sorted(d.keys())
dd = {1: 0}
ans = {}
for i in key:
    v = d[i]
    cnt = 1
    for j in v:
        if cnt != dd[i]:
            c = cnt
            cnt += 1
        else:
            c = cnt + 1
            cnt += 2
        ans[(i, j)] = c
        dd[j] = c
for a, b in L:
    print(ans[(a, b)])

Buggy submission (verdict: Runtime Error):
n = int(input())
L = []
d = {}
for _ in range(n-1):
    a, b = map(int, input().split())
    L.append((a, b))
    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)
k = 0
for i in d.keys():
    tmp_k = len(d[i]) if i == 1 else len(d[i]) + 1
    k = max(k, tmp_k)
print(k)
dd = {1: 0}
ans = {}
for i, v in d.items():
    cnt = 1
    for j in v:
        if cnt != dd[i]:
            c = cnt
            cnt += 1
        else:
            c = cnt + 1
            cnt += 2
        ans[(i, j)] = c
        dd[j] = c
for a, b in L:
    print(ans[(a, b)])

Buggy submission (verdict: Runtime Error):
n = int(input())
d = {}
k = 0
for _ in range(n-1):
    a, b = map(int, input().split())
    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)
for i in d.keys():
    tmp_k = len(d[i]) if i == 1 else len(d[i]) + 1
    k = max(k, tmp_k)
print(k)
dd = {1: 0}
for i, v in d.items():
    cnt = 1
    for j in v:
        if cnt != dd[i]:
            c = cnt
            cnt += 1
        else:
            c = cnt + 1
            cnt += 2
        print(c)
        dd[j] = c