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

Fixed submission:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
sys.setrecursionlimit(10**6)

n = ni()
a = na()
b = []
for i in range(n):
    b.append((a[i],i))
 
b.sort(reverse=True)

dp = [[0]*(n+1) for i in range(n+1)]

for i in range(1,n+1):
    x,y = b[i-1]
    for j in range(i+1):
        left = dp[i-1][j-1] + x*abs(y-j+1) if j > 0 else -1
        right = dp[i-1][j] + x*abs(n-i+j-y) if j < i else -1
        dp[i][j] = max(left,right)

print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = []
for i in range(n):
    b.append((a[i],i))

b.sort(reverse=True)

ans = 0

def f(left,right,k,c):
    if k == n:
        return c
    i,j = b[k]
    x = abs(j-left)
    y = abs(right-j)
    return max(f(left+1,right,k+1,c+x*i), f(left,right-1,k+1,c+y*i))

ans = f(0,n-1,0,0)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = []
for i in range(n):
    b.append((a[i],i))

b.sort(reverse=True)

ans = 0

def f(left,right,k,c):
    if k == n:
        return c
    i,j = b[k]
    x = j-left
    y = right-j
    return max(f(left+1,right,k+1,c+x*i), f(left,right-1,k+1,c+y*i))

ans = f(0,n-1,0,0)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = []
r = [0]
for i in range(n):
    b.append((a[i],i))
for i in a:
    r.append(r[-1]+i)

b.sort(reverse=True)

ans = 0

def f(left,right,k,c):
    if k == n:
        return c
    i,j = b[k]
    p = r[j]
    q = r[n]-r[j+1]
    x = (j-left)*i
    y = (right-j)*i
    if x >= 0 and x+p >= y+q:
        return f(left+1, right, k+1, c+x)
    else:
        return f(left, right-1, k+1, c+y)

ans = f(0,n-1,0,0)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = []
r = [0]
for i in range(n):
    b.append((a[i],i))
for i in a:
    r.append(r[-1]+i)

b.sort(reverse=True)

ans = 0

def f(left,right,k,c):
    if k == n:
        return c
    i,j = b[k]
    p = r[j]
    q = r[n]-r[j+1]
    x = (j-left)*i+p
    y = (right-j)*i+q
    if x >= y:
        return f(left+1,right,k+1,c+(j-left)*i)
    elif x < y:
        return f(left,right-1,k+1,c+(right-j)*i)

ans = f(0,n-1,0,0)

print(ans)
Problem p02716 (python)

Fixed submission:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

dp = [0]*n
b = a[0]

dp[1] = max(a[0],a[1])

for i in range(2,n):
    if i%2 == 0:
        b += a[i]
        dp[i] = max(dp[i-1],dp[i-2]+a[i])
    else:
        dp[i] = max(b,dp[i-2]+a[i])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import numpy as np

n = ni()
a = na()
x = n//2

dp = [[a[i]]*(x+1) for i in range(n)]

se = [2,3,4]

for i in range(n):
    for j in range(2,x+1):
        a = -100000000000
        for k in se:
            p = i-k
            if p >= 0:
                a = max(a,dp[p][j-1])
        dp[i][j] += a

print(dp[n-1][x])
Problem p02855 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w,K = na()
s = []
for i in range(h):
    s.append(list(ns()))

ans = []
k = 1
bb = 0

for i in range(h):
    if '#' in s[i]:
        ret = []
        flag = True
        for j in range(w):
            if s[i][j] == '#':
                if flag:
                    flag = False
                else:
                    k+=1
            ret.append(k)
        ans.append(ret)
        k+=1
        if bb:
            for _ in range(bb):
                ans.append(ans[-1])
            bb = 0
    else:
        if len(ans) == 0:
            bb += 1
            continue
        ans.append(ans[-1])


for i in ans:
    print(*i,sep=' ')

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w,k = na()
s = []
for i in range(h):
    s.append(list(ns()))

ans = []
k = 1
for i in range(h):
    if '#' in s[i]:
        ret = []
        for j in range(w):
            if j != 0 and s[i][j] == '#':
                k+=1
            ret.append(k)
        ans.append(ret)
        k+=1
    else:
        ans.append(ans[-1])

for i in ans:
    print(*i,sep=' ')
Problem p02975 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if a[0] == a[m-1] and a[m] == a[2*m-1] and a[2*m] == a[3*m-1] and a[0]^a[m] == a[2*m]:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if A[0] == A[m-1] and A[m] == A[2*m-1] and A[2*m] == A[3*m-1] and A[0]^A[m] == A[2*m]:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

if n%2 == 0:
	print(['No','Yes'][all([e == a[0] for e in a[1:] and a[0] == 0])])
else:
	a = sorted(a)
	b = [a[0]]
	for i in range(1,n):
		b.append(a[0]^a[i])
	b = sorted(b)
	c = a[-1::-1]
	d = [c[0]]
	for i in range(1,n):
		d.append(c[0]^c[i])
	c = sorted(c)
	d = sorted(d)
	print(['No','Yes'][a==b and c==d])

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

if n%2 == 0:
	print(['No','Yes'][all([e == a[0] for e in a[1:] and a[0] == 0])])
else:
	a = sorted(a)
	b = [a[0]]
	for i in range(1,n):
		b.append(a[0]^a[i])
	b = sorted(b)
	
    c = a[-1::-1]
	d = [c[0]]
	for i in range(1,n):
		d.append(c[0]^c[i])
	c = sorted(c)
	d = sorted(d)
	print(['No','Yes'][a==b and c==d])
Problem p03006 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import collections

n = ni()

if n == 1:
    print(1)
    exit()

balls = []
dis = []

for i in range(n):
    x,y = na()
    for b in balls:
        k = '_1' if (b[0]-x)*(b[1]-y) > 0 else '_0'
        dis.append(str(abs(b[0]-x))+'_'+str(abs(b[1]-y))+k)
    balls.append([x,y])

c = collections.Counter(dis)
m = c.most_common()

if len(m) == 1:
    print(1)
    exit()

u = m[0][1]

print(n-u)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import collections

n = ni()
balls = []
dis = []

for i in range(n):
    x,y = na()
    for b in balls:
        dis.append(str(abs(b[0]-x))+'_'+str(abs(b[1]-y)))
    balls.append([x,y])

c = collections.Counter(dis)
u = c.most_common()[0][1]

print(n-u)
Problem p03044 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
g = [[] for i in range(n)]

for i in range(n-1):
    u,v,w = na()
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))

dp = [0]*n

def f(a,b,c):
    dp[b] = c
    for i,j in g[b]:
        if i != a:
            f(b,i,c+j)

f(0,0,0)

for k in dp:
    print(k%2)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
g = [[] for i in range(n)]

for i in range(n-1):
    u,v,w = na()
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))

dp = [0]*n

def f(a,b,c):
    dp[b] = c
    for i,j in g[b]:
        if i != a:
            f(b,i,c+j)

f(0,0,0)

for k in dp:
    print(k%2)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
g = [[] for i in range(n)]

for i in range(n-1):
    u,v,w = na()
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))

dp = [0]*n

def f(a,b,c):
    dp[b] = c
    for i,j in g[b]:
        if i != a:
            f(b,i,c+j)

f(0,0,0)
print(dp)
for k in dp:
    print(k%2)
Problem p03087 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
 
import bisect
 
n,q = na()
s = ns()
x = []
 
for r in range(len(s)-1):
  if s[r] == 'A':
    if s[r+1] == 'C':
      x.append(r)
 
for i in range(q):
  l,r = na()
  b = bisect.bisect_left(x,l-1)
  a = bisect.bisect_right(x,r-2)
  c = a-b if a-b>0 else 0
  print(c)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
 
import bisect
 
n,q = na()
s = ns()
x = []
 
for r in range(len(s)):
  if s[r] == 'A':
    if s[r+1] == 'C':
      x.append(r)
 
for i in range(q):
  l,r = na()
  k = [j for j in x if j >= l-1 and j <= r-2]
  print(len(k))

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

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

import bisect

n,q = na()
s = ns()
x = []

for r in range(len(s)):
  if s[r] == 'A':
    if s[r+1] == 'C':
      x.append(r)

for i in range(q):
  l,r = na()
  b = bisect.bisect_left(x,l-1)
  a = bisect.bisect_right(x,r-2)
  c = a-b if a-b>0 else 0
  print(c)
Problem p03090 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
print(n*(n-1)//2-n//2)

for i in range(n):
    a = n-1-i if n%2 == 0 else n-2-i
    for j in range(i+1,n):
        if j != a:
            print(i+1,j+1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
print(m*(m-1)//2-m//2)

for i in range(n):
    a = n-1-i if n%2 == 0 else n-2-i
    for j in range(i,n):
        if j != a:
            print(i+1,j+1)
Problem p03156 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a,b = na()
p = na()
c = [0,0,0]

for i in p:
    if i <= a:
        c[0] += 1
    elif a+1 <= i <= b:
        c[1] += 1
    else:
        c[2] += 1

print(min(c))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a,b = na()
p = na()
c = [0,0,0]

for i in p:
    if i <= a:
        c[0] += 1
    elif a+1 < p <= b:
        c[1] += 1
    else:
        c[2] += 1

print(c)
Problem p03229 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = []

for i in range(n):
    a.append(ni())

a.sort()
t = n//2

if n%2 == 0:
    ans = (sum(a[t+1:])-sum(a[:t-1]))*2+a[t]-a[t-1]
    print(ans)
else:
    x = 2*(sum(a[t+1:])-sum(a[:t-1])) - a[t-1] - a[t]
    y = 2*(sum(a[t+2:])-sum(a[:t])) + a[t+1] + a[t]
    print(max(x,y))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = []

for i in range(n):
    a.append(ni())

a.sort()
k = n//2

if n%2 == 0:
    ans = (sum(a[t+1:])-sum(a[:t-1]))*2+a[t]-a[t-1]
    print(ans)
else:
    x = 2*(sum(a[t+1:])-sum(a[:t-1])) - a[t-1] - a[t]
    y = 2*(sum(a[t+2:])-sum(a[:t])) + a[t+1] + a[t]
    print(max(x,y))
Problem p03471 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,y = na()
ans = [-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    a = 10000*i + 5000*j + 1000*(n-i-j)
    if a == y:
      ans = [i,j,n-i-j]

print(ans[0],ans[1],ans[2])

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,y = ni()
ans = [-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    a = 10000*i + 5000*j + 1000*(n-i-j)
    if a == y:
      ans = [i,j,ni-j]

print(ans)
Problem p03569 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
ans = 0
r = 0
l = len(s)-1
while r < l:
  if s[r] == s[l]:
    r += 1
    l -= 1
  elif s[r] == "x":
    ans += 1
    r += 1
  elif s[l] == "x":
    ans += 1
    l -= 1
  else:
    print(-1)
    exit()

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
ans = 0
r = 0
l = len(s)-1
while r < l:
  if s[r] == s[l]:
    r += 1
    l -= 1
  elif s[r] == "x":
    ans += 1
    r += 1
  elif s[l] == "x":
    rns += 1
    l -= 1
  else:
    print(-1)
    exit()

print(r)
Problem p03646 (python)

Fixed submission:
import sys
stdin = sys.stdin

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

k = ni()
n = 50

a = k//n
b = k%n
c = n-1+a

ans = [str(c+n-b+1)]*b + [str(c-b)]*(n-b)

print(n)
print(' '.join(ans))

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

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

k = ni()
n = 50

a = k//n
b = k&n
c = n-1+x

ans = [str(c+n-b+1)]*b + [str(c-b)]*(n-b)

print(n)
print(''.join(ans))
Problem p03659 (python)

Fixed submission:
import sys
stdin = sys.stdin

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

n = ni()
a = na()

import numpy as np
a = list(np.cumsum(a))

ans = 100000000000000000

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

print(ans)

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

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

n = ni()
a = na()

import numpy as np
a = list(np.cumsum(a))

import bisect

ma = bisect.bisect_right(a,a[-1]/2)+1
mi = bisect.bisect_left(a,a[-1]/2)-1

ma = ma if ma < n-1 else n-2
mi = mi if mi > 0 else 0
mid = mi+1 if n>2 else mi

print(min(abs(a[-1]-a[ma]*2), abs(a[-1]-a[mi]*2), abs(a[-1]-a[mid]*2)))

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

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

n = ni()
a = na()

import numpy as np
a = list(np.cumsum(a))

import bisect
print(a)

ma = bisect.bisect_right(a,a[-1]/2)+1
mi = bisect.bisect_left(a,a[-1]/2)-1

ma = ma if ma < n-1 else n-2
mi = mi if mi > 0 else 0
mid = mi+1 if n>2 else mi

print(min(abs(a[-1]-a[ma]*2), abs(a[-1]-a[mi]*2), abs(a[-1]-a[mid]*2)))
Problem p03722 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
abc = [tuple(na()) for i in range(m)]

dp = [float('inf')]*n
dp[0] = 0

for i in range(n):
    for a,b,c in abc:
        a,b,c = a-1,b-1,-c
        if dp[a] != float('inf') and dp[b] > dp[a] + c:
            dp[b] = dp[a] + c
            if i == n-1 and b == n-1:
                print('inf')
                exit()

print(-dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import copy

n,m = na()
g = [[] for i in range(n)]

for i in range(m):
    a,b,c = na()
    a,b = a-1,b-1
    g[a].append((b,c))

def dfs(k, rr, ss):
    s = copy.copy(ss)
    ans = -1000000000000
    for v,c in g[k]:
        r = rr+c
        if v == k:
            if c > 0:
                print('inf')
                exit()
            continue
        if v in s:
            if r > s[v]:
                print('inf')
                exit()
            else:
                return
        s[v] = r
        ans = max(ans,dfs(v,r,s))
        if v == n-1:
            ans = max(ans, r)
    return ans

print(dfs(0, 0, {}))
Problem p03837 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

n,m = na()
g = WarshallFloyd(n)
abc = []

for i in range(m):
    a,b,c = na()
    g.add(a-1,b-1,c)
    abc.append([a-1,b-1,c])

dp = g.WarshallFloyd_search()

ans = 0
for a,b,c in abc:
    if dp[a][b] < c:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

n,m = na()
g = WarshallFloyd(n)
abc = []

for i in range(m):
    a,b,c = na()
    g.add(a,b,c)
    abc.append([a,b,c])

dp = g.WarshallFloyd_search()

ans = 0
for a,b,c in abc:
    if dp[a][b] < c:
        ans += 1

print(ans)
Problem p03909 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
co = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(h):
    s = nn()
    if 'snuke' in s:
        j = s.index('snuke')
        print(co[j]+str(i+1))
        exit()

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
co = ['A','B','C','D','E','F','G','H','I','J']

for i in range(h):
    s = nn()
    if 'snuke' in s:
        j = s.index('snuke')
        print(co[j]+str(i+1))
        exit()