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

Fixed submission:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, k = nm()
    if k > 45:
        k = 45
    a = nl()
    b = [0]*n
    for _ in range(k):
        for i in range(n):
            b[max(0, i - a[i])] += 1
            if i + a[i] + 1 < n:
                b[i + a[i] + 1] -= 1
        for i in range(n-1):
            b[i+1] += b[i]
            a[i] = 0
        a[-1] = 0
        b, a = a, b
    print(*a)
    return

solve()

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
from numba import njit

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

@njit(cache=True)
def solve(n, k, a):
    if n == 0:
        return
    for _ in range(k):
        b = [0]*n
        for i in range(n):
            if i > a[i]:
                b[i-a[i]] += 1
            else:
                b[0] += 1
            if i + a[i] + 1 < n:
                b[i + a[i] + 1] -= 1
        a = list(accumulate(b))
        if min(a) >= n:
            break
    print(*a)
    return

solve(0, 0, 0)
n, k = nm()
a = nl()
solve(n, k, a)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
from numba import njit

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

@njit(cache=True)
def solve():
    n, k = nm()
    a = nl()
    for _ in range(k):
        b = [0]*n
        for i in range(n):
            if i > a[i]:
                b[i-a[i]] += 1
            else:
                b[0] += 1
            if i + a[i] + 1 < n:
                b[i + a[i] + 1] -= 1
        a = list(accumulate(b))
        if min(a) >= n:
            break
    print(*a)
    return

solve()
Problem p02662 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n, s = nm()
a = nl()
mod = 998244353
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    v = a[i]
    for j in range(s, -1, -1):
        dp[i+1][j] = dp[i][j] * 2 % mod
        if v + j <= s:
            dp[i+1][v+j] = (dp[i+1][v+j] + dp[i][j]) % mod

print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n, s = nm()
a = nl()
mod = 998244353
dp = [0]*(s+1)
dp[0] = 1
for i in range(n):
    v = a[i]
    for j in range(s, -1, -1):
        dp[j] = (dp[j]*2 + dp[j-v]*(j >= v)) % mod
print(dp[s])
Problem p02709 (python)

Fixed submission:
import sys

stdin = sys.stdin
sys.setrecursionlimit(10**6)
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
lis = [(e, i) for i, e in enumerate(a)]
lis.sort()
dp = [[-1]*n for _ in range(n)]

def solve(l, r):
    if l > r:
        return 0
    if dp[l][r] >= 0:
        return dp[l][r]
    idx = r - l
    e, i = lis[idx]
    dp[l][r] = max(abs(i-l)*e + solve(l+1, r), abs(r-i)*e + solve(l, r-1))
    return dp[l][r]

print(solve(0, n-1))

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
lis = [(e, i) for i, e in enumerate(a)]
lis.sort()
dp = [[-1]*n for _ in range(n)]

def solve(l, r):
    if l > r:
        return 0
    if dp[l][r] >= 0:
        return dp[l][r]
    idx = r - l
    e, i = lis[idx]
    dp[l][r] = max(abs(i-l)*e + solve(l+1, r), abs(r-i)*e + solve(l, r-1))
    return dp[l][r]

print(solve(0, n-1))
Problem p02716 (python)

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
dp = [[0]*3 for _ in range(n+5)]
t = n%2
for i in range(n):
    dp[i][0] = dp[i-2][0] + a[i]
    dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + a[i]
    if t:
        dp[i][2] = max(dp[i-2][2], dp[i-3][1], dp[i-4][0]) + a[i]
if t:
    print(max(dp[n-3][0], dp[n-2][1], dp[n-1][2]))
else:
    print(max(dp[n-2][0], dp[n-1][1]))

Buggy submission (verdict: Runtime Error):
#![allow(unused_imports, non_snake_case)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

macro_rules! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }
    let mut dp = vec![vec![0; 3]; n+4];
    for i in 0..n{
        dp[i + 4][0] = dp[i + 2][0] + a[i];
        dp[i + 4][1] = max!(dp[i+2][1], dp[i+1][0]) + a[i];
        if n & 1 > 0 {
            dp[i + 4][2] = max!(dp[i + 2][2], dp[i + 1][1], dp[i][0]) + a[i];
        }
    }
    if n & 1 > 0 {
        println!("{}", max!(dp[n+1][0], dp[n+2][1], dp[n+3][2]));
    } else {
        println!("{}", max!(dp[n+2][0], dp[n+3][1]));
    }
}
Problem p02764 (python)

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

def intersection(p, q, eps = 10**-7):
    x1, y1, r1 = p
    x2, y2, r2 = q
    X = x2 - x1; Y = y2 - y1
    d = X**2 + Y**2
    c1 = r1**2; c2 = r2**2

    rc = (d + c1 - c2) / 2
    rs = d * c1 - rc ** 2
    
    if rs < eps: return list()
    
    rs **= .5
    p1x = x1 + (rc * X + rs * Y) / d
    p1y = y1 + (rc * Y - rs * X) / d
    p2x = x1 + (rc * X + rs * Y) / d
    p2y = y1 + (rc * Y + rs * X) / d
    return [(p1x, p1y), (p2x, p2y)]

eps = 10**-7
n,k = nm()
if k == 1: print(0); exit(0)
niku = [tuple(nm()) for _ in range(n)]
l = [c*(x**2+y**2)**.5 for x,y,c in niku]
l.sort()
hi = l[k-1]
lo = 0
for _ in range(50):
  mid = (hi+lo)/2
  l = [(x,y,mid/c) for x,y,c in niku]
  p = [(x,y) for x,y,c in niku]
  for i in range(n-1):
    for j in range(i+1,n):
      p.extend(intersection(l[i], l[j]))
  for x,y in p:
    f = sum((v-x)**2 + (w-y)**2 <= r**2 + eps for v,w,r in l)
    if f >= k:
      hi = mid
      break
  else:
    lo = mid
print(hi)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

def intersection(p,q):
    x1, y1, r1 = p
    x2, y2, r2 = q
    d = ((x1 - x2)**2 + (y1 - y2)**2)**.5
    if d > r1 + r2 or abs(r1 - r2) > d:
        return list()
    rc = (d**2 + r1**2 - r2**2) / (2 * d)
    rs = (r1**2 - rc**2)**.5
    vx = (x2 - x1) / d
    vy = (y2 - y1) / d
    p1x = x1 + rc * vx + rs * vy
    p1y = y1 + rc * vy - rs * vx
    p2x = x1 + rc * vx - rs * vy
    p2y = y1 + rc * vy + rs * vx
    return [(p1x, p1y), (p2x, p2y)]

n,k = nm()
if k == 1: print(0); exit(0)
niku = [tuple(nm()) for _ in range(n)]
l = [c*(x**2+y**2)**.5 for x,y,c in niku]
l.sort()
hi = l[k-1]
lo = 0
for _ in range(200):
  mid = (hi+lo)/2
  l = [(x,y,mid/c) for x,y,c in niku]
  p = [(x,y) for x,y,c in niku]
  for i in range(n-1):
    for j in range(i+1,n):
      p.extend(intersection(l[i], l[j]))
  for x,y in p:
    f = sum((v-x)**2 + (w-y)**2 <= r**2 for v,w,r in l)
    if f >= k:
      hi = mid
      break
  else:
    lo = mid
print(hi)
Problem p02774 (python)

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,k = nm()
l = nl()
f = list(filter(lambda x:x>0, l))
g = list(filter(lambda x:x<0, l))
f.sort(); g.sort(reverse=True)
pl = len(f); mi = len(g)
ze = n - pl - mi
tomi = pl*mi
if tomi >= k:
    def jud(z):
        ret = 0
        i = mi
        for x in f:
            while i and x*g[i-1] <= z: i -= 1
            ret += mi - i
        return ret
    ok,ng = 0,max(f)*min(g)-1
    while ok - ng > 1:
        mid = (ok+ng)//2
        if jud(mid) < k:
            ng = mid
        else:
            ok = mid
    print(ok)
    exit(0)

tomi += ze*(n-ze) + (ze-1)*ze//2
if tomi >= k:
    print(0); exit(0)

else:
    k -= tomi
    def jud2(z):
        ret = 0
        i = pl
        for e,x in enumerate(f):
            while i and f[i-1]*x > z: i -= 1
            ret += i - (e<=i-1)
        i = mi
        for e,x in enumerate(g):
            while i and g[i-1]*x > z: i -= 1
            ret += i - (e<=i-1)
        return ret//2
    ok,ng = 0,max(max(f+[0])**2, min(g+[0])**2)
    while ng - ok > 1:
        mid = (ok+ng)//2
        if jud2(mid) < k:
            ok = mid
        else:
            ng = mid
    print(ng)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,k = nm()
l = nl()
f = list(filter(lambda x:x>0, l))
g = list(filter(lambda x:x<0, l))
f.sort(); g.sort(reverse=True)
pl = len(f); mi = len(g)
ze = n - pl - mi
tomi = pl*mi
if tomi >= k:
    def jud(z):
        ret = 0
        i = mi
        for x in f:
            while i and x*g[i-1] <= z: i -= 1
            ret += mi - i
        return ret
    ok,ng = 0,max(f)*min(g)-1
    while ok - ng > 1:
        mid = (ok+ng)//2
        if jud(mid) < k:
            ng = mid
        else:
            ok = mid
    print(ok)
    exit(0)

tomi += ze*(n-ze) + (ze-1)*ze//2
if tomi >= k:
    print(0); exit(0)

else:
    k -= tomi
    def jud2(z):
        ret = 0
        i = pl
        for e,x in enumerate(f):
            while i and f[i-1]*x > z: i -= 1
            ret += i - (e<=i-1)
        i = mi
        for e,x in enumerate(g):
            while i and g[i-1]*x > z: i -= 1
            ret += i - (e<=i-1)
        return ret//2
    ok,ng = 0,max(max(f)**2, min(g)**2)
    while ng - ok > 1:
        mid = (ok+ng)//2
        if jud2(mid) < k:
            ok = mid
        else:
            ng = mid
    print(ng)
Problem p02822 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


n = ni()
G = [list() for _ in range(n)]
for _ in range(n-1):
  a, b = nm()
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
  
  
mod = 10**9 + 7
dub = [1]*(n+1)
for i in range(n):
  dub[i+1] = dub[i] * 2
  if dub[i+1] > mod:
    dub[i+1] -= mod
    
size = [-1]*n
q = [0]
while q:
  v = q[-1]
  if size[v] < 0:
    for x in G[v]:
      if size[x] < 0:
        q.append(x)
    size[v] = 0
  else:
    size[v] = 1
    for x in G[v]:
      size[v] += size[x]
    q.pop()

ans = 0
for v in range(n):
  c = 0
  res = 1
  for x in G[v]:
    if size[x] < size[v]:
      c += size[x]
      res += dub[size[x]] - 1
  res += dub[n-1-c] - 1
  res %= mod
  ans = (ans + dub[n-1] - res) % mod
print(ans * pow(dub[n], mod-2, mod) % mod)

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


n = ni()
G = [list() for _ in range(n)]
for _ in range(n-1):
  a, b = nm()
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
  
  
mod = 10**9 + 7
dub = [1]*(n+1)
for i in range(n):
  dub[i+1] = dub[i] * 2
  if dub[i+1] > mod:
    dub[i+1] -= mod
    
size = [1]*n
def dfs_depandsize(tree,v,p):
    for x in tree[v]:
        if x == p:
            continue
        size[v] += dfs_depandsize(tree,x,v)
    return size[v]
dfs_depandsize(G, 0, -1)
ans = 0
for v in range(n):
  c = 0
  res = 1
  for x in G[v]:
    if size[x] < size[v]:
      c += size[x]
      res += dub[size[x]] - 1
  res += dub[n-1-c] - 1
  res %= mod
  ans = (ans + dub[n-1] - res) % mod
print(ans * pow(dub[n], mod-2, mod) % mod)
Problem p02838 (python)

Fixed submission:
n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
b = [sum(1 for x in a if x&(1<<i)) for i in range(60)]
ans = 0
for i in range(60):
  t = b[i]*(n-b[i])
  m = (1<<i)%mod
  ans = (ans + t*m%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def fold(x,m):
    y = 0
    for _ in range(m):
        if x & 1:
            y |= 1
        y <<= 1
        x >>= 1
    return x|y



h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    g[i][j] = abs(a[i][j] - b[i][j])
a = b = 0
m = max(max(x) for x in g)
mask = (1<<(m*(h+w+2)//2)) - 1

dp = [[0]*(w+1) for _ in range(h+1)]
dp[0][1] = 1
dp[1][0] = 1
for i in range(1,h+1):
  for j in range(1,w+1):
    par = dp[i-1][j] | dp[i][j-1]
    dp[i][j] = mask&(par<<g[i-1][j-1])|fold(par,g[i-1][j-1])
for i in range(m*(h+w+2)//2):
  if dp[h][w]&(1<<i):
    print(i)
    break
Problem p02839 (python)

Fixed submission:
def fold(x,m):
    y = 0
    for _ in range(m):
        y |= x&1
        y <<= 1
        x >>= 1
    return x|y

lmi = lambda: list(map(int, input().split()))

h,w = lmi()
a = [lmi() for _ in range(2*h)]
g = [[abs(a[i][j] - a[i+h][j]) for j in range(w)] for i in range(h)]

mask = (1<<12801) - 1

dp = [[0]*(w+1) for _ in range(h+1)]
dp[0][0] = 1
for i in range(h):
  for j in range(w):
    cur,par = g[i][j],dp[i][j]
    pos = (par<<cur)|fold(par,cur)
    pos &= mask
    dp[i+1][j] |= pos
    dp[i][j+1] |= pos
for i in range(12801):
  if dp[-1][-2]&(1<<i):
    print(i)
    break

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    g[i][j] = abs(a[i][j] - b[i][j])
a = b = 0
m = max(max(x) for x in g)*(h+w)//2 + 1
dp = [[[False]*m for _ in range(w+1)] for _ in range(h+1)]
dp[0][1][0] = True
dp[1][0][0] = True
for i in range(1,h+1):
  for j in range(1,w+1):
    for x in range(m):
      if dp[i-1][j][x] or dp[i][j-1][x]:
        dp[i][j][abs(x-g[i-1][j-1])] |= True
        if x + g[i-1][j-1] < 3000:
            dp[i][j][x+g[i-1][j-1]] |= True
for x in range(m):
  if dp[h][w][x]:
    print(x)
    break

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    g[i][j] = abs(a[i][j] - b[i][j])
a = b = 0
m = max(max(x) for x in g)*(h+w)
dp = [[[False]*m for _ in range(w+1)] for _ in range(h+1)]
dp[0][1][0] = True
dp[1][0][0] = True
for i in range(1,h+1):
  for j in range(1,w+1):
    for x in range(m):
      if dp[i-1][j][x] or dp[i][j-1][x]:
        dp[i][j][abs(x-g[i-1][j-1])] |= True
        if x + g[i-1][j-1] < 3000:
            dp[i][j][x+g[i-1][j-1]] |= True
for x in range(m):
  if dp[h][w][x]:
    print(x)
    break
Problem p02840 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
  n, x, d = nm()
  ans = 0
  if d == 0:
    print(1 if x == 0 else n+1)
    return
  if d < 0:
    d = -d
    x = -x
  g = dict()
  g[0] = [(0, 0)]
  for i in range(1, n+1):
    c, y = divmod(x * i, d)
    # print((c, y))
    f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
    if y not in g:
      g[y] = list()
    g[y].append(f)
  for y in g:
    f = sorted(g[y])
    # print(f)
    cx, cy = f[0]
    for nx, ny in f:
      if nx <= cy:
        cx = min(nx, cx)
        cy = max(ny, cy)
      else:
        ans += cy - cx + 1
        cx, cy = nx, ny
    ans += cy - cx + 1
  print(ans)
  return

solve()

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
  n, x, d = nm()
  ans = 0
  if d == 0:
    print(0 if x == 0 else n)
  if d < 0:
    d = -d
    x = -x
  g = dict()
  g[0] = [(0, 0)]
  for i in range(1, n+1):
    c, y = divmod(x * i, d)
    # print((c, y))
    f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
    if y not in g:
      g[y] = list()
    g[y].append(f)
  for y in g:
    f = sorted(g[y])
    # print(f)
    cx, cy = f[0]
    for nx, ny in f:
      if nx <= cy:
        cx = min(nx, cx)
        cy = max(ny, cy)
      else:
        ans += cy - cx + 1
        cx, cy = nx, ny
    ans += cy - cx + 1
  print(ans)
  return

solve()
Problem p02842 (python)

Fixed submission:
n=int(input())
for i in range(50001):
  if i*1.08//1 == n:
    print(i)
    break
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
for i in range(50001):
  if i*1.08//1 == n:
    print(i)
    break
else:
  print(":(")
Problem p02854 (python)

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

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

c = a[-1]
for i in range(n):
    c = min(c, abs(a[-1]-a[i]*2))
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
c = a[-1]
for i in range(n):
   p = abs(a[-1]-a[i]*2)
      if c > p:
        c = p   
print(c)
Problem p02882 (python)

Fixed submission:
from math import atan, pi

a,b,v = map(int, input().split())
if v == a*a*b:
  theta = pi/2
elif v*2 < a*a*b:
  e= v*2/(a*b)
  theta = atan(e/b)
else:
  e = 2*(a*b - v/a)/a
  theta = atan(a/e)
theta *= 180/pi
print(90.0 - theta)

Buggy submission (verdict: Runtime Error):
from math import atan, pi

a,b,v = map(int, input().split())
if v*2 < a*a*b:
  e= v*2/(a*b)
  theta = atan(e/b)
else:
  e = 2*(a*b - v/a)/a
  theta = atan(a/e)
theta *= 180/pi
print(90.0 - theta)
Problem p02889 (python)

Fixed submission:
n,m,l = map(int,input().split())
g = [[1<<30]*n for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a-1][b-1] = c
  g[b-1][a-1] = c
for i in range(n):
  g[i][i] = 0

def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g

g = bell(g,n)
for i in range(n):
  for j in range(n):
    if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30
g = bell(g,n)

q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  if g[s-1][t-1]>>30:
    print(-1)
  else:
    print(g[s-1][t-1]-1)

Buggy submission (verdict: Runtime Error):
nm = lambda : map(int,input().split())
nl = lambda : list(nm())
import heapq as h

n,m,l = nm()
g = [list() for _ in range(n+1)]
ans = [0]
for _ in range(m):
    a,b,c = nm()
    g[a].append((b,c))
    g[b].append((a,c))
q = int(input())

def move(tup,cost):
    if tup[1] + cost > 0:
        if l < cost:
            return -1
        return (tup[0]+1,cost-l)
    return (tup[0],tup[1]+cost)

for st in range(1,n+1):
    dist = [-1]*(n+1)
    que = [((0,-l),st)]
    while que:
        tup,v = h.heappop(que)
        if dist[v] != -1 and dist[v] < tup:
            continue
        dist[v] = tup
        for x,c in g[v]:
            new = move(tup,c)
            if dist[x] == -1 or dist[x] > new:
                h.heappush(que,(new,x))
    ans.append(dist)

for _ in range(q):
    s,t = nm()
    if ans[s][t] == -1:
        print(-1)
    else:
        print(ans[s][t][0])
Problem p02901 (python)

Fixed submission:
n,m = map(int,input().split())
dp = [10**9]*(2**n)
dp[0] = 0
for _ in range(m):
  a,_ = map(int,input().split())
  c = list(map(int,input().split()))
  t = 0
  for x in c:
    t |= 1<<(x-1)
  for b in range(2**n):
    dp[b|t] = min(dp[b|t],dp[b]+a)
if dp[-1] > 10**8:
  print(-1)
else:
  print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
dp = [10**9]*(2**n)
for i in range(m):
  a,_ = map(int,input().split())
  c = list(map(int,input().split()))
  t = 0
  for x in c:
    t |= 1<<(x-1)
  for b in range(2**n):
    dp[b|t] = min(dp[b],dp[b+a])
if dp[-1] > 10**8:
  print(-1)
else:
  print(dp[-1])
Problem p02903 (python)

Fixed submission:
h,w,a,b = map(int,input().split())
if b > h//2 or a > w//2:
    print("No")
    exit(0)
for _ in range(h-b):
    print("0"*(w-a) + "1"*a)
for _ in range(b):
    print("1"*(w-a) + "0"*a)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
raw = list(map(int,input().split()))
num = 2**(n-1).bit_length()
seg1 = [0]*2*num
seg2 = [n]*2*num

def build(raw):
    for i in range(n):
        seg1[i+num-1] = raw[i]
        seg2[i+num-1] = raw[i]
    for i in range(num-2,-1,-1):
        seg1[i] = max(seg1[2*i+1],seg1[2*i+2])
        seg2[i] = min(seg2[2*i+1],seg2[2*i+2])
    return True

build(raw)
cnt = n-k+1

def query(seg,ele,segf,p,q):
    if q <= p:
        return False
    p += num - 1
    q += num - 2
    res = ele
    while q-p > 1:
        if not p%2:
            res = segf(res,seg[p])
        if q%2:
            res = segf(res,seg[q])
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res = segf(res,seg[p])
    else:
        res = segf(res,seg[p],seg[q])
    return res

def check(i):
    #print(i,query(seg1,0,max,i,i+k+1),query(seg2,n+1,min,i,i+k+1))
    return query(seg1,0,max,i,i+k+1) == raw[i+k] and query(seg2,n+1,min,i,i+k+1) == raw[i]

t = [0]*n
f = -1
c = -1
for i in range(n):
    if raw[i] > c:
        f += 1
    else:
        f = 0
    c = raw[i]
    t[i] = f

for i in range(n-k):
    if t[i+k-1] - t[i] == k-1 or check(i):
        #print("y")
        cnt -= 1
print(cnt)