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

Fixed submission:
import sys
input = sys.stdin.readline
h, w, d = map(int, input().split())
a = {}
l = list(range(1, h * w + 1))
for i in range(h):
  for j, x in enumerate(input().split()):
    a[int(x)] = (i, j)
memo = {}
def calc(s):
  tmp = 0
  memo[a[s+1]] = 0
  for Xc, Xn in zip(l[s::d], l[s+d::d]):
    xc, yc = a[Xc]
    xn, yn = a[Xn]
    tmp += abs(xc - xn) + abs(yc - yn)
    memo[a[Xn]] = tmp
for i in range(d):
  calc(i)
for _ in range(int(input())):
  l, r = map(int, input().split())
  print(memo[a[r]] - memo[a[l]])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h, w, d = map(int, input().split())
a = {}
l = list(range(1, h * w + 1))
for i in range(h):
  for j, x in enumerate(input().split()):
    a[int(x)] = (i, j)
memo = {}
def calc(s):
  tmp = 0
  memo[a[s]] = 0
  for Xc, Xn in zip(l[s::d], l[s+d::d]):
    xc, yc = a[Xc]
    xn, yn = a[Xn]
    tmp += abs(xc - xn) + abs(yc - yn)
    memo[a[Xn]] = tmp
for i in range(d):
  calc(i+1)
for _ in range(int(input())):
  l, r = map(int, input().split())
  print(memo[a[r]] - memo[a[l]])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h, w, d = map(int, input().split())
a = {}
l = list(range(h * w))
for i in range(h):
  for j, x in enumerate(input().split()):
    a[int(x)] = (i, j)
memo = {}
def calc(s):
  tmp = 0
  memo(a[s]) = 0
  for xc, xn in zip(l[s::d], l[s+d::d]):
    xc, yc = a[xc]
    xn, yn = a[xn]
    tmp += abs(xc - xn) + abs(yc - yn)
    memo(a[xn]) = tmp
for i in range(d):
  calc(i)
for _ in range(int(input())):
  l, r = map(int, input().split())
  print(memo[a[r]] - memo[a[l]])
Problem p03634 (python)

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

INF = 10 ** 18

class Edge():
    def __init__(self, start, end, cost):
        self.start = start
        self.end = end
        self.cost = cost
    def __str__(self):
        return 'Edge: {} -> {}, cost {}'.format(self.start, self.end, self.cost)

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for e in G[v]:
            if dist[e.end] > dist[v] + e.cost:
                dist[e.end] = dist[v] + e.cost
                heapq.heappush(h, (dist[e.end], e.end))
    return dist


n = int(input())
es = [[] for i in range(n)]

for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    es[a-1].append(Edge(a-1, b-1, c))
    es[b-1].append(Edge(b-1, a-1, c))

q, k = map(int, input().split())
k -= 1

d = dijkstra(n, es, k)

for j in range(q):
    x, y = map(int, input().split())
    print(d[x-1] + d[y-1])

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import sys
input = sys.stdin.readline

import heapq

INF = 10 ** 18

class Edge():
    def __init__(self, start, end, cost):
        self.start = start
        self.end = end
        self.cost = cost
    def __str__(self):
        return 'Edge: {} -> {}, cost {}'.format(self.start, self.end, self.cost)

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for e in G[v]:
            if dist[e.end] > dist[v] + e.cost:
                dist[e.end] = dist[v] + e.cost
                heapq.heappush(h, (dist[e.end], e.end))
    return dist


n = int(input())
es = [[] for i in range(n)]

for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    es[a-1].append(Edge(a-1, b-1, c))
    es[b-1].append(Edge(b-1, a-1, c))

q, k = map(int, input().split())
k -= 1

d = dijkstra(n, es, k)

for j in range(q):
    x, y = map(int, input().split())
    print(d[x-1] + d[y-1])
Problem p03805 (python)

Fixed submission:
n, m = map(int, input().split())
d = {i+1 : [] for i in range(n)}
for _ in range(m):
  a, b = map(int, input().split())
  d[a].append(b)
  d[b].append(a)
ans = 0
def go(c, rem):
  global ans
  if not len(rem):
    ans += 1
    return
  for cand in d[c]:
    if cand in rem:
      i = rem.index(cand)
      go(cand, rem[:i] + rem[i+1:])
go(1, list(range(2, n+1)))
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
d = {i+1 : [] for i in range(n)}
for _ in range(n):
  a, b = map(int, input().split())
  d[a].append(b)
  d[b].append(a)
ans = 0
def go(c, rem):
  global ans
  if not len(rem):
    ans += 1
    return
  for cand in d[c]:
    if cand in rem:
      i = rem.index(cand)
      go(cand, rem[:i] + rem[i+1:])
go(1, list(range(2, n+1)))
print(ans)
Problem p02598 (python)

Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        #print(l, r)
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:# sum == K
            r = test
        if int(r) == r and r-l < 1:
            print(int(r))
            return

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    eps = 1e-8
    while int(l) != int(r):
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += (a-eps) // test
        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test

    if int(l) == l:
        sum = 0
        for a in A:
            sum += (a - eps) // int(l)
        if sum == K:
            print(int(l))

    print(int(l)+1)





if __name__ == "__main__":
    run()
Problem p02729 (python)

Fixed submission:
N, M = input().split()
N, M = int(N), int(M)
if N < 2:
  print(int(M*(M-1)/2))
elif M < 2:
  print(int(N*(N-1)/2))
else:
  print(int(N*(N-1)/2 + M*(M-1)/2))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import itertools
A = [0]
N, S = list(map(int, input().split()))
A = A + list(map(int, input().split()))   
val = 0
for L in range(1, N+1):
  for R in range(L, N+1):
    A_ = A[L:R+1]
    lists = []
    for n in range(len(A_)):
      for comb in itertools.combinations(A_, n+1):
        lists.append(list(comb))
    for lis in lists:
      _sum = sum(lis)
      if _sum == S:
        val += 1
      if val == 998244353:
        val = 0
print(val)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
A = input().split()
for k in range(N):
  A_ = A.copy()
  del A_[k]
  ans = 0
  while len(A_) > 0:
    val = A_[0]
    counts = A_.count(val)
    ans += int(counts * (counts - 1) / 2)
    while True:
      try:
        A_.remove(val)
      except:
        break

  print('{}'.format(ans))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
A = input().split()
for k in range(N):
  A_ = A.copy()
  del A_[k]
  ans = 0
  while len(A_) > 0:
    val = A_[0]
    counts = A_.count(val)
    ans += int(counts * (counts - 1) / 2)
    while True:
      try:
        A_.remove(val)
      except:
        break

  print('{}'.format(ans))

Buggy submission (verdict: Runtime Error):
L = int(input())
print((L/3)**3)
Problem p02753 (python)

Fixed submission:
S = list(input())
if (S[0] == S[1]) & (S[1] == S[2]):
  print('No')
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
S = list(input())
if S[0] == S[1] & S[1] == S[2]:
  print('No')
else:
  print("Yes")
Problem p02577 (python)

Fixed submission:
N = int(input()) 
if N%9==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

char S[20010];
int main() {
  cin >> S;
  int len = strlen(S);
  int sum=0;
  for(int i=0; i<len; i++) {
    sum += S[i]-'0';
  }
  if(sum%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}
Problem p02572 (python)

Fixed submission:
mod = 10**9 + 7
n = int(input())
A = list(map(int,input().split()))
S = sum(A)%mod
ans = 0
for a in A:
    ans += a * (S - a)
print(ans*pow(2,-1,mod)%mod)

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
n = int(input())
A = list(map(int,input().split()))
S = sum(A)%mod
ans = 0
for a in A:
    ans += a * (S - a)
print(ans*pow(2,-1,mod)%mod)
Problem p02629 (python)

Fixed submission:
n = int(input())
i = 1
while pow(26,i) < n:
    n -= pow(26,i)
    i += 1
ans = ''
n -= 1
for _ in range(i):
    ans += chr(ord('a') + n%26)
    n //= 26
print(ans[::-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()

def f(k):
    return chr(97+k)

c = 0
i = 1
while True:
    d = c+pow(26,i)
    if c < n <= d:
        break
    c = d
    i+=1

m = n-c-1
ans = ''
for _ in range(i)
    ans = f(m%26) + ans
    m = m//26
ans = f(m%26) + ans

# ans = 'a'*(i-len(ans)) + ans

print(ans)
Problem p02634 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
mod = 998244353
dp = [[0]*(d-b+1) for i in range(c-a+1)]
if a == c and b == d:
    print(1)
elif a == c:
    print(pow(a,d-b,mod))
elif b == d:
    print(pow(b,c-a,mod))
else:
    for i in range(c-a):
        p = 0
        for j in range(d-b+1):
            if i == j == 0:
                dp[i][j] = 1
            dp[i+1][j] = (p + dp[i][j]*(b+j))%mod

            p += dp[i][j]
            p %= mod
            p *= a+i
            p %= mod

    ans = 0
    for d in dp[-1]:
        ans *= c
        ans %= mod
        ans += d
        ans %= mod
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
mod = 998244353
dp = [[0]*(d-b+1) for i in range(c-a+1)]
if a == c and b == d:
    print(1)
elif a == c:
    print(a)
elif b == d:
    print(b):
else:
    for i in range(c-a):
        p = 0
        for j in range(d-b+1):
            if i == j == 0:
                dp[i][j] = 1
            dp[i+1][j] = (p + dp[i][j]*(b+j))%mod

            p += dp[i][j]
            p %= mod
            p *= a+i
            p %= mod

    ans = 0
    for d in dp[-1]:
        ans *= c
        ans %= mod
        ans += d
        ans %= mod
    print(ans)
Problem p02695 (python)

Fixed submission:
import itertools
n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    tmp = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    cnt = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            cnt += d[i]
    ans = max(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(n):
    a[i],b[i],c[i],d[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
A = [0]*n
ans = 0
def dfs(h):
    global ans
    if h == n-1:
        cnt = 0
        for i in range(q):
            if A[b[i]] - A[a[i]] == c[i]:
                cnt += d[i]
        ans = max(ans,cnt)
    else:
        for i in range(A[h],m+1):
            A[h+1] = i
            dfs(h+1)
    return

for i in range(1,m+1):
    A[0] = i
    dfs(0)
print(ans)
Problem p02723 (python)

Fixed submission:
s = input()
if s[2] == s[3] and s[5] == s[4]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n = int(readline())

mod = 10**9 + 7

def expo(x,n):
    var = 1
    while n>0:
        if n%2 == 1:
            var = (var*x) % mod
        x = (x*x)%mod
        n = n>>1
    return var

def conbi(*x):
    num = 1
    den = 1
    for i in range(1,sum(x)+1):
        num = (num*i)%mod
    for i in x:
        for j in range(1,i+1):
            den = (den * j)%mod
    return (num*expo(den,mod-2))%mod

path = [set() for _ in range(n)]
pathq= [0]*n

for _ in range(n-1):
    a,b = map(int,read().split())
    a -= 1
    b -= 1
    path[a].add(b)
    pathq[a] += 1
    path[b].add(a)
    pathq[b] += 1

memo = {}
def go(i,j):
    if (i,j) in memo.keys():
        return memo[(i,j)]
    else:
        memo[(i,j)] = [1,1]
        cnt = []
        meth = 1
        for k in path[j]:
            if i != k:
                [x,y] = go(j,k)
                meth *= y
                meth %= mod
                cnt.append(x)
        memo[(i,j)] = [sum(cnt)%mod + 1, meth*conbi(*cnt)%mod]
        return memo[(i,j)]

for i in range(n):
    ans = 1
    cnt = []
    meth = 1
    for j in path[i]:
        [x,y] = go(i,j)
        meth *= y
        meth %= mod
        cnt.append(x)
    print(meth*conbi(*cnt)%mod)
Problem p02753 (python)

Fixed submission:
s = input()
if s == 'AAA' or s == 'BBB':
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()
if s == 'AAA' or s == 'BBB':
  print(No)
else:
  print(Yes)
Problem p02769 (python)

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

mod = 10**9 + 7
l = 10**7
fac = [1]*l
facr = [1]*l

for i in range(l-1):
    fac[i+1] = fac[i]*(i+1)%mod
facr[l-1] = pow(fac[l-1],mod - 2,mod)
for i in range(1,l)[::-1]:
    facr[i-1] = facr[i]*i%mod

def combi(N,K):
    return fac[N]*facr[N-K]%mod*facr[K]%mod

ans = 1
for i in range(1,min(n,k+1)):
    ans += combi(n,i)*combi(n-1,i)%mod
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 7+10**9

def expo(x):
  ans = 1
  n = mod-2
  if memo_e[x]:
    return memo_e[x]
  while n>0:
    if n%2 == 1:
      ans = ans*x%mod
    x = x*x%mod
    n = n >> 1
  memo_e[x] = ans
  return ans

def combi(n,k):
  return (fac[n]*(expo(fac[k]))%mod)*expo(fac[n-k])%mod

n,k = map(int,input().split())
fac = [1]+[0]*n
for i in range(1,n+1):
  fac[i] = fac[i-1]%mod

memo_e = [0]*(n**n+1)
ans = 0
for i in range(min(n,k+1)):
  ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

mod = 7+10**9

def expo(x,n):
  ans = 1
  while n>0:
    if n%2 == 1:
      ans = ans*x%mod
    x = x*x%mod
    n = n >> 1
  return ans

def fac(n):
  if not memo_f[n]:
    memo_f[n] = (n*fac(n-1))%mod
  return memo_f[n]

def combi(n,k):
  return (((fac(n)*(expo(fac(k),mod-2)))%mod)*expo(fac(n-k),mod-2))%mod


n,k = map(int,input().split())
memo_f = [1]+[0]*n

if k == 1:
  ans = combi(n-1,k)*combi(n,k)%mod
elif k >= n:
  ans = 0
  for i in range(n):
    ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
else:
  ans = 0
  for i in range(k+1):
    ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 7+10**9

def expo(x,n):
  ans = 1
  while n>0:
    if n%2 == 1:
      ans = ans*x%mod
    x = x*x%mod
    n = n >> 1
  return ans

def fac(n):
  if not memo_f[n]:
    memo_f[n] = (n*fac(n-1))%mod
  return memo_f[n]

def combi(n,k):
  return (((fac(n)*(expo(fac(k),mod-2)))%mod)*expo(fac(n-k),mod-2))%mod


n,k = map(int,input().split())
memo_f = [1]+[0]*n

if k == 1:
  ans = combi(n-1,k)*combi(n,k)%mod
elif k >= n:
  ans = 0
  for i in range(n):
    ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
else:
  ans = 0
  for i in range(k+1):
    ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 7+10**9

def expo(x,n):
  ans = 1
  if x%2 == 1:
    ans = ans*x
  x = x*x
  n = n >> 1
  return ans

def fac(n):
  if not memo_f[n]:
    return (n*fac(n-1))%mod
  else:
    return memo_f[n]

def combi(n,k):
  return (((fac(n)*(expo(fac(k),mod-2)))%mod)*expo(fac(n-k)))%mod


n,k = map(int,input().split())
memo_f = [1]+[0]*n

if k == 1:
  ans = combi(n-1,k)*combi(n,k)%mod
elif k >= n:
  ans = 0
  for i in range(n):
    ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
else:
  ans = 0
  for i in range(k+1):
    ans = (ans + combi(n,i)*combi(n-1,i)%mod)%mod
print(ans)
Problem p02790 (python)

Fixed submission:
a,b = map(int,input().split())
print(str(min(a,b))*max(a,b))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print(str(min(a,b)*max(a,b))
Problem p02836 (python)

Fixed submission:
s = input()
n = len(s)
ans = 0
for i in range(n//2):
  if s[i] != s[n-i-1]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = int(input())
n = len(s)
ans = 0
for i in range(n//2):
  if s[i] != s[n-i-1]:
    ans += 1
print(ans)
Problem p02863 (python)

Fixed submission:
n,t = map(int,input().split())
ab = [[0,0] for _ in range(n)]
for i in range(n):
    ab[i] = list(map(int,input().split()))
dp = [[0]*t for i in range(n+1)]
ab.sort()
ans = 0
for i in range(n):
    a,b = ab[i]
    for j in range(t)[::-1]:
        v = dp[i][j]
        ans = max(ans,v+b)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j + a >= t:continue
        dp[i+1][j+a] = max(dp[i][j+a], v+b)
print(ans)

Buggy submission (verdict: Runtime Error):
n,t = map(int,input().split())
ab = [[0,0] for _ in range(n)]
for i in range(n):
    ab[i] = list(map(int,input().split()))
dp = [[0]*t for i in range(n+1)]
ab.sort()
ans = 0
for i in range(n):
    a,b = ab[i]
    for j in range(t)[::-1]:
        v = dp[i][j]
        ans = max(ans,v+b)
        dp[i+1][j] = max(dp[i+1][j], dp[j][i])
        if j + a >= t:continue
        dp[i+1][j+a] = max(dp[i][j+a], v+b)
print(ans)
Problem p03012 (python)

Fixed submission:
n = int(input())
w = list(map(int,input().split()))
ans = sum(w)
for i in range(1,n):
  ans = min(ans, abs(sum(w[:i])-sum(w[i:])))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = list(map(int,input().split()))
ans = 1e100
for i in range(1,n):
  ans = min(ans, abs(sum[:i]-sum[i:]))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = list(map(int,input().split()))
ans = 1e100
for t in w:
  over = 0
  under= 0
  for i in w:
    if i > w:
      over += i
    else:
      under+= i
  ans = min(ans,abs(over - under))
print(ans)
Problem p03075 (python)

Fixed submission:
ae = [int(input()) for _ in range(5)]
ae.sort()
if ae[-1] - ae[0] <= int(input()):
  print('Yay!')
else:
  print(':(')

Buggy submission (verdict: Runtime Error):
ae = [int(input()) for _ in range(5)]
ae.sort()
if ae[-1] - ae[0] <= int(Input()):
  print('Yay!')
else:
  print(':(')
Problem p03208 (python)

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

h = [0]*n

for i in range(n):

    h[i] = int(input())

h.sort()

ans = float('inf')

for i in range(n-k+1):

    ans = min(ans,abs(h[i+k-1]-h[i]))

print(ans)

Buggy submission (verdict: Runtime Error):
h,n = map(int,input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
h.sort()
ans = float('inf')
for i in range(n-k):
    ans = min(ans,abs(h[i+k-1]-h[i])
print(ans)
Problem p03250 (python)

Fixed submission:
abc = list(map(int,input().split()))
abc.sort()
abc[2] *= 10
print(sum(abc))

Buggy submission (verdict: Runtime Error):
abc = list(map(int,input()))
abc.sort()
abc[2] *= 10
print(sum(abc))
Problem p03291 (python)

Fixed submission:
from bisect import *
S = input()
mod = 10**9 + 7
A = []
B = []
C = []
X = []
q = 0
for i,s in enumerate(S):
    if s == 'A':
        A.append(i)
    elif s == 'B':
        B.append((i,0))
    elif s == 'C':
        C.append(i)
    else:
        X.append(i)
        B.append((i,1))
        q += 1

pow3 = [pow(3,q,mod),pow(3,max(0,q-1),mod),pow(3,max(0,q-2),mod),pow(3,max(0,q-3),mod)]
ans = 0
for b,flag in B:
    Al = bisect_left(A,b)
    Cr = (len(C) - bisect_right(C,b))
    Xl = bisect_left(X,b)
    Xr = (len(X) - bisect_right(X,b))
    ans += (Al*Cr%mod)*pow3[flag]%mod
    ans %= mod
    ans += (Al*Xr%mod + Xl*Cr%mod)*pow3[flag+1]%mod
    ans %= mod
    ans += (Xl*Xr%mod)*pow3[flag+2]%mod
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import *
S = input()
mod = 10**9 + 7
A = []
B = []
C = []
X = []
q = 0
for i,s in enumerate(S):
    if s == 'A':
        A.append(i)
    elif s == 'B':
        B.append((i,0))
    elif s == 'C':
        C.append(i)
    else:
        X.append(i)
        B.append((i,1))
        q += 1

pow3 = [pow(3,q,mod),pow(3,q-1,mod),pow(3,q-2,mod),pow(3,q-3,mod)]
ans = 0
for b,flag in B:
    Al = bisect_left(A,b)
    Cr = (len(C) - bisect_right(C,b))
    Xl = bisect_left(X,b)
    Xr = (len(X) - bisect_right(X,b))
    ans += (Al*Cr%mod)*pow3[flag]%mod
    ans %= mod
    ans += (Al*Xr%mod + Xl*Cr%mod)*pow3[flag+1]%mod
    ans %= mod
    ans += (Xl*Xr%mod)*pow3[flag+2]%mod
print(ans)
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
win = {}
# key:勝者 value:keyに負けた人(set)
for i in range(n - 1):
    a = int(input())
    a -= 1
    if a not in win.keys():win[a] = set()
    win[a].add(i+1)

def dfs(winner):
    if winner not in win.keys():return 0
    losers = win[winner]
    storong = len(losers)
    deeps = []
    for loser in losers:
        deeps.append(dfs(loser))
    deeps.sort(reverse = True)
    deep = 1
    for i,d in enumerate(deeps):
        deep = max(deep, i+1 + d)
    return deep

print(dfs(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
win = {}
# key:勝者 value:keyに負けた人(set)
for i in range(n - 1):
    a = int(input())
    a -= 1
    if a not in win.keys():win[a] = set()
    win[a].add(i+1)

def dfs(winner):
    if winner not in win.keys():return 0
    losers = win[winner]
    storong = len(losers)
    deeps = []
    for loser in losers:
        deeps.append(dfs(loser))
    deeps.sort(reverse = True)
    deep = 1
    for i,d in enumerate(deeps):
        deep = max(deep, i+1 + d)
    return deep

print(dfs(0))