Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
N, M=map(int, input().split())
A=list(map(int, input().split()))
lst=[list(map(int, input().split())) for _ in range(M)]
A.sort()
lst.sort(key=lambda x: (x[1], x[0]), reverse=True)
for i in range(M):
  index=bisect_left(A, lst[i][1])
  if index-1>=lst[i][0]:
    A[:index]=A[lst[i][0]:index]+[lst[i][1] for _ in range(lst[i][0])]
  else:
    A[:index]=[lst[i][1] for _ in range(index)]
    break
print(sum(A))

Fixed submission:
from collections import defaultdict
N, M=map(int, input().split())
A=list(map(int, input().split()))
d=defaultdict(int)
for a in A:
  d[a]+=1
for i in range(M):
  B, C=map(int, input().split())
  d[C]+=B
index_list=sorted(d)
ans=0
ans_size=0
for i in range(len(index_list)-1, -1, -1):
  card=index_list[i]
  if d[card]+ans_size>=N:
    ans+=(N-ans_size)*card
    break
  else:
    ans+=d[card]*card
    ans_size+=d[card]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
N, M=map(int, input().split())
A=list(map(int, input().split()))
lst=[list(map(int, input().split())) for _ in range(M)]
A.sort()
lst.sort(key=lambda x: (x[1], x[0]), reverse=True)
for i in range(M):
  index=bisect_left(A, lst[i][1])
  if index-1>=lst[i][0]:
    A[:index]=A[lst[i][0]:index]+[lst[i][1] for _ in range(lst[i][0])]
  else:
    A[:index]=[lst[i][1] for _ in range(index)]
    break
print(sum(A))

Fixed submission:
from collections import defaultdict
N, M=map(int, input().split())
A=list(map(int, input().split()))
d=defaultdict(int)
for a in A:
  d[a]+=1
for i in range(M):
  B, C=map(int, input().split())
  d[C]+=B
index_list=sorted(d)
ans=0
ans_size=0
for i in range(len(index_list)-1, -1, -1):
  card=index_list[i]
  if d[card]+ans_size>=N:
    ans+=(N-ans_size)*card
    break
  else:
    ans+=d[card]*card
    ans_size+=d[card]
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A=list(map(lambda x:-x if x < 0 else x, A))
A.sort()
print(sum(A[1:]-A[0]))

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
cnt=0
for i in range(N):
  if A[i]<0:
    A[i]*=-1
    cnt+=1
A=list(map(abs, A))
A.sort()
if cnt&1==0:
  print(sum(A))
else:
  print(sum(A[1:])-A[0])

Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int, input().split()))
A=list(map(math.fabs, A))
A.sort()
print(sum(A[1:]-A[0]))

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
cnt=0
for i in range(N):
  if A[i]<0:
    A[i]*=-1
    cnt+=1
A=list(map(abs, A))
A.sort()
if cnt&1==0:
  print(sum(A))
else:
  print(sum(A[1:])-A[0])

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A=list(map(abs, A))
A.sort()
print(sum(A[1:]-A[0]))

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
cnt=0
for i in range(N):
  if A[i]<0:
    A[i]*=-1
    cnt+=1
A=list(map(abs, A))
A.sort()
if cnt&1==0:
  print(sum(A))
else:
  print(sum(A[1:])-A[0])
Buggy python submission (verdict: Time Limit Exceeded):
N, K=map(int, input().split())
H=list(map(int, input().split()))
MAXV=10**9
dp=[MAXV for _ in range(N)]
dp[0]=0
for i in range(1, N):
  minv=MAXV
  dp[i]=min([dp[j]+abs(H[j]-H[i]) if j>=0 else MAXV for j in range(i-K, i)])
print(dp[-1])

Fixed submission:
N, K=map(int, input().split())
H=list(map(int, input().split()))
MAXV=10**9
dp=[MAXV for _ in range(N)]
dp[0]=0
for i in range(1, N):
  minv=MAXV
  dp[i]=min([dp[j]+abs(H[j]-H[i]) if j>=0 else MAXV for j in range(i-K, i)])
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M=map(int, input().split())
A=list(map(int, input().split()))
s=[0 for _ in range(N+1)]
counts=[0 for _ in range(M)]
for i in range(N):
    s[i+1]=(s[i]+A[i])%M
ans=0
for i in range(N+1):
    ans+=counts[s[i]]
    counts[s[i]]+=1
print(ans)

Fixed submission:
from collections import defaultdict
#from collections import deque

N, K=map(int, input().split())
A=list(map(int, input().split()))
#for i in range(N):
    #A[i]-=1
s=[0 for _ in range(N+1)]
for i in range(N):
    s[i+1]=(s[i]+A[i])%K
d=defaultdict(int)
ans=0
#q=deque()
for j in range(N+1):
    ans+=d[s[j]]
    d[s[j]]+=1
    #q.append(s[j])
    #if len(q)==K:
        #d[q[0]]-=1
        #q.popleft()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
lst=list(map(int, input().split()))

cnt=0
for i in range(n):
  xor_tmp=0
  add_tmp=0
  for j in range(i+1):
    xor_tmp^=lst[i-j]
    add_tmp+=lst[i-j]
    if xor_tmp!=add_tmp:
      break
    else:
      cnt+=1
print(cnt)

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

res=0
xor_sum=0
add_sum=0
right=0
for left in range(n):
  while right<n and xor_sum^A[right]==add_sum+A[right]:
    xor_sum^=A[right]
    add_sum+=A[right]
    right+=1
  res+=(right-left)
  if right==left:
    right+=1
  else:
    xor_sum^=A[left]
    add_sum-=A[left]
print(res)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

V = [[] for _ in range(M)]

for _ in range(M):
    a,b = map(int,input().split())
    a = a-1
    b = b-1
    V[a].append(b)
    V[b].append(a)

from collections import deque

q = deque([0])

ans = [-1]*N
ans[0] = 0

while q:
    v = q.popleft()
    for nv in V[v]:
        if ans[nv] == -1:
            ans[nv] = v + 1
            q.append(nv)

print("Yes")
print(*ans[1:],sep="\n")


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

V = [[] for _ in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    a = a-1
    b = b-1
    V[a].append(b)
    V[b].append(a)

from collections import deque

q = deque([0])

ans = [-1]*N
ans[0] = 0

while q:
    v = q.popleft()
    for nv in V[v]:
        if ans[nv] == -1:
            ans[nv] = v + 1
            q.append(nv)

print("Yes")
print(*ans[1:],sep="\n")

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

ans = [0]*N
pas = [M+1]*N
ans[0] = 1
pas[0] = 0

for i in range(M):
    if D[i][0] > D[i][1]:
        tmp = D[i][1]
        D[i][1] = D[i][0]
        D[i][0] = tmp
D.sort(key=lambda x:x[0])

for i in range(M):
    while ans[D[i][0]-1] == 0:
        D.append(D[i])
        D.pop(i)
    if pas[D[i][0]-1]+1 < pas[D[i][1]-1]:
        pas[D[i][1]-1] = pas[D[i][0]-1]+1
        ans[D[i][1]-1] = D[i][0]
    if pas[D[i][1]-1]+1 < pas[D[i][0]-1]:
        pas[D[i][0]-1] = pas[D[i][1]-1]+1
        ans[D[i][0]-1] = D[i][1]


if 0 not in pas[1:]:
    print('Yes')
    for n in ans[1:]:
        print(n)

else:
    print('No')


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

V = [[] for _ in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    a = a-1
    b = b-1
    V[a].append(b)
    V[b].append(a)

from collections import deque

q = deque([0])

ans = [-1]*N
ans[0] = 0

while q:
    v = q.popleft()
    for nv in V[v]:
        if ans[nv] == -1:
            ans[nv] = v + 1
            q.append(nv)

print("Yes")
print(*ans[1:],sep="\n")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

DP = [0,0,0]
m = N//2*2
if N%2 == 0:
    for i in range(0,m,2):
        DP[0] += A[i]
        DP[1] += A[i+1]
        DP[1] = max(DP[0],DP[1])

    print(DP[1])

else:
    for i in range(0,m,2):
        DP[0] += A[i]
        DP[1] += A[i+1]
        DP[2] += A[i+2]

        DP[1] = max(DP[0],DP[1])
        DP[2] = max(DP[1],DP[2])

    print(DP[2])


Fixed submission:
N = input()

if "7" in N:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

if N%2 == 0:
    sum1 = sum(A[x*2] for x in range(N//2))
    sum2 = sum(A)-sum1
    print(max(sum1,sum2))
    exit()

DP = [0,0,0]
m = N//2*2
for i in range(0,m,2):
    DP[0] += A[i]
    DP[1] += A[i+1]
    DP[2] += A[i+2]

    DP[1] = max(DP[0],DP[1])
    DP[2] = max(DP[1],DP[2])

print(DP[3])


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

DP = [0,0,0]
m = N//2*2
if N%2 == 0:
    for i in range(0,m,2):
        DP[0] += A[i]
        DP[1] += A[i+1]
        DP[1] = max(DP[0],DP[1])

    print(DP[1])

else:
    for i in range(0,m,2):
        DP[0] += A[i]
        DP[1] += A[i+1]
        DP[2] += A[i+2]

        DP[1] = max(DP[0],DP[1])
        DP[2] = max(DP[1],DP[2])

    print(DP[2])
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)
S = sum(A)
i = 0

while A[i] >= S/(M*4) and i < N:
    i += 1

if i >= M:
    print("Yes")
else:
    print("No")


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

A.sort(reverse=True)
S = sum(A)

for i in range(M):
    if A[i] < S/(4*M):
        print('No')
        exit()

print('Yes')

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

A.sort(reverse=True)
S = sum(A)
i = 0
while A[i] > S//(M*4) and i < N:
    i += 1

if i >= M:
    print("Yes")
else:
    print("No")


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

A.sort(reverse=True)
S = sum(A)

for i in range(M):
    if A[i] < S/(4*M):
        print('No')
        exit()

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int,input().split())
X,Y = X-1,Y-1
from collections import deque

DP = [[-1]*N for _ in range(N)]

ans = [0]*N

for i in range(N):
    for j in range(i+1,N):
        x = j - (i+1)
        y = j
        if j <= X or Y <= i:
            DP[i][j] = j - i
        elif i <= X and Y <= j:
            DP[i][j] = X-i + 1 + j-Y
        elif i <= X and j <= Y:
            DP[i][j] = min(j-i,X-i + 1 + Y-j)
        elif X <= i and j <= Y:
            DP[i][j] = min(j-i,i-X+1+Y-j)
        else:
            DP[i][j] = min(j-i,i-X+1+j-Y)
        ans[DP[i][j]] += 1

print(*ans[1:],sep='\n')


Fixed submission:
N,X,Y = map(int,input().split())
X,Y = X-1,Y-1

ans = [0]*N

for i in range(N):
    for j in range(i+1,N):
        if j <= X or Y <= i:
            a = j - i
        elif i <= X and Y <= j:
            a = X-i + 1 + j-Y
        elif i <= X and j <= Y:
            a = min(j-i,X-i + 1 + Y-j)
        elif X <= i and j <= Y:
            a = min(j-i,i-X+1+Y-j)
        else:
            a = min(j-i,i-X+1+j-Y)
        ans[a] += 1

print(*ans[1:],sep='\n')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

ls = [0]*N
for i in range(N):
    ls[A[i]] += 1
s = 0
for i in range(N):
    s += ls[i]*(ls[i]-1)//2

for k in range(N):
    print(s-ls[A[k]] + 1)
    

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

ls = [0]*N
for i in range(N):
    ls[A[i]-1] += 1
s = 0
for i in range(N):
    s += ls[i]*(ls[i]-1)//2
ans = [0]*N
for i in range(N):
    ans[i] = s-ls[A[i]-1] + 1

print(*ans,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
N,S = map(int,input().split())
A = list(map(int,input().split()))
from collections import deque
import itertools
import numpy as np
ls = deque([])

A = np.array(A)
for v in itertools.product([0,1], repeat=N):
    u = np.array(v)
    if S == np.dot(A,u):
        u = list(u)
        i = N
        j = 0
        for k in range(N):
            if u[k] == 1:
                i = min(i,k)
                j = k
        ls.append([i,j])

ans = 0
MOD = 998244353

while ls:
    a = ls.pop()
    ans += (a[0]+1)*(N-a[1]) % MOD

print(ans)


Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
ans = 0
dp = [0]*S

for i, a in enumerate(A):
    dp[0] +=1
    if a > S:
        continue

    ans = (ans + dp[S-a]*(N-i)% mod) % mod

    for j, x in enumerate(dp[:S-a]):
        dp[j+a] += x
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [input() for _ in range(H)]
import math
DP = [[math.inf]+[0]*W for _ in range(H+1)]
re = [[0]*(W+1) for _ in range(H+1)]
DP[0] = [math.inf]*(W+1)
DP[0][1] = DP[1][0] = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i-1][j-1] == ".":
            DP[i][j] = min(DP[i-1][j],DP[i][j-1])
        else:
            u = DP[i-1][j]+1-re[i-1][j]
            l = DP[i][j-1]+1-re[i][j-1]
            DP[i][j] = min(u, l)
            re[i][j] = 1
            if u < l and re[i-1][j] == 0:
                DP[i][j] += 1
            elif u > l and re[i][j-1] == 0:
                count += 1
            elif u == l:
                count += 1 - re[i-1][j]*re[i][j-1]
                
print(DP[H][W])



Fixed submission:
H,W = map(int,input().split())
s = [input() for _ in range(H)]

DP = [[1000]+[0]*W for _ in range(H+1)]
re = [[0]*(W+1) for _ in range(H+1)]
DP[0] = [1000]*(W+1)
DP[0][1] = DP[1][0] = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i-1][j-1] == ".":
            DP[i][j] = min(DP[i-1][j],DP[i][j-1])
        else:
            u = DP[i-1][j]+1-re[i-1][j]
            l = DP[i][j-1]+1-re[i][j-1]
            DP[i][j] = min(u, l)
            re[i][j] = 1

print(DP[H][W])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,intput().split()))

for i in range(N):
    if A[i]%2 == 0 and (A[i]%3 != 0 and A[i]%5 != 0):
        print('DENIED')
        exit()

print('APPROVED')

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

for i in range(N):
    if A[i]%2 == 0 and (A[i]%3 != 0 and A[i]%5 != 0):
        print('DENIED')
        exit()

print('APPROVED')
Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())

magics = [list(map(int,input().split())) for _ in range(N)]
max_A = max(a for a,b in magics)
DP = [float('inf')]*(H+max_A)
DP[0] = 0
for i in range(1,H+max_A):
    DP[i] = min(DP[i-a] + b for a,b in magics)

ans = min(DP[H:])

print(ans)


Fixed submission:
H,N = map(int,input().split())
magics = [list(map(int,input().split())) for _ in range(N)]

max_A = max(a for a,b in magics)
INF = 10**10
DP = [INF]*(H+max_A)
DP[0] = 0

for i in range(1,H+max_A):
    DP[i] = min(DP[i-a] + b for a,b in magics)
    
ans = min(DP[H:])
print(ans)

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

DP = [float('inf')]*(H+max(A))
DP[0] = 0
for i in range(H):
    if DP[i] != float('inf'):
        for j in range(N):
            DP[i+A[j]] = min(DP[i+A[j]],DP[i]+B[j])

ans = min(DP[H:])

print(ans)


Fixed submission:
H,N = map(int,input().split())
magics = [list(map(int,input().split())) for _ in range(N)]

max_A = max(a for a,b in magics)
INF = 10**10
DP = [INF]*(H+max_A)
DP[0] = 0

for i in range(1,H+max_A):
    DP[i] = min(DP[i-a] + b for a,b in magics)
    
ans = min(DP[H:])
print(ans)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
long long ans = 0;
long long N,D,A;
cin >> N >> D >> A;
vector<vector<long long>> enemies(N, vector<long long> (2));
for (int i = 0; i < N; i++)
{
    cin >> enemies.at(i).at(0) >> enemies.at(i).at(1);
}
sort(enemies.begin(),enemies.end(),[](const vector<long long> &alpha,const vector<long long> &beta){return alpha[0] < beta[0];});

queue<vector<long long>> damage;
long long dmg = 0;
for (int i = 0; i < N; i++){
    long long x = enemies.at(i).at(0);
    long long h = enemies.at(i).at(1);
    if (damage.empty()){
        long long bomb = (h+A-1)/A;
        ans += bomb;
        dmg += bomb*A;
        damage.push({x+2*D,bomb});
    }
    else{
        while (!damage.empty()){
            vector<long long> vec;
            vec = damage.front();
            long long d = vec.at(0);
            long long bomb = vec.at(1);
            if (d < x){
                dmg -= bomb*A;
                damage.pop();
            }
            else{
                break;
            }
        }
        if (h > dmg){
            long long bomb = (h-dmg+A-1)/A;
            dmg += bomb*A;
            damage.push({x+2*D,bomb});
            ans += bomb;
        }
        
    }
}

cout << ans << endl;
}

Fixed submission:
N,D,A = map(int,input().split())
enemies = [list(map(int,input().split())) for _ in range(N)]
enemies.sort(key=lambda x:x[0])
ans = 0
from collections import deque
damage = deque()
dmg = 0
for x,h in enemies:
    if len(damage) == 0:
        bomb = -(-h//A)
        damage.append([x+2*D,bomb])
        dmg += bomb*A
        ans += bomb
    else:
        while len(damage) > 0:
            d,bomb = damage.popleft()
            if x > d:
                dmg -= bomb*A
            else:
                damage.appendleft([d,bomb])
                break
        if h > dmg:
            bomb = -(-(h-dmg)//A)
            dmg += bomb*A
            damage.append([x+2*D,bomb])
            ans += bomb

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A = map(int,input().split())
enemies = [list(map(int,input().split())) for _ in range(N)]
enemies.sort(key=lambda x:x[0])
ans = 0
for i in range(N):
    if enemies[i][1] > 0:
        bomb = -(-enemies[i][1]//A)
        j = i
        while j < N and enemies[j][0]-enemies[i][0] <= 2*D:
            enemies[j][1] -= A*bomb
            j += 1
        ans += bomb

print(ans)


Fixed submission:
N,D,A = map(int,input().split())
enemies = [list(map(int,input().split())) for _ in range(N)]
enemies.sort(key=lambda x:x[0])
ans = 0
from collections import deque
damage = deque()
dmg = 0
for x,h in enemies:
    if len(damage) == 0:
        bomb = -(-h//A)
        damage.append([x+2*D,bomb])
        dmg += bomb*A
        ans += bomb
    else:
        while len(damage) > 0:
            d,bomb = damage.popleft()
            if x > d:
                dmg -= bomb*A
            else:
                damage.appendleft([d,bomb])
                break
        if h > dmg:
            bomb = -(-(h-dmg)//A)
            dmg += bomb*A
            damage.append([x+2*D,bomb])
            ans += bomb

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
abc = []
for _ in range(M):
    abc.append(list(map(int,input().split())))

cost = [-float('inf')]*N
cost[0] = 0

for i in range(2):
    for a,b,c in abc:
        a,b = a-1,b-1
            cost[b] = max(cost[b], cost[a] + c)
                
    if i == 0:
        ans = cost[N-1]
    else:
        Max = cost[N-1]


if ans != Max:
    print('inf')
else:
    print(ans)


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

from collections import deque
ls = [deque([]) for _ in range(N)]

for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    ls[a].append([b,c])
cost = [-(10**10)*N]*N
cost[0] = 0

for i in range(N):
    update = False
    q = [deque(m for m in l) for l in ls]
    for j in range(N):
        if cost[j] != -(10**10)*N:
            while q[j]:
                b,c = q[j].pop()
                if cost[b] < cost[j] + c:
                    cost[b] = cost[j] + c
                    update = True
    if i == 0:
        Max = cost[N-1]
    elif i < N-1:
        Max = max(Max,cost[N-1])

if update == True and Max < cost[N-1]:
    print('inf')
else:
    print(Max)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
from collections import deque
v = [deque([]) for _ in range(N)]

for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    v[a].append([b,c])
    v[b].append([a,c])
import math

s = deque([])
for i in range(N):
    ls = [[-1,math.inf]]*N
    ls[i] =  [-1,0]
    q = [deque(j for j in i) for i in v]
    l = deque([i])
    while l:
        u = l.popleft()
        while q[u]:
            e = q[u].popleft()
            if ls[u][1] + e[1] < ls[e[0]][1]:
                ls[e[0]] = [u, ls[u][1] + e[1]]
                l.append(e[0])
    for j,e in enumerate(ls):
        if e[0] != -1:
             s.append([min(j,e[0]),max(j,e[0])])

s = list(map(list, set(map(tuple, s))))
print(M-len(s))


Fixed submission:
N,M = map(int,input().split())
from collections import deque
v = [deque([]) for _ in range(N)]

for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    v[a].append([b,c])
    v[b].append([a,c])

s = deque([])
for i in range(N):
    ls = [[-1,M*10000]]*N
    ls[i] =  [-1,0]
    q = [deque(j for j in k) for k in v]
    l = deque([i])
    while l:
        u = l.popleft()
        x = len(q[u])
        for i in range(x):
            e = q[u].popleft()
            if ls[u][1] + e[1] < ls[e[0]][1]:
                ls[e[0]] = [u, ls[u][1] + e[1]]
                l.append(e[0])
            q[u].append(e)
    for j,e in enumerate(ls):
        if e[0] != -1:
             s.append([min(j,e[0]),max(j,e[0])])

s = list(map(list, set(map(tuple, s))))
print(M-len(s))
Buggy python submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if list[x] == list[x+1]:
        n = n - 1
        if not list[x+1] == list[-1]:
            if list[x+2] == list[x+3]:
                n = n - 1
                if not list[x+3] == list[-1]:
                    if list[x+4] == list[x+5]:
                         n = n - 1
                         y = 1
    x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Fixed submission:
n = input()
a = 's'
b = 'es'
if n[-1] == 's':
    n = n + b
else:
    n = n + a
print(n)

Buggy python submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if list[x] == list[x+1]:
        n = n - 1
        if not list[x+1] == list[-1]:
            if list[x+2] == list[x+3]:
                n = n - 1
                if not list[x+3] == list[-1]:
                    if list[x+4] == list[x+5]:
                         n = n - 1
                         y = 1
    x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Fixed submission:
n = input()
a = 's'
b = 'es'
if n[-1] == 's':
    n = n + b
else:
    n = n + a
print(n)

Buggy python submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if not list[x-1] == list[-1]:
        if list[x] == list[x+1]:
            if not list[x+1] == list[-1]:
                if list[x+2] == list[x+3]:
                    if not list[x+3] == list[-1]:
                        if list[x+4] == list[x+5]:
                            y = 1
    x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Fixed submission:
n = input()
a = 's'
b = 'es'
if n[-1] == 's':
    n = n + b
else:
    n = n + a
print(n)

Buggy python submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if list[x] == list[x+1]:
        if not list[x+1] == list[-1]:
            if list[x+2] == list[x+3]:
                if not list[x+3] == list[-1]:
                    if list[x+4] == list[x+5]:
                        y = 1
    if not x+7 > len(list):
        x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Fixed submission:
n = input()
a = 's'
b = 'es'
if n[-1] == 's':
    n = n + b
else:
    n = n + a
print(n)