Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())

ds = {}
dsl ={}
dt = {}
for i in range(len(s)):
    if s[i] not in ds.keys():    
        ds[s[i]] = 0
        dsl[s[i]] = []
    ds[s[i]]+=1
    dsl[s[i]].append(i)

for i in range(len(t)):
    if t[i] not in dt.keys():    
        dt[t[i]] = 0
    if t[i] not in ds.keys():
        ds[t[i]] = 0
    dt[t[i]]+=1

import bisect
ans = 1
now = 0
for i in range(len(t)):
    if ds[t[i]] == 0:
        print("-1")
        exit()
    elif ds[t[i]] == 1:
        if dsl[t[i]][0] > now:
            ans += (dsl[t[i]][0] - now)
        else:
            ans += dsl[t[i]][0]+1 +(len(s) - now - 1)
        now = dsl[t[i]][0] 
    else:
        index = bisect.bisect_right(dsl[t[i]],now)
        indexv = dsl[t[i]][index]
        if indexv > now:
            ans+= indexv - now
            now = indexv
        else:
            index = 0
            ans+= dsl[t[i]][index]+1 + (len(s) - now - 1)
            now = dsl[t[i]][index] 

print(ans)

Fixed submission:
import bisect
s = list(input())
t = list(input())

ds = {}  # ｓに含まれる文字それぞれの数
dsl = {}  # ｓの文字の位置
for i in range(len(s)):
    if s[i] not in ds.keys():
        ds[s[i]] = 0
        dsl[s[i]] = []
    ds[s[i]] += 1
    dsl[s[i]].append(i)

for i in range(len(t)):
    if t[i] not in ds.keys():
        ds[t[i]] = 0

#print(ds, dsl)

ans = 0
now = -1
for i in range(len(t)):
    if ds[t[i]] == 0:  # ｓにｔを構成する文字がない場合
        print("-1")
        exit()
    elif ds[t[i]] == 1:
        if dsl[t[i]][0] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][0] - now)
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
        now = dsl[t[i]][0]
    else:
        index = bisect.bisect_right(dsl[t[i]], now)
        if index == len(dsl[t[i]]):
            index = -1
        if dsl[t[i]][index] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][index] - now)
            now = dsl[t[i]][index]
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
            now = dsl[t[i]][0]

print(ans)
Buggy python submission (verdict: Runtime Error):
L,R = map(int,input().split())

for i in range(1,10**6):
    if i * 2019 >= L and i*2019 <= R:
        print(0)
        exit()

ans = 10**20

for i in range(L,min(L+2019,R+1)):
    for j in range(L,min(L+2019,R+1)):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
￥for i in range(max(L,R-2019),R+1):
    for j in range(max(L,R-2019),R+1):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
print(ans)


Fixed submission:
L,R = map(int,input().split())

for i in range(1,10**6):
    if i * 2019 >= L and i*2019 <= R:
        print(0)
        exit()

ans = 10**20

for i in range(L,min(L+2019,R+1)):
    for j in range(L,min(L+2019,R+1)):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
for i in range(max(L,R-2019),R+1):
    for j in range(max(L,R-2019),R+1):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
print(ans)
Buggy python submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())

ans = 0
if W % 2 == 0:
    if W // 2 == x:
        ans += 1
if H % 2 == 0:
    if H //2 == y:
        ans += 1

if ans == 2:
    ans = 1
else:
    ans = 0

if x == 0 or y == 0:
    ans = 0


tate = min((W-x)*H , (x - 0)*H)
yoko = min((H-y)*W , (y - 0)*W)

k = max(tate,yoko)

if (x == W and y == 0) or (x == 0 and y == H) or (x == W and y == H) or (x == 0 and y == 0):
    k = (W*H)/2
    ans = 0

if H == W:
    if x == y:
        k = (W*H)/2
    elif y + x == H:
        k = (W*H)/2


if H == 1 and  Y == 1:
    k = 0.5
    ans = 0


print(k,ans,sep=" ")


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

ans = 0
if W % 2 == 0 and W//2==x and H %2 == 0 and H//2==y:
    ans = 1

tate = min((W-x)*H , (x - 0)*H)
yoko = min((H-y)*W , (y - 0)*W)
k = max(tate,yoko)

if (x == W and y == 0) or (x == 0 and y == H) or (x == W and y == H) or (x == 0 and y == 0):
    k = (W*H)/2

if H == W:
    if x == y:
        k = (W*H)/2
    elif y + x == H:
        k = (W*H)/2



k = (W*H)/2
print(k,ans,sep=" ")
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : x[1],reverse=True)

import bisect
ans = 0
c = 0
sA= sorted(A)
for i in range(M):
    if -bc[i][0] - c > N + 1:
        c = -bc[i][0] + N + 1
    if A[-bc[i][0]-c] > bc[i][1]:
        cc = bisect.bisect_left(sA,bc[i][1])
        ans += (bc[i][1]*(cc-c))
        c += (cc-c)
        break
    else:
        c += bc[i][0]
        ans += (bc[i][1]*bc[i][0])

for i in range(N):
    if i < N - c:
        ans += A[i]
    else:
        break
print(ans)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : -x[1])
i = 0
for b,c in bc:
    for j in range(i,min(N,i+b)):
        if A[j] < c:
            A[j] = c
    i += b
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : x[1],reverse=True)

import bisect
ans = 0
c = 0
for i in range(M):
    if A[-bc[i][0]-c] > bc[i][1]:
        cc = bisect.bisect_left(sorted(A),bc[i][1])
        ans += (bc[i][1]*(cc-c))
        c += (cc-c)
        break
    else:
        c += bc[i][0]
        ans += (bc[i][1]*bc[i][0])

for i in range(N):
    if i < N - c:
        ans += A[i]
    else:
        break

print(ans)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : -x[1])
i = 0
for b,c in bc:
    for j in range(i,min(N,i+b)):
        if A[j] < c:
            A[j] = c
    i += b
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

A = sorted(A,reverse=True)
bc = sorted(bc,key=lambda x : x[1],reverse=True)

AA = []
for i in range(M):
    l = [bc[i][1]]*bc[i][0]
    AA += l

AA = sorted(AA)
AAA = []
for i in range(1,min(len(A),len(AA))+1):
    if A[-i] < AA[-i]:
        AAA.append(AA[-i])
    else:
        AAA.append(A[-i])
if len(A) >= len(AA):
    AAA += A[:N-len(AAA)]
print(sum(AAA))


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : -x[1])
i = 0
for b,c in bc:
    for j in range(i,min(N,i+b)):
        if A[j] < c:
            A[j] = c
    i += b
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    if col[x] == -1:
        col[x] = c
        for v,w in e[x]:
            if col[v] == -1:
                dfs(v , c+w)

dfs(1,0)
for i in range(1,N+1):
    if col[i] % 2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    col[x] = c
    for v,w in e[x]:
        if col[v] == -1:
            dfs(v , c+w)

dfs(1,0)



for i in range(1,N+1):
    print(col[i] % 2)

Buggy python submission (verdict: Runtime Error):
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    col[x] = c
    for v,w in e[x]:
        if col[v] == -1:
            dfs(v , c+w)

dfs(1,0)

for i in range(1,N+1):
    if col[i] % 2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    col[x] = c
    for v,w in e[x]:
        if col[v] == -1:
            dfs(v , c+w)

dfs(1,0)



for i in range(1,N+1):
    print(col[i] % 2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

if N == 2:
    print(max(A))
    exit()

maxa = max(A)
import fractions
d = []
for i in range(N):
    d.append(fractions.gcd(maxa , A[i]))
d = list(set(d))
d = sorted(d)
print(d[1])


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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i]))
r.append(0)
r.append(A[-1])
for i in range(1,N-1):
    r.append(fr.gcd(r[i],A[-i-1]))

ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)

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


maxa = max(A)
import fractions
d = []
for i in range(N):
    if A[i] != maxa:
        d.append(fractions.gcd(maxa , A[i]))
d = list(set(d))
if len(d) == 0:
    print(A[0])
    exit()
d = sorted(d)
print(d[1])

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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i]))
r.append(0)
r.append(A[-1])
for i in range(1,N-1):
    r.append(fr.gcd(r[i],A[-i-1]))

ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if (a < b and b < c) or (a > b and b > c):
    print("No")
else:
    print("Yes")


Fixed submission:
N = int(input())
S = input()
K = int(input())

a = S[K-1]

ans = ""
for i in range(N):
    if S[i] == a:
        ans += a
    else:
        ans += "*"
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())

ans = 0
for i in range(N-2):
    if S[i] == "#" and S[i+1] == "#" and S[i+2] == ".":
        ans += 1
        S[i+2] = "#"
    elif S[i] == "#" and S[i+1] == "." and S[i+2] == ".":
        ans += 1
        S[i] = "."
    elif S[i] == "#" and S[i+1] == "." and S[i+2] == "#":
        ans += 1
        S[i] = "."
if S[-2] == "#" and S[-1] == ".":
    ans += 1

print(ans)


Fixed submission:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    s = input()
    black = s.count("#")
    white = len(s) - black
    ans = min(black, white)
    
    b,w = 0,0
    for i in range(len(s)):
        if s[i] == "#":
            b += 1
        else:
            w += 1
        
        ans = min(ans, b + (white - w))
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(input())
cnt = 1
k = {}
if S[0] == "0":
    k[cnt] = [0]
    cnt += 1


flg = False
for i in range(N):
    if S[i] == '1':
        if cnt not in k.keys() :
            k[cnt] = []
        k[cnt].append(i)
        flg = True
    else:
        if flg == True:
            flg = False
            cnt += 1

if S[-1] == '0':
    k[cnt] = [N-1]


if '0' not in S:
    print(len(S))
    exit()
if N == 1:
    print(1)
    exit()

if cnt - K + 1 < 0:
    print(len(S))
    exit()

ans = 0
for i in range(1,cnt - K+1):
    ans = max(ans , k[i+K][-1]-k[i][0] + 1)
print(ans)


Fixed submission:
N,K = map(int,input().split())
S = list(input())
cnt = 1
k = {}
if S[0] == "0":
    k[cnt] = [0]
    cnt += 1


flg = False
for i in range(N):
    if S[i] == '1':
        if flg == False :
            k[cnt] = []
        k[cnt].append(i)
        flg = True
    else:
        if flg == True:
            flg = False
            cnt += 1

if S[-1] == '0':
    k[cnt] = [N-1]

if '0' not in S:
    print(len(S))
    exit()
if N == 1:
    print(1)
    exit()
if cnt - K + 1 < 0:
    print(len(S))
    exit()

ans = 0
for i in range(1,cnt - K+1):
    ans = max(ans , k[i+K][-1]-k[i][0] + 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
l = []
for i in range(5):
    l.append(int(input()))

ans = 10**10

import itertools
t = 0
for P in itertools.permutations(l,len(l)):
    for p in P:
        t += p
        if (p % 10) != 0:
            tt = 10-p%10
            t += (10 - p%10)


    ans = min(ans , t-tt)
    t = 0
print(ans)


Fixed submission:
l = []
for i in range(5):
    l.append(int(input()))

ans = 10**10

import itertools
t = 0
tt = 0
for P in itertools.permutations(l,len(l)):
    for p in P:
        t += p
        if (p % 10) != 0:
            tt = 10-p%10
            t += (10 - p%10)
    ans = min(ans , t-tt)
    t = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    n, q = map(int, input().split())
    s = list(input())
    lr = [list(map(int, input().split())) for i in range(q)]
    ruiseki = [0 for i in range(n)]

    for i in range(n - 1):
        if s[i] == "A" and s[i + 1] == "C":
            ruiseki[i + 1] = ruiseki[i] + 1
        else:
            ruiseki[i + 1] = ruiseki[i]

    for l, r in lr:
        print((ruiseki[r] - ruiseki[l]))


if __name__ == '__main__':
    main()


Fixed submission:
N,Q = map(int,input().split())
S = input()
ACnum = [0]
for i in range(1,N):
    if "AC" == S[i-1:i+1]:
        ACnum.append(ACnum[i-1] + 1)
    else:
        ACnum.append(ACnum[i-1])
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

for i in range(Q):
    print(ACnum[lr[i][1]-1] - ACnum[lr[i][0]-1])
Buggy python submission (verdict: Runtime Error):
N,M,C = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    if a in ab.keys():
        ab[a] += b
        continue
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)


Fixed submission:
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(list(map(int,input().split())))

ans = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += A[i][j]*B[j]
    tmp += C
    if tmp > 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
honsu = 0
money = 0
pre_money = 0
for i in keys:
    if honsu >= M:
        money = pre_money
        break
    ans += ab[i] * i
    honsu += ab[i]
    if honsu >= M:
        money = i
        break
    pre_money = i

for j in range(ab[money]):
    if honsu == M:
        break
    honsu -= 1
    ans -= money

print(ans)


Fixed submission:
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    if a in ab.keys():
        ab[a] += b
        continue
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
honsu = 0
money = 0
for i in keys:
    if honsu >= M:
        break
    ans += ab[i] * i
    honsu += ab[i]
    if honsu >= M:
        money = i
        break

for j in range(ab[money]):
    if honsu == M:
        break
    honsu -= 1
    ans -= money

print(ans)


Fixed submission:
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    if a in ab.keys():
        ab[a] += b
        continue
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())

if a == b:
    print(a)
    exit()

c = 0
d = a

e = ((b - a) // 4)*4

while True:
    if d >= b:
        break
    d += 4

d = a + e + 1
while True:
    if d > b:
        break
    a ^= d
    d += 1
print(a)


Fixed submission:
A,B = map(int,input().split())
 
aa,bb = 0,0
if (A-1) % 2 == 0:
    if ((A-1) //2) % 2 == 0:
        aa = (A-1)^1
    else:
        aa = (A-1)
else:
    if ((A+1) //2) % 2 == 0:
        aa = 1
 
if B % 2 == 0:
    if (B//2) % 2 == 0:
        bb = B^1
    else:
        bb = B
else:
    if ((B+1) //2) % 2 == 0:
        bb = 1
 
print(aa^bb)

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())

if a == b:
    print(a)
    exit()

c = 0
d = a
while True:
    if d >= b:
        break
    d += 4
    c += 1

d -= 3
c -= 1

while True:
    if d > b:
        break
    a ^= d
    d += 1
print(a)


Fixed submission:
A,B = map(int,input().split())
 
aa,bb = 0,0
if (A-1) % 2 == 0:
    if ((A-1) //2) % 2 == 0:
        aa = (A-1)^1
    else:
        aa = (A-1)
else:
    if ((A+1) //2) % 2 == 0:
        aa = 1
 
if B % 2 == 0:
    if (B//2) % 2 == 0:
        bb = B^1
    else:
        bb = B
else:
    if ((B+1) //2) % 2 == 0:
        bb = 1
 
print(aa^bb)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(N):
  x,v = map(int,input().split())
  if v == "JPY":
    ans += x
  else:
    ans += x*380000.0
print(ans)
  

Fixed submission:
N = int(input())
ans = 0
for i in range(N):
  x,v = input().split()
  x = float(x)
  if v == "JPY":
    ans += x
  else:
    ans += x*380000.0
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
X = list(map(int,input().split()))

if M == 1 and N > 0:
    print(0)
    exit()

X = sorted(X)
s = []
for i in range(len(X) - 1):
    s.append(abs(X[i+1]- X[i]))
ans = sum(s)
s = sorted(s)
for i in range(1,N):
    ans -= s[-i]
print(ans)


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

if M == 1 and N > 0:
    print(0)
    exit()
if M <= N:
    print(0)
    exit()


X = sorted(X)
s = []
for i in range(len(X) - 1):
    s.append(abs(X[i+1]- X[i]))
ans = sum(s)
s = sorted(s)
for i in range(1,N):
    ans -= s[-i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy

N = int(input())
A,B = [],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)


AA = list(numpy.argsort(A))[::-1]
BB = list(numpy.argsort(B))[::-1]
aans,bans = 0,0
while True:
    a = AA.pop(0)
    aans += A[a]
    if BB[0] == a:
        BB.pop(0)
    if not BB:
        break
    b = BB.pop(0)
    bans += B[b]
    if AA[0] == b:
        AA.pop(0)
    if not AA:
        break

print(aans - bans)


Fixed submission:
import numpy
import collections
N = int(input())
arr = []
for i in range(N):
    a,b = map(int,input().split())
    arr.append([a+b,a,b])

arr = sorted(arr,reverse=True)
ansa,ansb = 0 , 0
for i in range(N):
    if i % 2 == 0:
        ansa += arr[i][1]
    else:
        ansb += arr[i][2]
print(ansa - ansb)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
N = int(input())
A,B = [],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

AA = list(numpy.argsort(A)[::-1])
BB = list(numpy.argsort(B)[::-1])
Al = []
Bl = []
aans,bans = 0,0
for i in range(N):
    a = AA.pop(0)
    aans += A[a]
    Al.append(a)
    BB.remove(a)
    if not BB:
        break
    b = BB.pop(0)
    bans += B[b]
    Bl.append(b)
    AA.remove(b)
    if not AA:
        break

print(aans - bans)


Fixed submission:
import numpy
import collections
N = int(input())
arr = []
for i in range(N):
    a,b = map(int,input().split())
    arr.append([a+b,a,b])

arr = sorted(arr,reverse=True)
ansa,ansb = 0 , 0
for i in range(N):
    if i % 2 == 0:
        ansa += arr[i][1]
    else:
        ansb += arr[i][2]
print(ansa - ansb)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)

dp = [10**10] * (N+1)
dp[0],dp[1] = 0,0

for i in range(2,N+1):
    for j in range(min(K,i)):
        dp[i] = min(dp[i] , dp[i-j-1] + abs(h[i] - h[i-j-1]))
print(dp[N])


Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)

dp = [10**10] * (N+1)
dp[0],dp[1] = 0,0

for i in range(2,N+1):
    for j in range(min(K,i)):
        if i - j - 1 == 0:
            break
        dp[i] = min(dp[i] , dp[i-j-1] + abs(h[i] - h[i-j-1]))
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
wv = []
for i in range(N):
    wv.append(list(map(int,input().split())))

dp = [[ 0 for i in range(W+1)] for j in range(N+2)]

for i in range(N):
    for w in range(1,W+1):
        if w - wv[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w] , dp[i][w - wv[i][0]] + wv[i][1])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])


Fixed submission:
N,W = map(int,input().split())
wv = []
for i in range(N):
    wv.append(list(map(int,input().split())))

dp = [[ 0 for i in range(W+1)] for j in range(N+2)]

for i in range(N):
    for w in range(1,W+1):
        if w - wv[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w] , dp[i][w - wv[i][0]] + wv[i][1])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    p = list(map(float, input().split()))

    dp = [[0.0 for i in range(n + 1)] for j in range(n + 1)]
    dp[0][0] = 1.0
    for i in range(n):
        for j in range(n):
            dp[i + 1][j + 1] += dp[i][j] * p[i]
            dp[i + 1][j] += dp[i][j] * (1.0 - p[i])

    ans = 0.0
    for i in range(n // 2+1, n+1):
        ans += dp[n][i]
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    p = list(map(float, input().split()))

    dp = [[0.0 for i in range(n + 1)] for j in range(n + 1)]
    dp[0][0] = 1.0
    for i in range(n):
        for j in range(n):
            dp[i + 1][j + 1] += dp[i][j] * p[i]
            dp[i + 1][j] += dp[i][j] * (1.0 - p[i])

    ans = 0.0
    for i in range(n // 2+1, n+1):
        ans += dp[n][i]
    print(ans)


if __name__ == '__main__':
    main()