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

Fixed submission:
from fractions import gcd

a, b, c, d = map(int, input().split())


def lcm(x, y):
    if gcd(x, y) == 0:
        return x * y
    return x * y // gcd(x, y)


def cantdiv(x):
    return x - x // c - x // d + x // lcm(c, d)


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    if math.gcd(x, y) == 0:
        return x * y
    return x * y // gcd(x, y)


def cantdiv(x):
    return x - x // c - x // d + x // lcm(c, d)


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    if math.gcd(x, y) == 0:
        return x * y
    return x * y / gcd(x, y)


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    if math.gcd(x, y) == 0:
        return x * y
    return x * y / math.gcd(x, y)


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    if math.gcd(x, y) == 0:
        return x*y
    return x * y / math.gcd(x, y)


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    return x * y / math.gcd(x, y)


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    return x * y / math.gcd(x, y)


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())


def lcm(x, y):
    return x * y / gcd(x, y)


def gcd(x, y):
    r = x % y
    while r != 0:
        x = y
        y = r
        r = x % y
    return r


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))
Problem p03060 (python)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print(ans)

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

N = int(input())
VS = input().split()
CS = input().split()

V = [int(v) for v in VS]
C = [int(v) for v in CS]

R = []


for i in range(N-1):
    R.append(V[i]/C[i])

RR = reversed(R)
RA = np.argsort(RR)

best = 0

Vsum=0
Csum=0

for r in RA:
    Vsum += V[r]
    Csum += C[r]

    if (Vsum-Csum) >= best:
        best = Vsum-Csum

print(best)

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

N = int(input())
VS = input().split()
CS = input().split()

V = [int(v) for v in VS]
C = [int(v) for v in CS]

R = [N]


for i in range(N-1):
    R[i] = V[i]/C[i]

RA = np.argsort(-R)

best = 0

Vsum=0
Csum=0

for r in RA:
    Vsum += V[i]
    Csum += C[i]

    if (Vsum-Csum) >= best:
        best = Vsum-Csum

print(best)
Problem p03089 (python)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()

ans = []

for i in range(n):
    for j in range(len(b))[::-1]:
        if b[j] == j + 1:
            ans.append(b[j])
            del b[j]
            break
        if j == 0:
            print(-1)
            exit()

print(' '.join([str(_) for _ in reversed(ans)]))

Buggy submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()



ans = []

for i in range(n):
    for j in range(b):
        if b[j] == j+1:
            ans.append(b[j])
            del b[j]
            continue
        print(-1)
        exit()

print(' '.join(reversed(ans)))
Problem p03146 (python)

Fixed submission:
s = int(input())

log = set()
log.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

    if s in log:
        print(i+2)
        break

    log.add(s)

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

log = set()
set.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

    if s in log:
        print(i+2)
        break

    log.add(s)
Problem p03212 (python)

Fixed submission:
import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
sys.setrecursionlimit(10**10)



def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
sys.setrecursionlimit(n)



def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))
Problem p03251 (python)

Fixed submission:
ni = lambda: int(input())
nl = lambda: list(map(int, input().split()))
nm = lambda: map(int, input().split())

n, m, x, y = nm()
xmax = max(nl()+[x])
ymin = min(nl()+[y])

if xmax < ymin:
    print('No War')
else:
    print('War')

Buggy submission (verdict: Runtime Error):
ni = lambda: int(input())
nl = lambda: list(map(int, input().split()))
nm = lambda: map(int, input().split())

n, m, x, y = nm()
xmax = max(nl())+[x]
ymin = min(nl())+[y]

if xmax < ymin:
    print('No War')
else:
    print('War')
Problem p03407 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a+b>=c:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split())
if a+b=>c:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split())
if a+b>=c:
  print('Yes')
else:
  print('No')
Problem p03470 (python)

Fixed submission:
n = int(input())
 
s = set()
for i in range(n):
  s.add(int(input()))
 
print(len(s))

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

s = set()
for i in range(n):
  s.add(int(input())

print(min(3,len(s)))
Problem p03001 (python)

Fixed submission:
W, H, x, y = map(int, input().split())
print(W * H / 2, 1 if x * 2 == W and y * 2 == H else 0)

Buggy submission (verdict: Runtime Error):
import bisect
N, K = map(int, input().split())
A = tuple(map(int, input().split()))

s = [0] * (N + 1)
for i in range(N):
    s[i+1] = s[i] + A[i]
ans = 0
for b in range(N):
    i = bisect.bisect_left(s, K + s[b], b)
    ans += (N + 1 - i)
print(ans)
Problem p03230 (python)

Fixed submission:
N = int(input())
for k in range(1, N + 2):
    sn = k - 1
    if k * sn != 2 * N:
        continue

    print("Yes")
    print(k)
    s = [[0] * sn for _ in range(sn)]
    for i in range(sn):
        s[i][i] = s[i-1][i-1] + (i + 1)
        for j in range(i + 1, sn):
            s[i][j] = s[i][j-1] + j
            s[j][i] = s[i][j]
    s.append([s[i][i] for i in range(sn)])
    for x in s:
        print(sn, " ".join(map(str, x)))
    break
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    raise RuntimeError()

for k in range(2, N + 1):
    sn = k - 1
    if k * sn != 2 * N:
        continue

    print("Yes")
    print(k)
    s = [[0] * sn for _ in range(sn)]
    for i in range(sn):
        s[i][i] = s[i-1][i-1] + (i + 1)
        for j in range(i + 1, sn):
            s[i][j] = s[i][j-1] + j
            s[j][i] = s[i][j]
    s.append([s[i][i] for i in range(sn)])
    for x in s:
        print(sn, " ".join(map(str, x)))
    break
else:
    print("No")

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

for k in range(2, N + 1):
    slen = k - 1
    if k * slen == 2 * N:
        print("Yes")
        print(k)
        x = [0] * N
        for i in range(k):
            s = [None] * slen
            for j in range(slen):
                n = (i + j) % N
                if x[n] < 2:
                    s[j] = str(n)
                    x[n] += 1
            print(slen, " ".join(s))
        break
else:
    print("No")
Problem p02608 (python)

Fixed submission:
n = int(input())

a = [0] * 10010

# x,y,z
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      if x*x + y*y + z*z + x*y + y*z + z*x > n:
        continue
      a[x*x + y*y + z*z + x*y + y*z + z*x] += 1


for i in range(1, n+1):
  print(a[i])

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

a = [0] * 10010

# x = y = z
x = 1
while True:
  a[6 * x * x] += 1
  x += 1
  if 6 * x * x > n:
    break

# x = y, z
for x in range(1, n+1):
  for z in range(1, n+1):
    if x == z:
      continue
    a[3 * x * x + z * z + 2 * x * z] += 1
    if 3 * x*x + z*z + 2*x*z > n:
      break
  if x * x > n:
    break

# x,y,z
for x in range(1, n+1):
  for y in range(x+1, n+1):
    for z in range(y+1, n+1):
      a[x*x + y*y + z*z + x*y + y*z + z*x] += 1
      if x*x + y*y + z*z + x*y + y*z + z*x > n:
        break
    if x*x + y*y + x*y > n:
      break
  if x*x > n:
    break

for i in range(n):
  print(a[i])
Problem p02936 (python)

Fixed submission:
N, Q = map(int, input().split())
tree = {}
ans = []
ans.extend([0 for _ in range(N)])

for i in range(N-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    tree.setdefault(a, []).append(b)
    tree.setdefault(b, []).append(a)

for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

sta = [(0, 0)]
while sta:
    k, p = sta.pop()
    for c in tree.get(k, []):
        if c == p:
            continue
        ans[c] += ans[k]
        sta.append((c, k))

print(' '.join([str(x) for x in ans]))

Buggy submission (verdict: Runtime Error):
tree = {}
ans = []
def resolve():
    N, Q = map(int, input().split())
    ans.extend([0 for _ in range(N)])

    for i in range(N-1):
        a, b = map(lambda x: int(x) - 1, input().split())
        tree.setdefault(a, []).append(b)
        tree.setdefault(b, []).append(a)

    for i in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x

    dfs(0, ans[0])

    print(' '.join([str(x) for x in ans]))


def dfs(k, val, par=0):
    if k not in tree:
        return
    for c in tree.get(k, []):
        if c == par:
            continue
        ans[c] += val
        dfs(c, ans[c], k)
    return

if __name__ == "__main__":
    resolve()
Problem p03244 (python)

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

evenv, oddv = Counter(v[0::2]).most_common(), Counter(v[1::2]).most_common()
ans = 0
if evenv == oddv and len(evenv) == 1:
    ans = n // 2
elif evenv[0][0] == oddv[0][0]:
    ans = n - max(evenv[0][1] + oddv[1][1], evenv[1][1] + oddv[0][1])
else:
    ans = n - evenv[0][1] - oddv[0][1]
print(ans)

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

evenv, oddv = Counter(v[0::2]).most_common(), Counter(v[1::2]).most_common()
ans = 0
if evenv == oddv and len(evenv) == 1:
    ans = n // 2
elif evenv[0][0] == oddv[0][0]:
    ans = n - max(evenv[0][1] + oddv[1][1], evenv[1][1] + oddv[0][1])
else:
    ans = n - evenv[0][1] - oddv[0][1]
print(ans)
Problem p02658 (python)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
    
main()

Buggy submission (verdict: Runtime Error):
#B
from functools import reduce

n = int(input())
a = list(map(int,input().split()))
flg = True
MAX = 10 ** 18
cnt = 1
a.sort()
result = reduce(lambda ans, x:ans * x, a)
if result > MAX:
    flg = False
    break
        
if flg:
    print(result)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
#B
from functools import reduce
n = int(input())
a = tuple(map(int,input().split()))
flg = True
MAX = 10 ** 18
cnt = 1
a.sort()
result = reduce(lambda ans, x:ans * x, a)
if result > MAX:
    flg = False
    break
        
if flg:
    print(result)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
#B
n = int(input())
a = tuple(map(int,input().split()))
flg = True
MAX = 10 ** 18
cnt = 1
result = reduce(lambda ans, x:ans * x, a)
if result > MAX:
    flg = False
        

if flg:
    print(result)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_n = np.array(a,dtype=np.float64)
#print(a_n)
result = np.prod(a_n)
if result >= 10**18:
    print(-1)
else:
    print(int(result))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_n = np.array(a,dtype=np.float64)
#print(a_n)
result = np.prod(a_n)
if result > 10**18:
    print(-1)
else:
    print(int(result))
Problem p02684 (python)

Fixed submission:
#D
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
tel = deque()
tel.append(1)
visit = [False for _ in range(n)]
visit[0] = True
for i in range(n):
    nx = a[tel[i]-1]
    if visit[nx-1] == True :
        tel.append(nx)
        #ループの始まりのindexをidxに格納
        idx = tel.index(nx)
        break
    tel.append(nx)
    visit[nx-1] = True
    
#print(tel)
#print(visit)
if k <= idx:
    goal = tel[k]
else:
    k -= idx
    loop_num = len(tel) - idx - 1
    #print('idx:',idx)
    #print('loop_num:',loop_num)
    goal = tel[idx + k%loop_num]
    
print(goal)

Buggy submission (verdict: Runtime Error):
#D
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
tel = deque()
tel.append(1)
visit = [False for _ in range(n)]
visit[0] = True
for i in range(n):
    nx = a[tel[i]-1]
    if visit[nx-1] == True :
        tel.append(nx)
        #ループの始まりのindexをidxに格納
        idx = tel.index(nx)
        break
    tel.append(nx)
    visit[nx-1] == True
    
#print(tel)
if k - idx <=0:
    print(tel[k-1])
else:
    k -= idx
    loop_num = len(tel) - idx - 1
    #print('idx:',idx)
    #print('loop_num:',loop_num)
    goal = tel[idx + k%loop_num]
    
    print(goal)
Problem p02748 (python)

Fixed submission:
listA=[]

while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 
wari = 100000000

for k in range(listA[0][2]):
    a = listA[k+3][0]
    b = listA[k+3][1]
    if wari > listA[1][a-1] + listA[2][b-1] - listA[k+3][2]:
        wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]

if money <= wari:
    print(money)
        
else:
    print(wari)

Buggy submission (verdict: Runtime Error):
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 

for k in range(listA[0][2]):
    wari = 1000
    a = listA[k+3][0]
    b = listA[k+3][1]
    if wari > listA[1][a-1] + listA[2][b-1] - listA[k+3][2]:
        wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]

if money <= wari:
    print(money)
        
else:
    print(wari)
Problem p02882 (python)

Fixed submission:
a,b,x = map(int,input().split())
import math
if a**2*b / 2 <=  x:
    alpha = math.degrees(math.atan(2 * (a**2 * b - x) / a**3))
else:
    alpha =  math.degrees(math.atan(a*b**2 / (2*x) ))
    
print(alpha)

Buggy submission (verdict: Runtime Error):
a,b,x = map(int,input().split())
import math
if a**2*b / 2 <  x:
    alpha = math.degrees(math.atan(2 * (a**2 * b - x) / a**3))
else:
    alpha =  math.degrees(math.acos(2*x / (a*b**2)))
    
print(alpha)

Buggy submission (verdict: Runtime Error):
a,b,x = map(int,input().split())
import math
if a**2*b / 2 <=  x:
    alpha = math.degrees(math.atan(2 * (a**2 * b - x) / a**3))
else:
    alpha =  math.degrees(math.acos(2*x / (a*b**2)))
    
print(alpha)
Problem p02888 (python)

Fixed submission:
import bisect
n = int(input())
l = list(map(int,input().split()))
cnt = 0
l.sort()

for i in range(n):
    for j in range(i+1,n):
        k = bisect.bisect_left(l,l[i]+l[j])
        if k > j:
            cnt += k - j - 1
        else:
            pass
            
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
cnt = 0
l.sort()

for i in range(n):
    for j in range(i+1,n):
        k = bisect.bisect_left(l,l[i]+l[j])
        if k > j:
            cnt += k - j - 1
        else:
            continue
            
print(cnt)
Problem p02900 (python)

Fixed submission:
import fractions
a,b = map(int,input().split())

gcd = fractions.gcd(a,b)

def prime_factorize(n):
    result = []
    for i in range(2,int(n**0.5)+1):
        while n % i == 0:
            n //= i
            result.append(i)
    if n != 1:
        result.append(n)
    return result

ans = len(set(prime_factorize(gcd)))

print(ans+1)

Buggy submission (verdict: Runtime Error):
#D
import math
a,b = map(int,input().split())

gcd = math.gcd(a,b)

def prime_factorize(n):
    result = []
    for i in range(2,int(n**0.5)+1):
        while n % i == 0:
            n //= i
            result.append(i)
    if n != 1:
        result.append(n)
    return result

ans = len(set(prime_factorize(gcd)))

print(ans+1)
Problem p02922 (python)

Fixed submission:
#B
import math
a,b = map(int,input().split())

k = math.ceil((b-1)/(a-1))

if b == 1:
    print(0)
elif a == b:
    print(1)
else:
    print(k)

Buggy submission (verdict: Runtime Error):
#B
a = int(input())
b = int(input())
if b == 1:
    print(0)
elif a >= b:
    print(1)
else:
    print((b-a)//a + 2)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
import sys
def input():
    return sys.stdin.readline()[:-1]

n,q = map(int,input().split())
tree = [[] for _ in range(n)]
point = [0] * n

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    
for _ in range(q):
    a,b = map(int,input().split())
    a -= 1
    point[a] += b
    
def dfs(now, prev = -1):
    for next in tree[now]:
        if next == prev:
            continue
        point[next] += point[now]
        
        dfs(next, now)
        
dfs(0)
print(*point)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5)
n,q = map(int,input().split())
tree = [[] for _ in range(n)]
point = [0] * n

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    
for _ in range(q):
    a,b = map(int,input().split())
    a -= 1
    point[a] += b
    
def dfs(now, prev = -1):
    for next in tree[now]:
        if next == prev:
            continue
        point[next] += point[now]
        
        dfs(next, now)
        
dfs(0)
print(*point)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
tree = [[] for _ in range(n)]
point = [0] * n

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    
for _ in range(q):
    a,b = map(int,input().split())
    a -= 1
    point[a] += b
    
def dfs(now, prev = -1):
    for next in tree[now]:
        if next == prev:
            continue
        point[next] += point[now]
        
        dfs(next, now)
        
dfs(0)
print(*point)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
tree = [[] for _ in range(n)]
point = [0] * n

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    
for _ in range(q):
    a,b = map(int,input().split())
    a -= 1
    point[a] += b
    
def dfs(now, prev = -1):
    for next in tree[now]:
        if next == prev:
            continue
        point[next] += point[now]
        
        dfs(next, now)
        
dfs(0)
print(*point)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
tree = [[] for _ in range(n)]
point = [0] * n

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    
for _ in range(q):
    a,b = map(int,input().split())
    point[a-1] += b
    
def dfs(now, prev = -1):
    for next in tree[now]:
        if next == prev:
            continue
        point[next] += point[now]
        
        dfs(next,now)
        
dfs(0)
print(*point)
Problem p02973 (python)

Fixed submission:
#E
from collections import deque
import bisect
n = int(input())
a = [int(input()) for _ in range(n)]
result = deque()

for i in a:
    idx = bisect.bisect_left(result,i)
    if idx == 0:
        result.appendleft(i)
        
    else:
        result[idx-1] = i
        
print(len(result))

Buggy submission (verdict: Runtime Error):
#E
from collections import deque
import bisecit
n = int(input())
a = [int(input()) for _ in range(n)]
result = deque()

for i in a:
    idx = bisect.bisect_left(result,i)
    if idx == 0:
        result.appendleft(i)
        
    else:
        result[idx-1] = i
        
print(len(result))
Problem p03044 (python)

Fixed submission:
#D
#https://tech-kyopro.com/atcoder-abc126-d

import sys
sys.setrecursionlimit(500*500)
n = int(input())
edges = [list(map(int,input().split())) for _ in range(n-1)]
#頂点iと隣接する頂点とその距離を格納[["隣接する頂点","その距離"]]
a = [[] for _ in range(n+1)]

for i in edges:
    a[i[0]].append([i[1],i[2]])
    a[i[1]].append([i[0],i[2]])
    
#頂点1からの距離をdepth
depth = [-1 for _ in range(n+1)]
depth[0] = 0

def dfs(a,s):
    for v in a[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(a,v[0])
            
dfs(a,1)

for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
#D
#https://tech-kyopro.com/atcoder-abc126-d
n = int(input())
edges = [list(map(int,input().split())) for _ in range(n-1)]
#頂点iと隣接する頂点とその距離を格納[["隣接する頂点","その距離"]]
a = [[] for _ in range(n+1)]

for i in edges:
    a[i[0]].append([i[1],i[2]])
    a[i[1]].append([i[0],i[2]])
    
#頂点1からの距離をdepth
depth = [-1 for _ in range(n+1)]
depth[0] = 0

def dfs(a,s):
    for v in a[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(a,v[0])
            
dfs(a,1)

for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)
Problem p03062 (python)

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

idx = bisect.bisect_left(a, 0)
sm = [abs(x) for x in a]
if idx % 2 == 0:
    print(sum(sm))
else:
    print(sum(sm) - 2*min(sm))

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

idx = bisect.bisect_left(a, 0)
sm = [abs(x) for x in a]
if idx % 2 == 0:
    print(sum(sm))
else:
    print(sum(sm) - 2*min(abs(a[idx]), abs(a[idx-1])))

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

idx = bisect.bisect_left(a, 0)

if idx % 2 == 0:
    print(sum(abs(a)))
else:
    sm = [abs(x) for x in a]
    print(sum(sm) - 2*min(abs(a[idx]), abs(a[idx-1])))