Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split())) 
i = list(map(int, input().split())) 
i.sort()
if(n[0] >= n[1]):
  print(0)
  break
else:
	k=1
	kyori=list()
	while k < n[1]: 
	  sa=i[k]-i[k-1]
	  kyori.append(sa)
	  k=k+1
	kyori.sort()
	mm=1
	owari=n[1]-n[0]
	kyori=kyori[0:owari]
	idou=sum(kyori)
	print(idou)

Fixed submission:
n = list(map(int, input().split())) 
i = list(map(int, input().split())) 
i.sort()
if(n[0] >= n[1]):
  print(0)
else:
	k=1
	kyori=list()
	while k < n[1]: 
	  sa=i[k]-i[k-1]
	  kyori.append(sa)
	  k=k+1
	kyori.sort()
	mm=1
	owari=n[1]-n[0]
	kyori=kyori[0:owari]
	idou=sum(kyori)
	print(idou)

Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split())) 
i = list(map(int, input().split())) 
i.sort()
while(n[0] >= n[1]):
  print(0)
  break
k=1
kyori=list()
while k < n[1]: 
  sa=i[k]-i[k-1]
  kyori.append(sa)
  k=k+1
mm=1
idou=sum(kyori)
for mm in range(0, n[0]-1,1):
  saidai=max(kyori)
  idou=idou-saidai
  kyori.remove(saidai)
print(idou)

Fixed submission:
n = list(map(int, input().split())) 
i = list(map(int, input().split())) 
i.sort()
if(n[0] >= n[1]):
  print(0)
else:
	k=1
	kyori=list()
	while k < n[1]: 
	  sa=i[k]-i[k-1]
	  kyori.append(sa)
	  k=k+1
	kyori.sort()
	mm=1
	owari=n[1]-n[0]
	kyori=kyori[0:owari]
	idou=sum(kyori)
	print(idou)

Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split())) 
i = list(map(int, input().split())) 
i.sort()
while(n[0] >= n[1]):
  print(0)
  break
k=1
kyori=list()
while k < n[1]: 
  sa=i[k]-i[k-1]
  kyori.append(sa)
  k=k+1
mm=1
idou=sum(kyori)
idoulist=kyori
for mm in range(0, n[0]-1,1):
  saidai=max(idoulist)
  idou=idou-saidai
  idoulist.remove(saidai)
print(idou)

Fixed submission:
n = list(map(int, input().split())) 
i = list(map(int, input().split())) 
i.sort()
if(n[0] >= n[1]):
  print(0)
else:
	k=1
	kyori=list()
	while k < n[1]: 
	  sa=i[k]-i[k-1]
	  kyori.append(sa)
	  k=k+1
	kyori.sort()
	mm=1
	owari=n[1]-n[0]
	kyori=kyori[0:owari]
	idou=sum(kyori)
	print(idou)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input())
wa=A+B
sa=A-B
seki=A*B
kotae=max(wa,sa,seki)
print(kotae)

Fixed submission:
A,B=map(int,input().split())
wa=A+B
sa=A-B
seki=A*B
kotae=max(wa,sa,seki)
print(kotae)
Buggy python submission (verdict: Runtime Error):
M, D=map(int,input().split())
if D>=M:
  print(M)
elif:
  print(M-1)

Fixed submission:
M, D=map(int,input().split())
if D>=M:
  print(M)
else:
  print(M-1)

Buggy python submission (verdict: Runtime Error):
M, D=map(int,input()>split())
if D>=M:
  print(M)
elif:
  print(M-1)

Fixed submission:
M, D=map(int,input().split())
if D>=M:
  print(M)
else:
  print(M-1)
Buggy python submission (verdict: Runtime Error):
x, y, z = map(int(input().split()))
print(z, x, y)

Fixed submission:
x, y, z = map(int, input().split())
print(z, x, y)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

nums = {}
for a in A:
    nums[a] = nums[a] + 1 if a in nums else 1
for k in A:
    res = 0
    for key in nums.keys():
        cnt = nums.get(key) - 1 if key == k else nums.get(key)
        res += cnt*(cnt-1)//2
    print(res)

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

nums = {}
for a in A:
    nums[a] = nums[a] + 1 if a in nums else 1
res = 0
for key in nums.keys():
    res += nums[key]*(nums[key]-1)//2
for a in A:
    print( res-nums[a]+1 )
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
a, b = '', ''
cnt = 0
for _ in range(q):
    que = input().split()
    if que[0] == '1':
        cnt += 1
    else:
        if (cnt+int(que[1])) %2 == 0:
            a += que[2]
        else:
            b += que[2]
if cnt%2 == 1:
    s = s[-1::-1]
    s = a[-1::-1]+s+b
else:
    s = b[-1::-1]+s+a
print(s)

Fixed submission:
s = input()
q = int(input())
a, b = '', ''
cnt = 0
for _ in range(q):
    que = input().split()
    if que[0] == '1':
        cnt += 1
    else:
        if (cnt+int(que[1])) %2 == 0:
            a += que[2]
        else:
            b += que[2]
if cnt%2 == 1:
    s = a[-1::-1]+s[-1::-1]+b
else:
    s = b[-1::-1]+s+a
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
for i in range(n-k+1):
    cnt = max(cnt, sum(p[i:i+k]))
print((cnt+k)/2)

Fixed submission:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p = list(map(int, input().split()))
cnt = sum(p[0:k])
tmp = 0
for i in range(k, n):
    if p[i] + tmp - p[i-k] > 0:
        cnt += p[i]-p[i-k]+tmp
        tmp = 0
    else:
        tmp += p[i]-p[i-k]
print((cnt+k)/2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
prf = [[] for _ in range(n)]
for i in range(n):
    a.append(int(input()))
    for _ in range(a[-1]):
        x, y = map(int, input().split())
        a[i].append((x-1, y))

res = 0
for i in range(1<<n):
    flg = True
    cnt = 0
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            cnt += 1
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            for x,y in a[j]:
                if y == 0 and ( i >> x & 1 ) == 1:
                    flg = False
                if y == 1 and ( i << x & 1 ) == 0:
                    flg = False
    if flg:
        ans = max(ans, cnt)
print(ans)


Fixed submission:
n = int(input())
prf = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        prf[i].append((x-1, y))

res = 0
for i in range(1<<n):
    flg = True
    cnt = 0
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            cnt += 1
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            for x,y in prf[j]:
                if y == 0 and ( i >> x & 1 ) == 1:
                    flg = False
                if y == 1 and ( i >> x & 1 ) == 0:
                    flg = False
    if flg:
        res = max(res, cnt)
print(res)
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

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

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

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

dgt = int(math.sqrt(max(a)))+1
dp = np.zeros(dgt)

for i in range(n):
    k = np.array(list( bin(a[i])[2:].zfill(dgt)), dtype=int)
    dp += k

res = 0
for i in range(dgt):
    if dp[-i-1] > 0:
        res += 2**i*int(dp[-i-1])*int(n-dp[-i-1]) % (10**9+7)
print(res)

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

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

def a(lst, target, with_replacement=False):
    def _a(idx, l, r, t, w):
        if t == sum(l):
            r.append(l)
            return r
        elif t < sum(l): return
        for u in range(idx, len(lst)):
            _a(u if w else (u + 1), l + [lst[u]], r, t, w)
        return r
    return _a(0, [], [], target, with_replacement)

goods = [100, 101, 102, 103, 104, 105]

res = a( goods, x, True)
print(1) if len(res)>0 else print(0)

Fixed submission:
x = int(input())
cnt = int(x/100)

print(1) if x-cnt*105<=0 else print(0)

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

def a(lst, target, with_replacement=False):
    def _a(idx, l, r, t, w):
        if t == sum(l): r.append(l)
        elif t < sum(l): return
        for u in range(idx, len(lst)):
            _a(u if w else (u + 1), l + [lst[u]], r, t, w)
        return r
    return _a(0, [], [], target, with_replacement)

goods = [100, 101, 102, 103, 104, 105]

res = a( goods, x, True)
print(1) if len(res)>0 else print(0)

Fixed submission:
x = int(input())
cnt = int(x/100)

print(1) if x-cnt*105<=0 else print(0)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)

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

prize = 0
if x==1:
    prize += 300000
elif x==2:
    prize += 200000
elif x==3:
    prize += 100000

if y==1:
    prize += 300000
elif y==2:
    prize += 200000
elif y==3:
    prize += 100000

if x==1 and y==1:
    prize += 400000

print(prize)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[:-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)

Fixed submission:
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))

sum_par = 0
cur, prv = 0, 0
sum_a = sum(a)
mid = sum_a//2
cost = 0
if sum_a%2 != 0:
    cost += 1
    mid += 1
for i in range(n):
    cur += a[i]
    if abs(cur-mid) > abs(prv-mid):
        obj = prv
        break
    prv = cur

cost += abs(obj-mid)*2
print(cost)

Fixed submission:
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
ans = []
clm = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        else:
            ans.append(ans[-1])

if flg:
    ans.insert(0, ans[0])

for a in ans:
    print(*a)


Fixed submission:
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
ans = []
vac = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        else:
            vac.append(i)

if flg:
    ans.insert(0, ans[0])
for k in vac:
    ans.insert(k, ans[k-1])

for a in ans:
    print(*a)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
ans = []
clm = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    print(a)
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        if i == H-1:
            ans.append(ans[-1])

if flg:
    ans.insert(0, ans[0])

for i in range(H):
    print(*ans[i])


Fixed submission:
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
ans = []
vac = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        else:
            vac.append(i)

if flg:
    ans.insert(0, ans[0])
for k in vac:
    ans.insert(k, ans[k-1])

for a in ans:
    print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import threading
sys.setrecursionlimit(10**9)
threading.stack_size(128*1024*1024)
x, y = map(int, input().split())
MOD = 10**9+7
cnt = 0

def move(i, j):
    if i > x or j > y:
        return 0

    if i == x and j == y:
        return 1
    else:
        cnt =  ( move(i+1, j+2) ) % MOD + ( move(i+2, j+1) ) % MOD
        return cnt

if (x+y) % 3 != 0:
    print(0)
    sys.exit()
print(move(0, 0))


Fixed submission:
import sys
input = sys.stdin.readline

x, y = map(int, input().split())
MOD = 10**9+7

def nck_tables(mod, n):
    fac = [1, 1] # 階乗テーブル
    ifac = [1, 1] #階乗の逆元テーブル
    inverse = [0, 1] #逆元テーブル

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac

def nck(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

if (x+y) % 3 != 0 or x > 2*y or y > 2*x:
    print(0)
    sys.exit()

times = (x+y)//3
k = max(x, y) - times
fac, ifac = nck_tables(MOD, times)
ans = nck(times, k, MOD, fac, ifac)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = sorted(list( map(int, input().split()) ))
f = sorted(list( map(int, input().split()) ), reverse=True)

lft = -1
rgt = 10**12
while rgt-lft > 1:
    mid = ( rgt+lft ) // 2
    cnt = 0

    for i, e in enumerate(a):
        cnt += max( 0, e-mid//f[i] )

    if cnt <= k:
        rgt = mid
    else:
        lft = mid

print(rgt)

Fixed submission:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = sorted(list( map(int, input().split()) ))
f = sorted(list( map(int, input().split()) ), reverse=True)

lft = -1
rgt = 10**12
while rgt-lft > 1:
    mid = ( rgt+lft ) // 2
    cnt = 0

    for i, e in enumerate(a):
        cnt += max( 0, e-mid//f[i] )

    if cnt <= k:
        rgt = mid
    else:
        lft = mid

print(rgt)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
l = list(map(int, input().split()))
count = 0
for a, b, c in combinations(l, 3):
    if a<b+c and b<c+a and c<a+b:
        count += 1
print(count)

Fixed submission:
from bisect import bisect_right, bisect_left
n = int(input())
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(n-2):
    for j in range(i+1, n-1):
        count += bisect_left(l, l[i]+l[j]) -j -1
print(count)
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())

count = 0

for i in range(3):
    if s[i] == t[i]:
        count = count + 1

print(count)

Fixed submission:
N = int(input())
pw = N**3
print(pw)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
lr = list(input())
j = 0
counts = [0]
for i in range(n):
    if lr[j] == lr[i]:
        counts[-1] += 1
    else:
        j = i
        counts.append(1)

for _ in range(k):
    if len(counts)>=3:
        counts[0] += counts[1]+counts[2]
        del counts[1:3]
    else:
        counts[0] += counts[1]
        del counts[1]

count = sum(counts) - len(counts)
print(count)

Fixed submission:
n, k = map(int, input().split())
lr = list(input())
j = 0
counts = [0]
for i in range(n):
    if lr[j] == lr[i]:
        counts[-1] += 1
    else:
        j = i
        counts.append(1)

for _ in range(k):
    if len(counts)>=3:
        counts[0] += counts[1]+counts[2]
        del counts[1:3]
    elif len(counts)==2:
        counts[0] += counts[1]
        del counts[1]
    else:
        break

count = sum(counts) - len(counts)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

intSum = 0
for i in range(N):
    intSum = intSum + i

print(intSum)

Fixed submission:
N = int(input())
count = int( (N-1) / 2 )

if (N-1) % 2 == 0:
    intSum = N*count
else:
    intSum = N*count + count + 1

print(intSum)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

DIV = 10**9+7
s = input()
n = len(s)-1
ary = [ (int(s[i]) if s[i] != '?' else -1) for i in range(n) ]
dp = [ [0 for _ in range(13)] for _ in range(n+1) ]
dp[0][0] = 1
for i in range(n):
    for j in range(10):
        if ary[i] != -1 and ary[i] != j:
            continue
        for k in range(13):
            dp[i+1][(k*10+j)%13] += dp[i][k]

    for j in range(13):
        dp[i+1][j] %= DIV
print(dp[n][5])

Fixed submission:
import sys
input = sys.stdin.readline

DIV = 10**9+7
s = input()
n = len(s)-1
ary = [ (int(s[i]) if s[i] != '?' else -1) for i in range(n) ]
dp = [ [0 for _ in range(13)] for _ in range(n+1) ]
dp[0][0] = 1
for i in range(n):
    for j in range(10):
        if ary[i] != -1 and ary[i] != j:
            continue
        for k in range(13):
            dp[i+1][(k*10+j)%13] += dp[i][k]

    for j in range(13):
        dp[i+1][j] %= DIV
print(dp[n][5])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

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

Fixed submission:
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

b = sorted(a)
for x in a:
    print( b[-2] if x == b[-1] else b[-1] )
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
MOD = 10**9+7
input = sys.stdin.readline

N, K = map(int, input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

ans = 1
que = deque( [1, 0, K] )

while que:
    u, p, k = que.popleft()
    ans = (ans*k) % MOD

    if p==0:
        k_next = k-1
    else:
        k_next = k-2
    for v in adj[u]:
        if v == p:
            continue
        que.append( (v, u, k_next) )
        k_next -= 1

print(ans)

Fixed submission:
import sys
from collections import deque
MOD = 10**9+7
input = sys.stdin.readline

N, K = map(int, input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

ans = 1
que = deque( [(1, 0, K)] )

while que:
    u, p, k = que.popleft()
    ans = (ans*k) % MOD

    if p == 0:
        k_next = K-1
    else:
        k_next = K-2

    for v in adj[u]:
        if v == p:
            continue
        que.append( (v, u, k_next) )
        k_next -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
MOD = 10**9+7
n, k = map(int, input().split())

def comb_mod(a, b):
    return int(comb(a, b, exact=True)) % MOD

for i in range(1, k+1):
    blue = comb_mod(k-1, i-1)
    red = comb_mod(n-k-1, i-2) + comb_mod(n-k-1, i) + 2*comb_mod(n-k-1, i-1)
    print((red*blue)%MOD)

Fixed submission:
from scipy.misc import comb
MOD = 10**9+7
n, k = map(int, input().split())

def comb_mod(a, b):
    return int(comb(a, b, exact=True)) % MOD

for i in range(1, k+1):
    blue = comb_mod(k-1, i-1)
    red = comb_mod(n-k+1, i)
    print((red*blue)%MOD)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
INF = 10**7
to = [ [] for _ in range(n) ]
dist = [ [INF]*n for _ in range(3) ]
for _ in range(m):
    u, v = map(int, input().split())
    to[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1
t -= 1

dist[s][0] = 0
que = deque([(s, 0)])
while que:
    u, t = que.popleft()
    d = dist[t][u]
    w = (t+1) % 3
    if t == 2:
        d += 1
    for v in to[u]:
        if dist[w][v] != INF:
            continue
        que.append((v, w))
        dist[w][v] = d
print( dist[0][t] if dist[0][t] < INF else -1 )

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
INF = 10**9
to = [ [] for _ in range(n) ]
dist = [ [INF]*n for _ in range(3) ]
for _ in range(m):
    u, v = map(int, input().split())
    to[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1; t -= 1

dist[0][s] = 0
que = deque([(s, 0)])
while que:
    u, prv = que.popleft()
    d = dist[prv][u]
    cur = (prv+1) % 3
    if prv == 2:
        d += 1
    for v in to[u]:
        if dist[cur][v] != INF:
            continue
        que.append((v, cur))
        dist[cur][v] = d
print( dist[0][t] if dist[0][t] < INF else -1 )
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))

dist, count = 0, 1
for i in range(n+1):
    dist += l[i]
    if dist > x:
        break
    count += 1

print(count)

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

dist, count = 0, 1
for i in range(n):
    dist += l[i]
    if dist > x:
        break
    count += 1

print(count)

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

dist, count = 0, 0
while dist <= x and count < n+1:
    dist += l[count]
    count += 1

print(count)

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

dist, count = 0, 1
for i in range(n):
    dist += l[i]
    if dist > x:
        break
    count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
mat = []
for _ in range(H):
    a = list(input())[:-1]
    mat.append(a)

def calc(H, W, mat):
    x = np.array([])
    for h in range(H):
        cnt = 0
        clm = np.array([])
        for w in range(W):
            if mat[h][w] == '#':
                if cnt == 0:
                    clm = np.hstack( [clm, 0] )
                    cnt = 0
                else:
                    clm = np.hstack( [clm, [cnt]*cnt, 0] )
                    cnt = 0
            else:
                cnt += 1
                if w == W-1:
                    clm = np.hstack( [clm, [cnt]*cnt] )
        x = np.append( x, clm )
    return x.reshape(H, W)

x = calc(H, W, mat)
y = calc(W, H, np.array(mat).T).T
res = np.max( x+y ) - 1
print(int(res))

Fixed submission:
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
F = []
for _ in range(H):
    a = list(input())[:-1]
    F.append(a)

L = [[0]*(W+2) for _ in range(H+2)]
R = [[0]*(W+2) for _ in range(H+2)]
U = [[0]*(W+2) for _ in range(H+2)]
D = [[0]*(W+2) for _ in range(H+2)]

for h in range(1, H+1):
    f = F[h-1]
    l = L[h]
    for w in range(1, W+1):
        l[w] = l[w-1] + 1 if f[w-1] == '.' else 0
        U[h][w] = U[h-1][w] + 1 if f[w-1] == '.' else 0

for h in range(H, 0, -1):
    f = F[h-1]
    r = R[h]
    for w in range(W, 0, -1):
        r[w] = r[w+1] + 1 if f[w-1] == '.' else 0
        D[h][w] = D[h+1][w] + 1 if f[w-1] == '.' else 0

ans = 0
for h in range(1, H+1):
    l, r, u, d = L[h], R[h], U[h], D[h]
    ans = max( ans, max( l[w]+r[w]+u[w]+d[w] for w in range(1, W+1) ))
print(ans-3)