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

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

ans=0
A.sort()

f=[0]*1000005

for i in A:
    f[i]+=1

for i in range(1,1000001,1):
    if f[i]==0:
        continue
    j=i+i
    while j<=1000000:
        f[j]+=f[i]
        j=j+i

for i in A:
    if f[i]==1:
        ans+=1


print(ans)

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

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

ans=0
A.sort()

f=[0]*1000005

for i in A:
    f[i]+=1

for i in range(1,1000001,1):
    if f[i]==0:
        continue
    j=i+i
    while j<=1000000:
        f[j]+=f[i]
        j=j+i

for i in A:
    if f[i]==1:
        ans+=1


print(ans)
Problem p02818 (python)

Fixed submission:
A,B,K=map(int,input().split())

if K<A:
    ans1=A-K
    ans2=B
else:
    ans1=0
    ans2=max(A+B-K,0)

print(ans1,ans2)

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())

if K<A:
    ans1=A-K
else:
    ans1=0
    ans2=max(A+B-K,0)

print(ans1,ans2)
Problem p03578 (python)

Fixed submission:
from collections import defaultdict
n= int(input())
D=list(map(int,input().split()))

m=int(input())
T=list(map(int,input().split()))

dicta=defaultdict(lambda:0)
dictb=defaultdict(lambda:0)

for i in range(n):
    dicta[D[i]]+=1

for i in range(m):
    dictb[T[i]]+=1


ans="YES"
for i in range(m):
    if dicta[T[i]]<dictb[T[i]]:
        ans="NO"
        break

print(ans)

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

m=int(input())
T=list(map(int,input().split()))

cnt=[0]*1000000010

for i in range(n):
    cnt[D[i]]+=1

ans="YES"
for i in range(m):
    cnt[T[i]]-=1
    if cnt[T[i]]<0:
        ans="NO"
        break

print(ans)
Problem p03612 (python)

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

ans=0
for i in range(N-1):
    if p[i]==i+1:
        p[i],p[i+1]=p[i+1],p[i]
        ans+=1

if p[N-1]==N:
    ans+=1
print(ans)

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

ans=0
for i in range(N):
    if p[i]==i+1:
        p[i],p[i+1]=p[i+1],p[i]
        ans+=1
print(ans)
Problem p03627 (python)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

cnt=Counter(a)
edge=[0,0]

for i in cnt:
    if cnt[i]>=4:
        edge.append(i)
    if cnt[i]>=2:
        edge.append(i)

edge.sort(reverse=True)
print(edge[0]*edge[1])

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

c=[0]*(max(a)+10)

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

short_edge=0
long_edge=0
for i in range(len(c)):
    if c[i]>=4:
        long_edge=i
        short_edge=i
    elif c[i]>=2:
        short_edge=long_edge
        long_edge=i
    else:
        pass

print(long_edge*short_edge)

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

c=[0]*(max(a)+10)

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

short_edge=0
long_edge=0
for i in range(len(c)):
    if c[i]>=4:
        long_edge=i
        short_edge=i
    elif c[i]>=2:
        short_edge=long_edge
        long_edge=i
    else:
        pass

print(long_edge*short_edge)
Problem p02628 (python)

Fixed submission:
n, k,  =map(int, input().split())
cost = 0
price = list(map(int, input().split()))
        
price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
price = []
cost = 0
for p in range(n):
        p = int(input())
        price.append(p)

price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(nput())
price = []
cost = 0
for p in range(n):
        p = int(input())
        price.append(p)

price.sort()
for  p in price:
        cost += p

print(price)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(nput())
price = []
cost = 0
for p in range(n):
        p = int(input())
        price.append(p)

price.sort()
for  p in price:
        cost += p

print(price)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(nput())
price = []
cost = 0
for p in range(n + 1):
        p = int(input())
        price.append(p)

price.sort()
for  p in price:
        cost += p

print(price)

Buggy submission (verdict: Runtime Error):
n = input()
k = input()
price = []
cost = 0
for p in range(n + 1):
        p = int(input())
        price.append(p)

price.sort(reverse = True)
for  p in price:
        cost += p

print(price)
Problem p03361 (python)

Fixed submission:
h, w = map(int, input().split())
src = [input() for i in range(h)]

ans = []
for row in src:
        ans.append(list(row))

dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                if src[x][y] == "#":
                        flag = 0
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[x + dx][y + dy] == "#":
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
src = [input() for i in range(h)]

ans = []
for row in src:
        ans.append(list(row))

flag = 0
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                else:
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[x + dx][y + dx] == "#":
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
src = [input() for i in range(h)]

ans = []
for row in src:
        ans.append(list(row))

flag = 0
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                else:
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[y +dy][x+dx] == "#":
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")
Problem p03632 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
if a < c:
        if b < c:
                print(0)
        if c <= b <= d:
                print(abs(b-c))
        if d < b:
                print(abs(d-c))
if c <= a:
        if d < a:
                print(0)
        if a <= d <= b:
                print(abs(d-a))
        if b < d:
                print(abs(b-a))

Buggy submission (verdict: Runtime Error):
 a, b, c, d = map(int, input().split())
print(max(min(b, d) - max(a, c), 0))
Problem p02618 (python)

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = [None] * D
for i in range(D):
    S[i] = list(map(int, input().split()))
lasts = [0] * 26
score = 0
for d in range(D):
    bs = None
    ba = None
    for t in range(26):
        s = S[d][t]
        s -= sum(C[i] * (d+1-l) for i, l in enumerate(lasts) if i != t)
        if bs is None or s > bs:
            bs = s
            ba = t
    score += bs
    lasts[ba] = d
    print(ba+1)

Buggy submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = [None] * D
for i in range(D):
    S[i] = list(map(int, input().split()))
lasts = [0] * 26
score = 0
for d in range(D):
    bs = 0
    ba = None
    for t in range(26):
        s = S[d][t]
        s -= sum(C[i] * (d+1-l) for i, l in enumerate(lasts) if i != t)
        if s > bs:
            bs = s
            ba = t
    score += bs
    lasts[ba] = d
    print(ba+1)
Problem p02855 (python)

Fixed submission:
H, W, K = map(int, input().split())

result = list()

l = list()
kk = 0
nls = list()
for hh in range(H):
    ll = input()
    s = [i+1 for i, x in enumerate(ll) if x == '#']
    ln = len(s)
    nl = list()
    if ln == 0:
        nls.append(hh)
    elif ln == 1:
        kk += 1
        nl = [kk] * W
    else:
        pre = 0
        for i, p in enumerate(s):
            kk += 1
            pp = p - (s[i-1] if i > 0 else 0)
            nl.extend([kk] * (1 if pp == 0 else pp))
            pre = p
    if len(nl) < W:
        nl.extend([kk] * (W - len(nl)))
    l.append(nl)

for i in nls:
    if i > 0 and l[i-1] not in nls:
        l[i] = l[i-1]
    else:
        for j in range(i + 1, H):
            if j in nls:
                continue
            l[i] = l[j]
            break

for h in l:
    print(' '.join(map(str, h)))

Buggy submission (verdict: Runtime Error):
H, W, K = map(int, input().split())

result = list()

l = list()
kk = 0
nls = list()
for hh in range(H):
    ll = input()
    s = [(i, x) for i, x in enumerate(ll) if x == '#']
    ln = len(s)
    nl = list()
    if ln == 0:
        nls.append(hh)
    elif ln == 1:
        kk += 1
        nl = [kk] * W
    else:
        for p, _ in s:
            kk += 1
            nl.extend([kk] * (1 if p == 0 else p))
    l.append(nl)

for i in nls:
    for j in range(W):
        l[i].append(l[(i - 1 if i > 0 else i + 1)][j])

for h in l:
    print(' '.join(map(str, h)))
Problem p02927 (python)

Fixed submission:
while True:
    MAPS = {'22': 4, '23': 6, '24': 8, '25': 10, '26': 12, '27': 14, '28': 16, '29': 18, '32': 6, '33': 9, '34': 12, '35': 15, '36': 18, '37': 21, '38': 24, '39': 27, '42': 8, '43': 12, '44': 16, '45': 20, '46': 24, '47': 28, '48': 32, '49': 36, '52': 10, '53': 15, '54': 20, '55': 25, '56': 30, '57': 35, '58': 40, '59': 45, '62': 12, '63': 18, '64': 24, '65': 30, '66': 36, '67': 42, '68': 48, '69': 54, '72': 14, '73': 21, '74': 28, '75': 35, '76': 42, '77': 49, '78': 56, '79': 63, '82': 16, '83': 24, '84': 32, '85': 40, '86': 48, '87': 56, '88': 64, '89': 72, '92': 18, '93': 27, '94': 36, '95': 45, '96': 54, '97': 63, '98': 72, '99': 81}
    try:
        M, D = map(int, input().split())
        result = 0
        if D >= 22:
            for i in range(22, D+1):
                i = str(i)
                mm = MAPS[i] if i in MAPS else None
                if mm is not None and mm <= M:
                    result += 1
        print(result)

    except EOFError:
        break

Buggy submission (verdict: Runtime Error):
while True:
    try:
        M, D = map(int, input().split())
        result = 0
        if D >= 22:
            for i in range(22, D+1):
                i = str(i)
                mm = MAPS[i] if i in MAPS else None
                if mm is not None and mm <= M:
                    result += 1
        print(result)

    except EOFError:
        break
Problem p02761 (python)

Fixed submission:
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
if m > 0:
    s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 0 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

ans = 0
if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

ans = 0

for i in range(n):
    ans += arr[i]*(10**(n-i-1))

if arr[0] == 0:
    ans += 10**(n-1)

print(ans)
Problem p02647 (python)

Fixed submission:
import math
n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    for k in range(1,n):
        a1[k]=a1[k-1]+a1[k]
    a=a1[:n]
    a1=[0]*(n+1)
print(' '.join([str(n) for n in a]))

Buggy submission (verdict: Runtime Error):
import math
import numpy

n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    a1=numpy.cumsum(a1)
    a=a1[:n]
    a1=[0]*(n+1)
print(' '.join([str(n) for n in a]))

Buggy submission (verdict: Runtime Error):
import math
n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    for k in range(1,n):
        a1[k]=a1[k-1]+a1[k]
    a=a1[:n]
    a1=[0]*n
print(' '.join([str(n) for n in a]))
Problem p02804 (python)

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

MOD = 1000000007

factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))

def combi(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % MOD

max_sum=0
min_sum=0

for i in range(k-1,n):
    t = combi(i,k-1)
    max_sum+=a[i]*t
    max_sum%=MOD
    min_sum+=a[n-i-1]*t
    min_sum%=MOD
if max_sum-min_sum<0:
    max_sum+=MOD
print(max_sum-min_sum)

Buggy submission (verdict: Runtime Error):
n , k = map(int, input().split())
a = list(map(int,input().split()))
a.sort()

N = 1000000007

def combi(n,r,N):
    if n<r or n<0 or r<0:
        ans = 0
        return ans
    if n==r:
        ans = 1
        return ans
    r= min(r, n-r)
    ans = f[n]*rf[r]*rf[n-r]%N
    return ans

f = [0]*(n+1)
f[1]=1

for i in range(2,10**5+1):
    f[i] = f[i-1]*i

rf = [0]*(n+1)

for i in range(1,10**5+1):
    rf[i] = pow(f[i],N-2,N)

max_sum=0
min_sum=0

for i in range(k-1,n):
    max_sum+=a[i]*combi(i,k-1,N)
    max_sum%=N
for i in range(n-k+1):
    min_sum+=a[i]*combi(n-i-1,k-1,N)
    min_sum%=N
if max_sum-min_sum<0:
    max_sum+=N
print(max_sum-min_sum)
Problem p02814 (python)

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

def gcd(num1,num2):
    r=1
    while r>0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    gcd1=gcd(num1,num2)
    return num1*num2//gcd1

lcm1=a[0]//2
lcm2=a[0]

for i in range(1,n):
    t=a[i]
    lcm1=lcm(lcm1,t//2)
    lcm2=lcm(lcm2,t)
    ta=max(t//2,lcm1)
    tb=min(t//2,lcm1)
    if ta!=tb and ta//tb%2==0:
        lcm1=0
        lcm2=0
        break

if lcm1!=0:
    ans1=m//lcm1
    ans2=m//lcm2
    ans=ans1-ans2
else:
    ans=0

print(ans)

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

def gcd(num1,num2):
    r=1
    while r>0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    gcd1=gcd(num1,num2)
    return num1*num2//gcd1

lcm1=a[0]//2
lcm2=a[0]

for i in range(1,n):
    t=a[i]
    ta=max(t//2,lcm1)
    tb=min(t//2,lcm1)
    if ta!=tb and ta//tb%2==0:
        lcm1=0
        lcm2=0
    lcm1=lcm(lcm1,t//2)
    lcm2=lcm(lcm2,t)


if lcm1!=0:
    ans1=m//lcm1
    ans2=m//lcm2
    ans=ans1-ans2
else:
    ans=0

print(ans)
Problem p02838 (python)

Fixed submission:
import numpy as np
N = 10**9+7
n = int(input())
a = np.array(input().split(), np.int64)

ans = 0

po = 1
for i in range(61):
    bit = (a>>i) & 1
    s=np.count_nonzero(bit)
    ans+=s*(n-s)%N*po
    ans%=N
    po*=2
    po%=N
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = 10**9+7
n = int(input())
a = list(map(int,input().split()))

ans = 0

a1 = max(a)
if a1 == 0:
    a1=2
ma = int(math.log2(a1))
if ma<0:
    ma=0
for i in range(ma+2):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*pow(2,i,N)
    ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = 10**9+7
n = int(input())
a = list(map(int,input().split()))

ans = 0

ma = int(math.log2(max(a)))
if ma<0:
    ma=0
for i in range(ma+2):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*pow(2,i,N)
    ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range(int(math.log2(max(a)))+2):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*(2**i)
    ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range(int(math.log2(max(a)))+2):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*(2**i)
    ans%=10**9+7
print(ans)
Problem p02903 (python)

Fixed submission:
h,w,a,b = map(int, input().split())

s='0'*a
s+='1'*(w-a)
for i in range(b):
    print(s)
s='1'*a
s+='0'*(w-a)
for i in range(h-b):
    print(s)

Buggy submission (verdict: Runtime Error):
from math import ceil
h,w,a,b = map(int, input().split())
se = w//a
if b>ceil(h/se):
    print('No')
else:
    for i in range(h):
        s='0'*(i%se)*a
        s+='1'*a
        s+='0'*(w-a-(i%se)*a)
        print(s)
Problem p02936 (python)

Fixed submission:
from collections import deque

n , q = map(int, input().split())
r = [[]for i in range(n)]
s = [0]*n
v = [0]*n
for i in range(n-1):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(q):
    p , x = map(int, input().split())
    s[p-1]+=x
d= deque()
d.append(0)
def bfs(now):
    v[now]=1
    while d:
        i = d.popleft()
        for j in r[i]:
            if v[j]==0:
                s[j]+=s[i]
                v[j]=1
                d.append(j)
    return
bfs(0)
print(' '.join(list(map(str,s))))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
n , q = map(int, input().split())
r = [[]for i in range(n)]
s = [0]*n
v = [0]*n
for i in range(n-1):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(q):
    p , x = map(int, input().split())
    s[p-1]+=x

def dfs(now):
    v[now]=1
    for i in r[now]:
        if v[i]==0:
            s[i]+=s[now]
            dfs(i)
    return
dfs(0)
print(' '.join(list(map(str,s))))

Buggy submission (verdict: Runtime Error):
n , q = map(int, input().split())
r = [[]for i in range(n)]
s = [0]*n
v = [0]*n
for i in range(n-1):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(q):
    p , x = map(int, input().split())
    s[p-1]+=x

def dfs(now):
    v[now]=1
    for i in r[now]:
        if v[i]==0:
            s[i]+=s[now]
            dfs(i)
    return
dfs(0)
print(' '.join(list(map(str,s))))

Buggy submission (verdict: Runtime Error):
n , q = map(int, input().split())
r = [[]for i in range(n)]
s = [0]*n
v = [0]*n
for i in range(n-1):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(q):
    p , x = map(int, input().split())
    s[p-1]+=x

def dfs(now):
    v[now]=1
    for i in r[now]:
        if v[i]==0:
            s[i]+=s[now]
            dfs(i)
dfs(0)
print(' '.join(list(map(str,s))))
Problem p03044 (python)

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


n = int(input())
col = [0]*n
next = [[] for i in range(n)]
d = [float('INF')]*n
d[0]=0

def dfs(now,parent):
    for next1,w1 in next[now]:
        if next1 == parent:
            continue
        elif d[next1]==float('INF'):
            d[next1]=d[now]+w1
            dfs(next1,now)

for i in range(n-1):
    u , v , w = map(int, input().split())
    next[u-1].append((v-1,w))
    next[v-1].append((u-1,w))

dfs(0,-1)

for i in range(n):
    if d[i]%2==0:
        print('0')
    else:
        print('1')

Buggy submission (verdict: Runtime Error):
n = int(input())
col = [0]*n
next = [[] for i in range(n)]
d = [float('INF')]*n
d[0]=0

def dfs(now):
    for next1,w1 in next[now]:
        if d[next1]>d[now]+w1:
            d[next1]=d[now]+w1
            dfs(next1)

for i in range(n-1):
    u , v , w = map(int, input().split())
    next[u-1].append((v-1,w))
    next[v-1].append((u-1,w))

dfs(0)

for i in range(n):
    if d[i]%2==0:
        print('0')
    else:
        print('1')
Problem p03231 (python)

Fixed submission:
n , m = map(int, input().split())
s = input()
t = input()

def gcd(num1,num2):
    r=1
    while r!=0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    return num1*num2//gcd(num1,num2)

g1 = lcm(n,m)
g2 = lcm(g1//n,g1//m)

for i in range(g1//g2):
    if s[g2*n*i//g1]!=t[g2*m*i//g1]:
        print('-1')
        exit()
print(g1)

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

def gcd(num1,num2):
    r=1
    while r!=0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    return num1*num2//gcd(num1,num2)

g1 = lcm(n,m)
g2 = lcm(g1//n,g1//m)

s*=g1//n
t*=g1//m

for i in range(g1//g2):
    if s[g2*i]!=t[g2*i]:
        print('-1')
        exit()
print(g1)

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

def gcd(num1,num2):
    r=1
    while r!=0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    return num1*num2//gcd(num1,num2)

g1 = lcm(n,m)
g2 = lcm(g1//n,g1//m)

s*=g1//n
t*=g1//m

for i in range(n//g2):
    if s[g2*i]!=t[g2*i]:
        print('-1')
        exit()
print(g1)
Problem p03309 (python)

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    x[i]-=i+1
x.sort()
if n%2==0:
    b = (x[n//2-1]+x[n//2])//2
else:
    b = x[(n-1)//2]
ans=0
for i in range(n):
    ans+=abs(x[i]-b)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    x[i]-=i+1
x.sort()
l=len(x)
if n%2==0:
    b = int((x[l/2-1]+x[l/2])/2)
else:
    b = x[int((l-1)/2)]
ans=0
for i in range(n):
    ans+=abs(x[i]-b)
print(ans)