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

Fixed submission:
from collections import defaultdict, deque
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M, P = map(int, input().split())
d = defaultdict(list)
e = defaultdict(list)
cd = defaultdict(list)
l = []

for _ in range(M):
    a, b, c = map(int, input().split())
    cd[a].append((b, P-c))
    d[a].append(b)
    e[b].append(a)

def check_visited(d, start):
    visited = [False]*(N+1)
    visited[start] = True
    q = deque([start])
    while q:
        s = q.popleft()
        for t in d[s]:
            if visited[t]:continue
            visited[t] = True
            q.append(t)
    
    s = set()
    for i in range(1, N+1):
        if visited[i]:
            s.add(i)
    return s

def shortest_path(s):
    INF = 10**18
    dist = [float("inf")]*(N+1)
    dist[s] = 0

    for i in range(N):
        for a, b, c in l:
            if dist[b]>dist[a]+c:
                dist[b] = dist[a]+c
                if i==N-1:
                    return dist, True
    return dist, False

add_l = check_visited(d, 1)&check_visited(e, N)
for a in add_l:
    for b, c in cd[a]:
        l.append((a, b, c))
d1, neg = shortest_path(1)
if neg:
    print(-1)
elif d1[N]<0:
    print(-d1[N])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M, P = map(int, input().split())
d = defaultdict(list)
candidate = []
l = []

for _ in range(M):
    a, b, c = map(int, input().split())
    
    if a==b:
        if P-c<0:
            candidate.append(a)
    else:
        l.append((a, b, P-c))
        d[a].append((P-c, b))

def check():
    if candidate:
        visited = [False]*(N+1)
        visited[1] = True
        q = deque([1])
        while q:
            s = q.popleft()
            for _, t in d[s]:
                if visited[t]:continue
                visited[t] = True
                q.append(t)
        
        candidate2 = [i for i in candidate if visited[i]]
        for i in candidate2:
            visited = [False]*(N+1)
            visited[i] = True
            q = deque([i])
            while q:
                s = q.popleft()
                for _, t in d[s]:
                    if visited[t]:continue
                    visited[t] = True
                    q.append(t)
            if visited[N]:
                return False
    return True

def shortest_path(s):
    INF = 10**18
    dist = [INF]*(N+1)
    dist[s] = 0

    while 1:
        update = False

        for a, b, c in l:
            if dist[a]!=INF and dist[b]>dist[a]+c:
                dist[b] = dist[a]+c
        if not update:
            break
    return dist

if check():
    d1 = shortest_path(1)
    dN = shortest_path(N)
    if dN[1]!=INF and d1[N]+dN[1]<0:
        print(-1)
    elif d1[N]<0:
        print(-d1[N])
    else:
        print(0)
else:
    print(-1)
Problem p02973 (python)

Fixed submission:
from collections import deque
from bisect import bisect_left

N = int(input())
d = deque([])
l = [int(input()) for _ in range(N)]

d.append(l[0])

for i in l[1:]:
    v = bisect_left(d, i)
    if v == 0:
        d.appendleft(i)
    else:
        d[v-1] = i

print(len(d))

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

N = int(input())
d = defaultdict(list)

for i in range(N):
    v = int(input())
    d[v].append(i)

keys = sorted(d.keys())
s = deque(d[keys[0]])

for k in keys[1:]:
    used = set()
    for i in d[k]:
        j = bisect_left(s, i)
        if 0<j<=len(s):
            if not s[j-1] in used:
                s[j-1] = i
            else:
                s = s[:j] + [i] + s[j:]
        elif j==0:
            s.appendleft(i)
        used |= {i}

print(len(s))
Problem p02985 (python)

Fixed submission:
from collections import defaultdict
v = defaultdict(list)
mod = 10**9+7

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

visited = [False]*(N+1)
ans = 1

q = [(1, 0, 0)]
while q:
    pos, parent, score = q.pop()
    visited[pos] = True
    ans *= (K-score)
    ans %= mod 
   
    a = 1 if pos==1 else 2
    b = 0

    for i in v[pos]:
        if visited[i]:continue
        q.append((i, pos, a+b))
        b += 1

print(ans)

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

N, K = map(int, input().split())
d = defaultdict(list)
MOD = 10**9+7

for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

ans = K
used = [0]*(N+1)
used[1] = True
q = deque([1])

while q:
    s = 1 if a==1 else 2
    for b in d[a]:
        if used[b]:continue
        used[b] = True
        ans *= (K-s)
        s += 1
        q.append(b)

ans %= MOD
print(ans)

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

N, K = map(int, input().split())
d = defaultdict(list)
MOD = 10**9+7

for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

ans = K
used = [0]*(N+1)
used[1] = True
q = deque([1])

while q:
    a = q.popleft()
    s = 1 if a==1 else 2
    for b in d[a]:
        if used[b]:continue
        used[b] = True
        ans *= (K-s)
        s += 1
        q.append(b)
	ans %= MOD

print(ans%MOD)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from functools import reduce
import sys
sys.setrecursionlimit(1000000)

v = defaultdict(list)
mod = 10**9+7

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

v = dict(v)
visited = [False]*(N+1)
p = [0]*(N+1)

def dfs(pos, parent, score):
    visited[pos] = True
    p[pos] = K - score
   
    a = 1 if pos==1 else 2
    b = 0

    for i in v[pos]:
        if visited[i]:continue
        dfs(i, pos, a+b)
        b += 1

dfs(1, 0, 0)

ans = p[1]
for i in p[2:]:
    ans *= i
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from functools import reduce
import sys
sys.setrecursionlimit(1000000)

v = defaultdict(list)
mod = 10**9+7

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

v = dict(v)
visited = [False]*(N+1)
p = [0]*(N+1)

def dfs(pos, parent, score):
    visited[pos] = True
    p[pos] = K - score
   
    a = 1 if pos==1 else 2
    b = 0

    for i in v[pos]:
        if visited[i]:continue
        dfs(i, pos, a+b)
        b += 1

dfs(1, 0, 0)
ans = reduce(lambda x,y:(x*y)%mod, p[1:])
print(ans)
Problem p02997 (python)

Fixed submission:
N, K = map(int, input().split())

amax = (N-1)*(N-2)//2
if amax-K>=0:
    print(amax-K+N-1)
    for i in range(N-1):
        print(1, i+2)
    cnt = 0

    def out(x):
        cnt = 0
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                if cnt == amax-K:
                    return
                print(i, j)
                cnt += 1
    out(amax-K)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

def f(N, K):
    for i in range(N+1):
        a = i*(i-1)//2
        for j in range(N+1):
            for k in range(N+1):
                if i+j+k+1==N and a+j+k==K:
                    return (i, j, k)
    return (-1, -1, -1)

i, j, k = f(N, K)
if i==-1 and j==-1 and k==-1:
    print(-1)
else:
    l = []
    for a in range(2, 2+i):
        l.append((1,a))

    p = a
    for a in range(p, p+j+1):
        l.append((a, a+1))
    p = a

    for a in range(p+j+1, N+1):
        for b in range(a+1, N+1):
            l.append((a,b))
    
    print(len(l))
    for a, b in l:
        print(a, b)
Problem p03026 (python)

Fixed submission:
from collections import defaultdict

V = defaultdict(list)
N = int(input())
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)
*c, = map(int, input().split())
c.sort(reverse=True)

root, _ = max(V.items(), key=lambda x:len(x[1]))
visited = [False] * (N+1)
identifier = [0] * (N+1)

p = 0
q = [root]
while q:
    a = q.pop()
    visited[a] = True
    identifier[a] = p

    p+=1

    for i in V[a]:
        if visited[i]:continue
        q.append(i)

cost = 0
visited = [False] * (N+1)
q = [root]
while q:
    a = q.pop()
    visited[a] = True
    p+=1

    for b in V[a]:
        if visited[b]:continue
        cost += min(c[identifier[a]], c[identifier[b]])
        q.append(b)

print(cost)
print(*[c[i] for i in identifier[1:]])

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

V = defaultdict(list)
N = int(input())
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)
*c, = map(int, input().split())
c.sort(reverse=True)

s = {}

cost = [-1]*(N+1)
p = 0
ans = 0
for v, l in sorted(V.items(),key=lambda x:-len(x[1])):
    print(cost[v], v, p, cost)
    if cost[v]==-1:
        cost[v] = c[p]
        p += 1

    for i in l:
        if cost[i]!=-1:continue
        cost[i] = c[p]
        s[(v, i)] = min(cost[i], cost[v])
        p += 1

print(sum(s.values()))
print(*cost[1:])
Problem p03068 (python)

Fixed submission:
N = int(input())
S = input()
K = int(input())
print("".join([i if i==S[K-1] else "*" for i in S]))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
K = int(input())
print("".join([i for i in S if i==S[K-1] else "*"]))
Problem p03078 (python)

Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

# x以上のものがK個あるならOK
def f(x):
    cnt = 0
    for i in A:
        for j in B:
            for k in C:
                if i+j+k<x:break
                cnt += 1
                if cnt>=K:
                    return True
    return False

def get_boarder():
    l, r = 0, A[0]+B[0]+C[0]
    while r-l>1:
        m = (l+r)//2
        if f(m):
            l = m
        else:
            r = m
    return l

boarder = get_boarder()
q = []
for i in A:
    for j in B:
        for k in C:
            if i+j+k<boarder:break
            heappush(q, -(i+j+k))

for _ in range(K):
    print(-heappop(q))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

q = []
visited = set()

a = A[0]
for i,b in enumerate(B):
    for j,c in enumerate(C):
        if not (0,i,j) in visited:
            heappush(q, -(a+b+c))
            visited.add((0,i,j))

b = B[0]
for i,a in enumerate(A):
    for j,c in enumerate(C):
        if not (i,0,j) in visited:
            heappush(q, -(a+b+c))
            visited.add((i,0,j))

c = C[0]
for i,a in enumerate(A):
    for j,b in enumerate(B):
        if not (i,j,0) in visited:
            heappush(q, -(a+b+c))
            visited.add((i,j,0))

for _ in range(K):
    print(-heappop(q))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

q = []
visited = set()

a = A[0]
for i,b in enumerate(B):
    for j,c in enumerate(C):
        if not (0,i,j) in visited:
            heappush(q, -(a+b+c))
            visited.add((0,i,j))

b = B[0]
for i,a in enumerate(A):
    for j,c in enumerate(C):
        if not (i,0,j) in visited:
            heappush(q, -(a+b+c))
            visited.add((i,0,j))

c = C[0]
for i,a in enumerate(A):
    for j,b in enumerate(B):
        if not (i,j,0) in visited:
            heappush(q, -(a+b+c))
            visited.add((i,j,0))

for _ in range(K):
    print(-heappop(q))
Problem p03096 (python)

Fixed submission:
from collections import defaultdict

N = int(input())
l = [int(input()) for _ in range(N)]
dp = [0] * (N+1)
pos = defaultdict(lambda: -1)
dp[0] = 1
MOD = 10**9+7

for i in  range(1, N+1):
    p = pos[l[i-1]]
    if i-p>1 and p!=-1:
        dp[i] += dp[p]
    pos[l[i-1]] = i
    dp[i] += dp[i-1]
    dp[i] %= MOD
    
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
l = [int(input()) for _ in range(N)]
dp = [0] * (N+1)
pos = [-1]*(N+1)
dp[0] = 1
MOD = 10**9+7

for i in  range(1, N+1):
    p = pos[l[i-1]]
    if i-p>1 and p!=-1:
        dp[i] += dp[p]
    pos[l[i-1]] = i
    dp[i] += dp[i-1]
    dp[i] %= MOD
    
print(dp[-1])
Problem p03106 (python)

Fixed submission:
a,b,c=map(int,input().split())
l=[]
for i in range(1,max(a,b)+1):
  if a%i==0 and b%i==0:
    l.append(i)
print(l[-c])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
rank=0
for i in range(1,max(a,b)+1):
  	if a%i==0 and b%i==0:
      rank+=1
    if rank==c:
      print(i)
      break
Problem p03168 (python)

Fixed submission:
N=int(input())
*p,=map(float,input().split())
dp=[[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0]=1

for i in range(1,N+1):
    for j in range(N+1):
        if j:
            dp[i][j]=dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1]
        else:
            dp[i][j]=dp[i-1][j]*(1-p[i-1])

t=N//2+1 if N%2 else N//2
ans=0
for i in range(t,N+1):
    ans+=dp[N][i]

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
*p,=map(float,input().split())
dp=[[0]*(N+1) for _ in range(N+1)]
dp[0][0]=1

for i in range(1,N+1):
    for j in range(N+1):
        dp[i][j]=dp[i-1][j]*(1-p[i-1])
        dp[i+1][j+1]+=dp[i][j]*p[i]

print(sum(dp[N][i] for i in range(N+1) if 2*i>=N))
Problem p03169 (python)

Fixed submission:
n=int(input())

b=[0,0,0]
for i in map(int,input().split()):
    b[i-1]+=1
k1,k2,k3=b
dp=[[[None]*(k3+1) for _ in range(k2+k3+1)] for _ in range(k1+k2+k3+1)]
dp[0][0][0]=0

for k in range(k3+1):
    for j in range(k2+k3+1-k):
        for i in range(k1+k2+k3+1-j-k):
            if not i+j+k:continue
            dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)

print(dp[k1][k2][k3])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

b=[0,0,0]
for i in a:
    b[i-1]+=1
k1,k2,k3=b

@lru_cache()
def f(i,j,k):
    v=0
    if not i+j+k:return 0.0
    v+=n
    if i:v+=f(i-1,j,k)*i
    if j:v+=f(i+1,j-1,k)*j
    if k:v+=f(i,j+1,k-1)*k
    v/=i+j+k
    return v

print(f(k1,k2,k3))
Problem p03206 (python)

Fixed submission:
D=int(input())
print(" ".join(["Christmas"]+["Eve"]*(25-D)))

Buggy submission (verdict: Runtime Error):
D=int(input())
print(" ".join(["Christmas"]+["Eve"]*(25-D))
Problem p03211 (python)

Fixed submission:
s=input()
n=len(s)
ans=float("inf")

for i in range(n-2):
  v=int(s[i:i+3])
  ans=min(ans,abs(753-v))

print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
print(min(abs(753-int(s[i:i+3])) for i in range(n-2)))
Problem p03213 (python)

Fixed submission:
from collections import Counter as c
from itertools import permutations as p

def fact(n):
    d=[]
    for i in range(2,int(n**0.5)+2):
        while n%i==0:
            n//=i
            d.append(i)
    if n!=1:d.append(n)
    return c(d)

n=int(input())
d=c()
for i in range(1,n+1):
    d+=fact(i)

v=sum(1 for i,j,k in p(d.values(),3) if i>=2 and j>=4 and k>=4)//2
v+=sum(1 for i,j in p(d.values(),2) if i>=2 and j>=24)
v+=sum(1 for i,j in p(d.values(),2) if i>=4 and j>=14)
v+=sum(1 for i in d.values() if i>=74)

print(v)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
from itertools import permutations as p

def factorize(n):
    d = dd(int)
    for i in range(2, int(n**0.5)+1):
        while n%i==0:
            d[i] += 1
            n //= i
        if not n:
            break
    if n>1:
        d[n] += 1
    return d

N = int(input())
d = defaultdict(int)
for i in range(1, N+1):
    e = factorize(i)
    for i,j in e.items():
        d[i] += j

ans = 0
for i, j, k in p(d.values(), 3):    
    if i>=2 and j>=4 and k>=4:
        ans += 1
ans //= 2

for i, j in p(d.values(), 2):
    if i>=2 and j>=24:
        ans += 1
    if i>=4 and j>=14:
        ans += 1

for i in d.values():
    if i>=74:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter as c

def fact(n):
    d=[]
    for i in range(2,int(n**0.5)+2):
        while n%i==0:
            n//=i
            d.append(i)
    if n!=1:d.append(n)
    return c(d)

n=int(input())
d=c()
for i in range(1,n+1):
    d+=fact(i)

f=lambda n,x:sum(1 for i in p(d.values(),n) if all(map(lambda x,y:x>=y,i,x)))
print(f(3,(2,4,4))//2+f(2,(2,24))+f(2,(4,14))+f(1,(74,)))
Problem p03230 (python)

Fixed submission:
N = int(input())

n1 = 8*N+1
a = int(n1**0.5)

if N==1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
elif N>=3 and n1==a**2:
    n = (-3+a)//2
    if (-3+a)%2:
        print("No")
    else:
        d = [[0]*(n+1) for _ in range(n+2)]
        d[0][0] = 1
        d[0][1] = 2
        d[1][0] = 2
        d[1][1] = 3
        d[2][0] = 3
        d[2][1] = 1
        for i in range(1, n):
            v = 4+((i-1)*(i+4)//2)
            c = 2+i

            for j in range(c):
                d[c][j] = v+j
                d[j][c-1] = v+j

        print("Yes")
        print(n+2)
        for i in range(n+2):
            print(n+1, *d[i], sep=" ")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())

n1 = 8*N+1
a = int(n1**0.5)

if N and n1==a**2:
    n = (-3+a)//2
    if (-3+a)%2:
        print("No")
    else:
        d = [[0]*(n+1) for _ in range(n+2)]
        d[0][0] = 1
        d[0][1] = 2
        d[1][0] = 2
        d[1][1] = 3
        d[2][0] = 3
        d[2][1] = 1
        for i in range(1, n):
            v = 4+((i-1)*(i+4)//2)
            c = 2+i

            for j in range(c):
                d[c][j] = v+j
                d[j][c-1] = v+j

        print("Yes")
        print(n+2)
        for i in range(n+2):
            print(n+1, *d[i], sep=" ")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())

n1 = 8*N+1
a = int(n1**0.5)

if n1==a**2:
    n = (-3+a)//2
    if (-3+a)%2:
        print("No")
    else:
        d = [[0]*(n+1) for _ in range(n+2)]
        d[0][0] = 1
        d[0][1] = 2
        d[1][0] = 2
        d[1][1] = 3
        d[2][0] = 3
        d[2][1] = 1
        for i in range(1, n):
            v = 4+((i-1)*(i+4)//2)
            c = 2+i

            for j in range(c):
                d[c][j] = v+j
                d[j][c-1] = v+j

        print("Yes")
        print(n+2)
        for i in range(n+2):
            print(n+1, *d[i], sep=" ")
else:
    print("No")
Problem p03231 (python)

Fixed submission:
def gcd(a,b):
  if a%b==0:return b
  return gcd(b,a%b)

f=lambda x,y:x*y//gcd(x,y)
n,m=map(int,input().split())
s,t=input(),input()
lcm=f(n,m)
a,b=lcm//n,lcm//m
d={}

for i in range(n):
  d[i*a]=s[i]
for i in range(m):
  if i*b in d and d[i*b]!=t[i]:
    print(-1)
    break
  d[i*b]=t[i]
else:
  print(lcm)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  if a%b==0:return b
  return gcd(b,a%b)

f=lambda x,y:x*y//gcd(x,y)
n,m=map(int,input().split())
s,t=input(),input()
lcm=f(n,m)
a,b=lcm//n,lcm//m
l=[None]*lcm

for i in range(n):
  l[i*a]=s[i]
for i in range(m):
  if l[i*b] and l[i*b]!=t[i]:
    print(-1)
    break
  l[i*b]=t[i]
else:
  print(lcm)
Problem p03241 (python)

Fixed submission:
def f():
  n,m=map(int,input().split())
  for i in range(m//n+1)[::-1]:
    if m%i==0:return i
print(f())

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
for i in range(m//n+1)[::-1]:
	if m%i==0:
		print(i)
        exit()
Problem p03263 (python)

Fixed submission:
h,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(h)]
m=[]

for y in range(h):
  for x in range(w):
    if x<w-1 and l[y][x]%2:
      l[y][x]-=1
      l[y][x+1]+=1
      m.extend([[y+1,x+1,y+1,x+2]])

for x in range(w):
  for y in range(h):
    if y<h-1 and l[y][x]%2:
      l[y][x]-=1
      l[y+1][x]+=1
      m.extend([[y+1,x+1,y+2,x+1]])

print(len(m))
for i in m:
  print(*i,sep=" ")

Buggy submission (verdict: Runtime Error):
N = int(input())
for _ in range(N):
  a, b, c = map(int, input().split())
  if (100*a+10*b+c)%2:
    print("No")
  else:
    v = (100*a+10*b+c)//2
    
    a1 = min(v//100, a)
    b1 = min((v-100*a1)//10, b)
    c1 = min(v-100*a1-10*b1, c)
    
    d1 = 100*a1+10*b1+c1
    d2 = 100*(a-a1)+10*(b-b1)+(c-c1)
    print("Yes" if d1==d2 else "No")
Problem p03274 (python)

Fixed submission:
n,k=map(int,input().split())
x=list(map(int,input().split()))
v=1e9
for l in range(n-k+1):
  r=l+k-1
  a=abs(x[l])+abs(x[l]-x[r])
  b=abs(x[r])+abs(x[l]-x[r])
  v=min(v,min(a,b))
print(v)

Buggy submission (verdict: Runtime Error):
import bisect
n,k=map(int,input().split())
o=list(map(int,input().split()))
a=1e9

p=bisect.bisect_left(o,0)
for l in range(k):
  r=l+k-1
  if l<=p<=r and r<n:
    if o[l]>=0:
      v=abs(o[r])
    else:
      a=abs(o[l])+2*abs(o[r])
      b=2*abs(o[l])+abs(o[r])
      v=min(a,b)
  a=min(a,v)
print(a)
Problem p03282 (python)

Fixed submission:
s=input()
k=int(input())
c=0

if k==1:
  print(s[0])
elif k>1:
  while c<k-1 and s[c]=="1":
    c+=1

  if k-1<c:
    print(s[c-1])
  else:
    print(s[c])

Buggy submission (verdict: Runtime Error):
s=input()
k=input()
if s[0]=="1":
  print(s[1])
else:
  print(s[0])
Problem p03331 (python)

Fixed submission:
n=int(input())
f=lambda x:sum(map(int,str(x)))
v=1e9
for i in range(1,n//2+1):
  a=i
  b=n-i
  v=min(v,f(a)+f(b))
print(v)

Buggy submission (verdict: Runtime Error):
n=int(input())
f=lambda x:sum(map(int,str(x)))
v=1e9
for i in range(1,n//2+3):
  a=i
  b=n-i
  v=min(v,f(a)+f(b))
print(v)
Problem p03385 (python)

Fixed submission:
import itertools
l=["".join(i) for i in itertools.permutations("abc")]
if input() in l:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
l=["".join(i) for i in itertools.permutations("abc")]
if input() in l:
  print("Yes")
else:
  print("No")
Problem p03393 (python)

Fixed submission:
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
  for j in sorted(s[-i+1:]):
    if j>s[-i]:break
  print(s[:-i]+j)

Buggy submission (verdict: Runtime Error):
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
for j in sorted(s[-i+1:]):
  if j>s[-i]:break
print(s[:-i]+j)

Buggy submission (verdict: Runtime Error):
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
for j in sorted(s[i+1:]):
  if j>s[i]:break
print(s[:i]+j)

Buggy submission (verdict: Runtime Error):
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  for i in range(n-1)[::-1]:
    if s[i]<s[i+1]:
      break
    if i==0:
      print(-1)
      exit()
for j in sorted(s[i+1:]):
  if j>s[i]:
    break
print(s[:i]+j)
Problem p03409 (python)

Fixed submission:
n=int(input())
a={tuple(map(int,input().split())):False for _ in range(n)}
b=sorted([tuple(map(int,input().split())) for _ in range(n)])

ak=sorted(a.keys(),key=lambda x:x[1])[::-1]

for i in b:
  for j in ak:
    if i[0]<j[0] or i[1]<j[1] or a[j]:continue
    else:
      a[j]=True
      break

print(sum(a.values()))

Buggy submission (verdict: Runtime Error):
N=int(input())
l=[list(map(int,input().split())) for _ in range(N)]
m=[list(map(int,input().split())) for _ in range(N)]
o=[[i for (i,j) in enumerate(m) if j[0]>k[0] and j[1]>k[1]] for k in l]
s=set()
for i in p:
  for l in i:
    if not l in s:
      s.add(l)
      break
print(len(s))