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

Fixed submission:
import sys

sys.setrecursionlimit(10**8)

def find(x):	#xの根を返す
	global table
	global diff_weight
	
	if table[x] == x:
		return x
	else:
		root = find(table[x])
		diff_weight[x] += diff_weight[table[x]] #親の更新に伴う 重みの更新
		table[x] = root	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,w):	#xとyを diff(x,y)=w で繋げる
	w = w - weight(y) + weight(x) 
	x = find(x)	
	y = find(y)
	
	if x == y:
		return
	
	if rank[x] < rank[y]:
		x,y = y,x
		w = -w
	
	table[y] = x
	diff_weight[y] = w
	
	if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y): #xとyか繋がっているか -> return bool
	if find(x) == find(y):
		return True
	else:
		return False

def weight(x):
	find(x)	#経路圧縮
	return diff_weight[x]
		
def diff(x,y): # weight(y)-weight(x)  (繋がってる前提)
	return (weight(y) - weight(x))

		
N,M = map(int,input().split())

table = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N)]	#木の長さ
diff_weight = [0 for i in range(N)]


for i in range(M):
	a,b,D = (map(int,input().split()))
	a -= 1
	b -= 1
	if check(a,b):
		if diff(a,b) != D:
			print('No')
			sys.exit()
	else:
		union(a,b,D)
	
	
print ('Yes')

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**8)

def find(x):	#xの根を返す
	global table
	global diff_weight
	
	if table[x] == x:
		return x
	else:
		diff_weight[x] += diff_weight[table[x]] #親の更新に伴う 重みの更新
		table[x] = find(table[x])	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,w):	#xとyを diff(x,y)=w で繋げる
	w = w - weight(y) + weight(x) 
	x = find(x)	
	y = find(y)
	
	if x == y:
		return
	
	if rank[x] < rank[y]:
		x,y = y,x
		w = -w
	
	table[y] = x
	diff_weight[y] = w
	
	if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y): #xとyか繋がっているか -> return bool
	if find(x) == find(y):
		return True
	else:
		return False

def weight(x):
	find(x)	#経路圧縮
	return diff_weight[x]
		
def diff(x,y): # weight(y)-weight(x)  (繋がってる前提)
	return (weight(y) - weight(x))

		
N,M = map(int,input().split())

table = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N)]	#木の長さ
diff_weight = [0 for i in range(N)]


for i in range(M):
	a,b,D = (map(int,input().split()))
	a -= 1
	b -= 1
	if check(a,b):
		if diff(a,b) != D:
			print ('table',table)
			print ('weight',diff_weight)
			print('No')
			sys.exit()
	else:
		union(a,b,D)
	print ('table',table)
	print ('weight',diff_weight)
	
	
print ('Yes')
Problem p03579 (python)

Fixed submission:
from collections import defaultdict 
import sys

sys.setrecursionlimit(10**8)


N,M = map(int,input().split())
dict = defaultdict(set)

for i in range(M):
	a,b = list(map(int,input().split()))
	dict[a].add(b)
	dict[b].add(a)


color = [0 for i in range(N+1)]
nibu = True

def dfs(v,c):
	u'''
	v : 現在のグラフの頂点
	c : vのグラフのcolor
	queue : 探索済みのグラフの頂点
	res   : 二部グラフの判定 bool
	'''

	global color
	global nibu 

	for i in list(dict[v]):
		if color[i] == c:#隣の頂点が同じ値を与えられている際Falseを返す
			nibu = False
			break
		elif color[i] == 0:	#探索済みでなければ再帰する
			color[i] = c*-1		#0ならcとは異なる値を格納
			dfs(i,-c)		#引数に-cとすることで,cが1=>-1=>1を繰り返す


color[1] = 1  #始点色分けする

dfs(1,1)

if nibu:
	b = color.count(1)
	w = color.count(-1)
	ans = b * w - M
else:
	ans = N * (N-1)//2 - M
	
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict 

N,M = map(int,input().split())
dict = defaultdict(set)

for i in range(M):
	a,b = list(map(int,input().split()))
	dict[a].add(b)
	dict[b].add(a)


color = [0 for i in range(N+1)]
nibu = True

def dfs(v,c):
	u'''
	v : 現在のグラフの頂点
	c : vのグラフのcolor
	queue : 探索済みのグラフの頂点
	res   : 二部グラフの判定 bool
	'''

	global color
	global nibu 

	for i in list(dict[v]):
		if color[i] == c:#隣の頂点が同じ値を与えられている際Falseを返す
			nibu = False
			break
		elif color[i] == 0:	#探索済みでなければ再帰する
			color[i] = c*-1		#0ならcとは異なる値を格納
			dfs(i,-c)		#引数に-cとすることで,cが1=>-1=>1を繰り返す


color[1] = 1  #始点色分けする

dfs(1,1)

if nibu:
	b = color.count(1)
	w = color.count(-1)
	ans = b * w - M
else:
	ans = N * (N-1)//2 - M
	
print(ans)
Problem p03609 (python)

Fixed submission:
X,t = map(int,input().split())
print(max(X-t,0))

Buggy submission (verdict: Runtime Error):
X,t = map(int,input().split())
print(max(X-t),0)
Problem p03632 (python)

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

a,b,c,d = inpl()
print(max(0,(min(b,d)-max(a,c))))

Buggy submission (verdict: Runtime Error):
a,b,c,d = inpl()
print(max(0,(min(b,d)-max(a,c))))
Problem p03671 (python)

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

a,b,c = inpl_int()
print(a+b+c-max(a,b,c))

Buggy submission (verdict: Runtime Error):
a,b,c = inpl_int()
print(a+b+c-max(a,b,c))
Problem p03674 (python)

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

def Comb(n):
    gyakugen = [1]*(n+1)
    fac = [1]*(n+1)

    for i in range(1,n+1):
        fac[i] = (fac[i-1]*i)%mod

    gyakugen[n] = pow(fac[n],mod-2,mod)

    for i in range(n,0,-1):
        gyakugen[i-1] = (gyakugen[i]*i)%mod

    com = [1]*(n+1)

    for i in range(1,n+1):
        com[i] = (fac[n]*gyakugen[i]*gyakugen[n-i])%mod

    return com

N = int(input())
aa = inpl_int()

i = 1
dd = defaultdict(int)
for i,a in enumerate(aa):
	if dd[a] == 0:
		dd[a] = i+1
	else:
		X1 = dd[a]-1
		X2 = i

L,R = X1,N-X2
ALL = 1

ALL = Comb(N+1)
daburi = Comb(L+R)

for i in range(1,N+2):
	if L+R+1 >= i:
		print((ALL[i]-daburi[i-1])%mod)
	else:
		print(ALL[i]%mod)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

N = int(input())
aa = inpl_int()

i = 1
while True:
	if aa.count(i)==2:
		X1 = aa.index(i)
		aa[X1] = 0
		X2 = aa.index(i)
		break
	i += 1

L,R = X1,N-X2
ALL = 1


def Pascal(N):
	if N == 1:
		return [1]
	else:
		tb1 = [1,1]
		for i in range(2,N+1):
			tb2=[1]
			for j in range(1,i):
				tb2.append((tb1[j-1]+tb1[j])%mod)
			tb2.append(1)
			tb1 = tb2[:]
		return tb1

ALL = Pascal(N+1)
daburi = Pascal(L+R)


for i in range(1,N+2):
	if L+R+1 >= i:
		print(i,ALL[i]-daburi[i-1])
	else:
		print(i,ALL[i])
Problem p03777 (python)

Fixed submission:
a, b = input().split()

if a=='H':
	print(b)
else:
	if b=='H':
		print('D')
	else:
		print('H')

Buggy submission (verdict: Runtime Error):
if a=='H':
	print(b)
else:
	if b=='H':
		print('D')
	else:
		print('H')
Problem p03779 (python)

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7

X = int(input())
N = int(math.sqrt(2*X))-1

while True:
	if N*(N+1)//2 >= X:
		print(N)
		break
	N += 1

Buggy submission (verdict: Runtime Error):
X = int(input())
N = int(math.sqrt(2*X))-1

while True:
	if N*(N+1)//2 >= X:
		print(N)
		break
	N += 1
Problem p03855 (python)

Fixed submission:
import sys
import itertools
from collections import defaultdict

sys.setrecursionlimit(10**8)

def find(x,table):	#xの根を返す	
	if table[x] == x:
		return x
	else:
		table[x] = find(table[x],table)	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,table,rank):	#xとyを繋げる
	x = find(x,table)	
	y = find(y,table)
	
	if x == y:
		return
	
	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y,table):
	if find(x,table) == find(y,table):
		return True
	else:
		return False

N,K,L = map(int,input().split())

table_car = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank_car  = [1 for i in range(N)]	#木の長さ
table_tr  = [i for i in range(N)] 
rank_tr   = [1 for i in range(N)]

for i in range(0,K):
	a,b = map(int, input().split())
	union(a-1,b-1,table_car,rank_car)
	
for i in range(0,L):
	a,b = map(int, input().split())
	union(a-1,b-1,table_tr,rank_tr)
	
ar = [(find(i,table_car),find(i,table_tr)) for i in range(N)]
dd = defaultdict(int)
for s in ar:
    dd[s] += 1
	
ans =[]
for i in range(N):
    ans.append(dd[ar[i]])
	
print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**8)

def find(x,table):	#xの根を返す	
	if table[x] == x:
		return x
	else:
		table[x] = find(table[x],table)	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,table,rank):	#xとyを繋げる
	x = find(x,table)	
	y = find(y,table)
	
	if x == y:
		return
	
	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y,table):
	if find(x,table) == find(y,table):
		return True
	else:
		return False

N,M = map(int,input().split())
P_li = list(map(int,input().split()))

table = [i for i in range(N+1)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N+1)]	#木の長さ

for i in range(0,M):
	a,b = map(int, input().split())
	union(a,b,table,rank)
	
ans = 0

for i in range(1,N+1):
	if check(i,P_li[i-1],table):
		ans += 1

print (ans)
Problem p03971 (python)

Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,A,B = inpl()
S = input()
tmp = 1
tmpf = 1

for s in S:
	if s == 'a':
		if tmp <= A+B:
			print('Yes')
			tmp += 1
		else:
			print('No')
	elif s == 'b':
		if tmp <= A+B and tmpf <= B:
			print('Yes')
			tmpf += 1
			tmp += 1
		else:
			print('No')
	else:
		print('No')

Buggy submission (verdict: Runtime Error):
N,A,B = map(int,list(input()))
S = input()
tmp = 0
tmpf = 0
for i in range(1,N+1):
  s = S[i]
  if s == "a":
    if tmp <= A+B:
      print("Yes")
      tmp +=1
    else:
      print("No")
  elif s == "b":
    if tmp <= A+B and tmpf <=B:
      print("Yes")
      tmp +=1
      tmpf += 1
    else:
      print("No")
  else:
    print("No")
Problem p04015 (python)

Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,A = inpl()
aa = inpl()

dp = [[[0]*(50*N+5) for j in range(N+1)] for i in range(N)]
# dp[i][j][k] : i 枚目まで見て，j枚選んで，合計がk の通り

for i in range(N):
    dp[i][0][0] = 1


for i in range(N):
    a = aa[i]
    for j in range(1,i+2):
        for k in range(50*j+5):
            dp[i][j][k] = dp[i-1][j][k]
            if k >= a:
                dp[i][j][k] += dp[i-1][j-1][k-a]

ans = 0
for j in range(N+1):
    ans += dp[-1][j][j*A]

print(ans-1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
xx = inpl()
L = int(input())

K = N.bit_length()
db_r = [[0]*K for i in range(N)]
for i,x in enumerate(xx):
    ind = bisect.bisect_right(xx,x+L)
    db_r[i][0] = ind-1

for k in range(1,K):
    for i in range(N):
        db_r[i][k] = db_r[db_r[i][k-1]][k-1]

def check(a,b,d):
    L = d.bit_length()
    for k in range(L):
        if d & (1<<k):
            a = db_r[a][k]
    return a >= b

Q = int(input())
for i in range(Q):
    a,b = inpl()
    a -= 1
    b -= 1
    a,b = min(a,b),max(a,b)
    OK = N
    NG = 0
    while OK-NG>1:
        mid = (OK+NG)//2
        if check(a,b,mid): OK = mid
        else: NG = mid
    print(OK)
Problem p03006 (python)

Fixed submission:
n = int(input())
xys = {}
xy = []
for _ in range(n):
  x, y = map(int, input().split())
  xys[(x,y)] = True
  xy.append((x,y))

scores = []

if n == 1:
  print(1)
  exit(0)
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    xi, yi = xy[i]
    xj, yj = xy[j]
    p = xj-xi
    q = yj-yi
    score = n
    for k in range(n):
      xk, yk = xy[k]
      if (xk+p, yk+q) in xys:
        score -= 1
    scores.append(score)

print(min(scores))

Buggy submission (verdict: Runtime Error):
n = int(input())
xys = {}
xy = []
for _ in range(n):
  x, y = map(int, input().split())
  xys[(x,y)] = True
  xy.append((x,y))

scores = []

for i in range(n):
  for j in range(n):
    if i == j:
      continue
    xi, yi = xy[i]
    xj, yj = xy[j]
    p = xj-xi
    q = yj-yi
    score = n
    for k in range(n):
      xk, yk = xy[k]
      if (xk+p, yk+q) in xys:
        score -= 1
    scores.append(score)

print(min(scores))
Problem p03032 (python)

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

values = []

if k > 1:
  for num_enqueue in range(k // 2):
    for num_dequeue in range(k-num_enqueue+1):
      for num_dequeue_left in range(num_dequeue+1):
        num_dequeue_right = num_dequeue - num_dequeue_left
        if num_dequeue >= n:
          dequeued = vs[:]
        else:
          dequeued = vs[:num_dequeue_left] + ([] if num_dequeue_right == 0 else vs[-num_dequeue_right:])
        dequeued_pos = [v for v in dequeued if v >= 0]
        dequeued_neg = sorted([v for v in dequeued if v < 0], reverse=True)

        for _ in range(num_enqueue):
          if dequeued_neg:
            dequeued_neg.pop()
        value = sum(dequeued_pos) + sum(dequeued_neg)
        #print(f'value={value}, enq={num_enqueue}, left={num_dequeue_left}, right={num_dequeue_right}, dequeued={dequeued}')
        values.append(value)
  print(max(values))
else:
  print(max(vs[0], vs[-1], 0))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
vs = list(map(int, input().split()))

values = []

for num_enqueue in range(k // 2):
  for num_dequeue in range(k-num_enqueue+1):
    for num_dequeue_left in range(num_dequeue+1):
      num_dequeue_right = num_dequeue - num_dequeue_left
      if num_dequeue >= n:
        dequeued = vs[:]
      else:
        dequeued = vs[:num_dequeue_left] + ([] if num_dequeue_right == 0 else vs[-num_dequeue_right:])
      dequeued_pos = [v for v in dequeued if v >= 0]
      dequeued_neg = sorted([v for v in dequeued if v < 0], reverse=True)

      for _ in range(num_enqueue):
        if dequeued_neg:
          dequeued_neg.pop()
      value = sum(dequeued_pos) + sum(dequeued_neg)
      #print(f'value={value}, enq={num_enqueue}, left={num_dequeue_left}, right={num_dequeue_right}, dequeued={dequeued}')
      values.append(value)

#print(values)
print(max(values))
Problem p03090 (python)

Fixed submission:
import itertools
n = int(input())
ns = list(range(1,n+1))
cs = list(itertools.combinations(ns, 2))
top = n if n % 2 == 0 else n-1

for nn in range(n):
  tpl = (nn+1, top-nn)
  if tpl[0] >= tpl[1]:
    break
  #print(f'removing {tpl}')
  cs.remove(tpl)

print(len(cs))
for a, b in cs:
  print('{0} {1}'.format(a, b))

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
ns = list(range(1,n+1))
cs = list(itertools.combinations(ns, 2))
top = n if n % 2 == 0 else n-1

for nn in range(n):
  tpl = (nn+1, top-nn)
  if tpl[0] >= tpl[1]:
    break
  #print(f'removing {tpl}')
  cs.remove(tpl)

print(len(cs))
for a, b in cs:
  print(f'{a} {b}')
Problem p03608 (python)

Fixed submission:
#import time
#t = time.time()
inf = float('inf')

n, m, r = map(int, input().split())
rs = [r-1 for r in list(map(int, input().split()))]


ds = [[inf] * n for _ in range(n)]
for i in range(n):
  ds[i][i] = 0

for mm in range(m):
  a, b, c = map(int, input().split())
  a, b = a-1, b-1
  ds[a][b] = c
  ds[b][a] = c

## warshall floyd
for k in range(n):
  for i in range(n):
    for j in range(n):
      ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])

#print(f'wf finished {time.time() - t}')
#t = time.time()

#def dfs(dist, before, remain, ds):
#  print(f'dfs({dist}, {before}, {remain})')
#  if remain == []:
#    return dist
#  dd = []
#  for r in remain:
#    if before is not None:
#      dist += ds[before][r]
#    dd.append(dfs(dist, r, list(set(remain) - set([r])), ds))
#  return min(dd)    
#
#print(dfs(0, None, rs, ds))


import itertools
dds = []
for i in itertools.permutations(rs, len(rs)):
  d = 0
  for j in range(len(rs)-1):
    dd = ds[i[j]][i[j+1]]
    d += dd
    #print(f'added {dd}')
  dds.append(d)
print(min(dds))

#print(f'search finished {time.time() - t}')
#t = time.time()

Buggy submission (verdict: Runtime Error):
inf = float('inf')
 
n, m, r = map(int, input().split())
rs = [r-1 for r in list(map(int, input().split()))]
 
 
ds = [[inf] * n for _ in range(n)]
for i in range(n):
  ds[i][i] = 0
 
for mm in range(m):
  a, b, c = map(int, input().split())
  a, b = a-1, b-1
  ds[a][b] = c
  ds[b][a] = c
 
## warshall floyd
for k in range(n):
  for i in range(n):
    for j in range(n):
      ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])
 
 
#def dfs(dist, before, remain, ds):
#  print(f'dfs({dist}, {before}, {remain})')
#  if remain == []:
#    return dist
#  dd = []
#  for r in remain:
#    if before is not None:
#      dist += ds[before][r]
#    dd.append(dfs(dist, r, list(set(remain) - set([r])), ds))
#  return min(dd)    
#
#print(dfs(0, None, rs, ds))
 
 
import itertools
dds = []
for i in itertools.permutations(rs, len(rs)):
  d = 0
  for j in range(len(rs)-1):
    dd = ds[i[j]][i[j+1]]
    d += dd
    #print(f'added {dd}')
  dds.append(d)
print(min(dds))
inf = float('inf')

n, m, r = map(int, input().split())
rs = [r-1 for r in list(map(int, input().split()))]


ds = [[inf] * n for _ in range(n)]
for i in range(n):
  ds[i][i] = 0

for mm in range(m):
  a, b, c = map(int, input().split())
  a, b = a-1, b-1
  ds[a][b] = c
  ds[b][a] = c

## warshall floyd
for k in range(n):
  for i in range(n):
    for j in range(n):
      ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])


#def dfs(dist, before, remain, ds):
#  print(f'dfs({dist}, {before}, {remain})')
#  if remain == []:
#    return dist
#  dd = []
#  for r in remain:
#    if before is not None:
#      dist += ds[before][r]
#    dd.append(dfs(dist, r, list(set(remain) - set([r])), ds))
#  return min(dd)    
#
#print(dfs(0, None, rs, ds))


import itertools
dds = []
for i in itertools.permutations(rs, len(rs)):
  d = 0
  for j in range(len(rs)-1):
    dd = ds[i[j]][i[j+1]]
    d += dd
    #print(f'added {dd}')
  dds.append(d)
print(min(dds))
Problem p03478 (python)

Fixed submission:
n,a,b = map(int,input().split())
ans = 0

def k(N):
    sum = 0
    while N>0:
        sum += N%10
        N = N//10
    return sum

for i in range(1,n+1):
    if a<=k(i)<=b:
        ans +=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b = (int(x) for x input().split())
ans = 0

def k(N):
    sum = 0
    while N>0:
        sum += N%10
        N = N//10
    return sum

for i in range(1,n+1):
    if a<=k(i)<=b:
        ans +=i
print(ans)
Problem p02778 (python)

Fixed submission:
s = input()
 
print('x' * len(s))

Buggy submission (verdict: Runtime Error):
s = input()

print(x * len(s))
Problem p02958 (python)

Fixed submission:
n = int(input())
p = [int(x) for x in input().split()]
 
count = 0
index = []
 
for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count != 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [int(x) for x in input().split()]

count = 0
index = []

for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count == 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')
Problem p02971 (python)

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

n = int(input())
a = [int(input()) for x in range(n)]

# a をソートして、一番大きい要素を取り出す
temp_list = sorted(a)
m = temp_list[::-1][0]


# 最も大きな数が複数あった場合
if temp_list[::-1][1] == m:
    m_dash = m
else:
    m_dash =temp_list[::-1][1]

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)

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

n = int(input())
a = [int(input()) for x in range(n)]

temp_list = sorted(a)
m = temp_list[n-1]


for x in temp_list[::-1]:
  if x == m:
    continue
  else:
    m_dash = x
    break

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)
Problem p03068 (python)

Fixed submission:
n = int(input())
s = input()
k = int(input())

x = s[k-1]
temp_list = []

for c in s:
  if c is not x:
    temp_list.append('*')
  else:
    temp_list.append(c)

print(''.join(temp_list))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())

x = s[k]
temp_list = []

for c in s:
  if c is not x:
    temp_list.append('*')
  else:
    temp_list.append(c)

print(''.join(temp_list))
Problem p03086 (python)

Fixed submission:
s = input()
acgt = {'A', 'C', 'G', 'T'}
count = 0
temp_list= []

for c in s:
  if c in acgt:
    count += 1
  else:
    count = 0
  
  temp_list.append(count)
  
print(max(temp_list))

Buggy submission (verdict: Runtime Error):
s = input()
acgt = {'A', 'C', 'G', 'T'}
count = 0
temp_list= []

for c in s:
  if c in acgt:
    count += 1
  else:
    temp_list.append(count)
    count = 0

print(max(temp_list))
Problem p03103 (python)

Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

ab.sort(key=lambda x: x[0])

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for bottle in b:
  index += 1
  if count + bottle < m:  
    count += bottle
  else:
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)
Problem p03909 (python)

Fixed submission:
import sys
input = sys.stdin.readline
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = 'snake'
h, w = map(int, input().split())

for i in range(h):
  i += 1
  s = [x for x in input().split()]
  if 'snuke' in s:
    ans = alphabet[s.index('snuke')] + str(i)
    break

print(ans)

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

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

h, w = map(int, input().split())

for i in range(h):
  col = my_index(input().split(), 'snuke')
  if col == False:
    row = i + 1
    break

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(alphabet[col] + str(row))