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

Fixed submission:
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
ansi=min(s.count('.'),s.count('#'))
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)
ansi=min(ansi,p)
print(ansi)
  
# This code is contributed 
# by Anant Agarwal.

Buggy submission (verdict: Runtime Error):
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
ansi=min(s.count('.'),s.count('#'))
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)) 
ansi=min(ans,p)
print(ans)
  
# This code is contributed 
# by Anant Agarwal.

Buggy submission (verdict: Runtime Error):
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
ans=min(s.count('.'),s.count('#'))
if s.count()
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)) 
ans=min(ans,p)
print(ans)
  
# This code is contributed 
# by Anant Agarwal.
Problem p02928 (python)

Fixed submission:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

mod = 10**9 + 7

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % mod 
    C = (C + np.sum(A < A[i])) % mod 
    
k_sum = int((K-1) * K//2) % mod 

E = (B * K) % mod 
F = (C * k_sum) % mod 

print(int((E+F) % mod ))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

for i in range(N):
    D = A[i::]
    B += np.sum(D < A[i]) % (10**9 + 7)
    C += np.sum(A < A[i]) % (10**9 + 7)
    
E = B * K % (10**9 + 7)
F = C * (np.sum(np.arange(K-1)+1) % (10**9 + 7)) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

B = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i::]
    B[i] = np.sum(D < A[i]) % (10**9 + 7)
    C[i] = np.sum(A < A[i]) % (10**9 + 7)
    
E = np.sum(B) * K % (10**9 + 7)
F = np.sum(C) * (np.sum(np.arange(K-1)+1) % (10**9 + 7)) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

B = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i::]
    B[i] = np.sum(D < A[i]) % (10**9 + 7)
    C[i] = np.sum(A < A[i]) % (10**9 + 7)
    
E = np.sum(B) * K % (10**9 + 7)
F = np.sum(C) * np.sum(np.arange(K-1)+1) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i::]
    B[i] = np.sum(D < A[i])
    C[i] = np.sum(A < A[i])
    
E = np.sum(B) * K % (10**9 + 7)
F = np.sum(C) * np.sum(np.arange(K-1)+1) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))
Problem p02972 (python)

Fixed submission:
import numpy as np
import copy

N = int(input())  
a = np.array(input().split(), dtype=np.int32)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[i::i+1]
    if np.sum(A) % 2  == 0:
        a[i] = 0
    else:
        a[i] = 1
        
ans = np.where(a == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())  
a = np.array(input().split(), dtype=np.int64)
b = copy.deepcopy(A)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[np.where(M % (i+1) == 0)]
    if (np.sum(A) + a[i]) % 2  == 0:
        b[i] = a[i]
    else:
        b[i] = (a[i] + 1) % 2
        
ans = np.where(b == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))
Problem p02983 (python)

Fixed submission:
import numpy as np

L,R = map(int, input().split())

if  R-L > 2018:
    print(0)
    
else:
    ans = 2018
    
    R = R % 2019
    L = L % 2019

    if L > R:
        R += 2019
        
    if R - L > 500:
        print(0)
        
    else:
        for i in np.arange(L, R+1):
            for j in np.arange(i+1, R+1):
                i = i % 2019
                j = j % 2019
                k = i * j % 2019
                ans = np.amin(np.array([k, ans]))
            
        print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

L,R = map(int, input().split())

A = np.arange(L, R+1)

if  R-L > 2018:
    print(0)
    
elif np.count_nonzero(A % 2019 == 0) > 0:
    print(0)
    
else:
    ans = 2019
    for i in np.arange(L, R+1):
        for j in np.arange(i+1, R+1):
            ans = np.amin(np.array([i * j % 2019, ans]))
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

L,R = map(int, input().split())

A = np.arange(L, R+1)

if  R-L > 2019:
    print(0)
    
elif np.count_nonzero(A == 2019) == 1:
    print(0)
    
else:
    ans = 2019
    for i in np.arange(L, R+1):
        for j in np.arange(i+1, R+1):
            ans = np.amin(np.array([i * j % 2019, ans]))
    print(ans)
Problem p02995 (python)

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

A,B,C,D = map(int, input().split())

c = B//C - (A-1)//C
d = B//D - (A-1)//D

CD = C * D // gcd(C, D)
cd = B//CD - (A-1)//CD

ans = B - (A-1) - (c + d - cd)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int, input().split())

c1 = int((B - B%C)/C) - int(((A-1) - (A-1)%C)/C)
d1 = int((B - B%D)/D) - int(((A-1) - (A-1)%D)/D)

CD = int((C * D - C * D % math.gcd(C, D)) / math.gcd(C, D))
cd1 = int((B - B%CD)/CD) - int(((A-1) - (A-1)%CD)/CD)

ans = B - (A-1) - (c1 + d1 - cd1)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int, input().split())

c = int((B - B%C)/C) - int(((A-1) - (A-1)%C)/C)
d = int((B - B%D)/D) - int(((A-1) - (A-1)%D)/D)

CD = int((C * D - C * D % math.gcd(C, D)) / math.gcd(C, D))
cd = int((B - B%CD)/CD) - int(((A-1) - (A-1)%CD)/CD)

ans = B - (A-1) - (c + d - cd)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int, input().split())

c = int(B/C) - int((A-1)/C)
d = int(B/D) - int((A-1)/D)

CD = int(C * D / math.gcd(C, D))
cd = int(B/CD) - int((A-1)/CD)

ans = B - (A-1) - (c + d - cd)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int, input().split())

c = int(B/C) - int((A-1)/C)
d = int(B/D) - int((A-1)/D)

CD = C * D / math.gcd(C, D)
cd = int(B/CD) - int((A-1)/CD)

ans = B - (A-1) - (c + d - cd)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

A,B,C,D = map(int, input().split())

c = int(B/C) - int((A-1)/C)
d = int(B/D) - int((A-1)/D)

CD = C * D / math.gcd(C, D)
cd = int(B/CD) - int((A-1)/CD)

ans = B - (A-1) - (c + d - cd)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

A,B,C,D = map(int, input().split())

c = int(B/C) - int((A-1)/C)
d = int(B/D) - int((A-1)/D)

CD = C * D / math.gcd(C, D)
cd = int(B/CD) - int((A-1)/CD)

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

A,B,C,D = map(int, input().split())

c = (B  - B%C) / C - ((A-1)  - (A-1)%C)/C
d = (B  - B%D) / D - ((A-1)  - (A-1)%D)/D

CD = (C * D  - (C * D % math.gcd(C, D))) / math.gcd(C, D)
cd = (B  - B%CD) / CD - ((A-1)  - (A-1)%CD)/CD

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

A,B,C,D = map(int, input().split())

c = (B  - B%C) / B - ((A-1)  - (A-1)%C)/C
d = (B  - B%D) / B - ((A-1)  - (A-1)%D)/D

CD = (C * D  - (C * D % math.gcd(C, D))) / math.gcd(C, D)
cd = (B  - B%CD) / B - ((A-1)  - (A-1)%CD)/CD

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

A,B,C,D = map(int, input().split())

c = B//C - (A-1)//C
d = B//D - (A-1)//D

CD = C * D // math.gcd(C, D)
cd = B//CD - (A-1)//CD

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)
Problem p02996 (python)

Fixed submission:
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = np.argsort(B)

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = B[np.argsort(B)]

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())

a = 0
for i in range(1000000):
    C = np.random.permutation(np.arange(N))
    k = 0
    a = 0
    b = 0
    for j in range(N):
        k += A[C[i]]
        if  k > B[i]:
            a = 1
            
    if a == 0:
        b = 1
        print('Yes')
        break
    
if b == 0:
    print('No')
Problem p02921 (python)

Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

S = list(input().rstrip())
T = list(input().rstrip())

count = 0
for i in range(3):
    if S[i] == T[i]:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
x
Problem p02924 (python)

Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


count = 0
for i in range(N):
    if i == (N-1):
        count += (i+1) % (1)
    else:
        count += (i+1) % (i+2)

print(count)
Problem p02936 (python)

Fixed submission:

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)

#print(tree_index)


ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x

def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur]
      dfs(chl, cur)
dfs(0, -1)
print(*ans)

Buggy submission (verdict: Runtime Error):

def inc(tree, point, p, x):
    # 自分
    point[p] += x
    if tree[p] == -1:
        return

    for child in tree[p]:
        inc(tree, point, child, x)


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

tree = [-1] * (N+1)
point = [0] * (N+1)

for i in range(N-1):
    a, b = map(int, input().split())
    if tree[a] == -1:
        tree[a] = [b]
    else:
        tree[a] += [b]

for i in range(Q):
    p, x = map(int, input().split())

    inc(tree, point, p, x)

point.pop(0)
print(*point)
Problem p02971 (python)

Fixed submission:

n = int(input())
A = [int(input()) for _ in range(n)]

first = max(A)
second = sorted(A)[-2]
for i in range(n):
    if first == A[i]:
        print(second)
    else:
        print(first)

Buggy submission (verdict: Runtime Error):

N = int(input())
A = [int(input()) for _ in range(N)]

L = [0] * (max(A)+1)
R = [0] * (max(A)+1)

L[0] = 0
for i in range(1, N+1):
    L[i] = max(A[i-1], L[i-1])

R[N] = 0
for i in range(N-1, 0, -1):
    R[i] = max(R[i+1], A[i])

#print(L)
#print(R)

for i in range(N):
    ans = max(L[i], R[i+1])
    print(ans)
Problem p02993 (python)

Fixed submission:
S = input()
before = ''
for x in S:
    if before == x:
        print('Bad')
        exit()
    before = x

print('Good')

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################
from fractions import gcd

# 最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())

A -= 1

# a/b以下の条件を満たす数
nb = B - B//C - B//D + B//lcm(C, D)
na = A - A//C - A//D + A//lcm(C, D)

print(nb - na)

Buggy submission (verdict: Runtime Error):

n, l = map(int, input().split())

# 味リストはL, L+1, L+2...
tastes = []
for i in range(n):
    tastes += [l+i]

# 味0があったらそれを食えばいい
if 0 in tastes:
    print(sum(tastes))
else:
    # 差が最小なのを食えばいい
    tastes.sort(key=abs)
    print(sum(tastes[1:]))
Problem p02994 (python)

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

# 味リスト
tastes = []
for i in range(n):
    tastes += [l+i]

# 全部
all_tastes = sum(tastes)

# 食ったあとの味リスト
ptn = []
for x in tastes:
    ptn += [all_tastes - x]

# 元との差(abs)
di = []
for i in range(n):
    di += [abs(all_tastes - ptn[i])]

min_value = min(di)
print(ptn[di.index(min_value)])

Buggy submission (verdict: Runtime Error):
# 味リストはL, L+1, L+2...
tastes = []
for i in range(n):
    tastes += [l+i]

# 味0があったらそれを食えばいい
if 0 in tastes:
    print(sum(tastes))
else:
    # 差が最小なのを食えばいい
    tastes.sort(key=abs)
    print(sum(tastes[1:]))
Problem p03031 (python)

Fixed submission:

N, M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
P = list(map(int,input().split()))

ans = 0
# (0, 1, 2, ... 2^n-1) の部分集合の全探索（0を含むので合計2^n個)
# 例えば8なら、000〜111までの全部なので、スイッチの全パターンをなめる
for b in range(1<<N):  # 2**nでも一緒
    # 縦軸（M個の電球）→ スイッチ0の電球全部、スイッチ1の電球全部, ...
    for i in range(M):
        c = 0

        # スイッチ番号を順番に取得
        for s in src[i][1:]:
            # bにswitch_num番目のフラグがたってるか？
            # つまり、全探索のなかで、ビットがたってたら「処理をする」というだけ
            switch_num = s-1

            # どうせ全部なめるので、どっちでもいい
#            if b & (1<<(switch_num)):
            if (b >> switch_num) & 1 == 1:
                c += 1

        if c%2 != P[i]:
            break
    else:
        # 割り切れたらその電球は点いてるのでカウント対象
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
give up
Problem p03037 (python)

Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N, M = map(int, input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    l, r = map(int, input().split())
    L[i] = l
    R[i] = r

left = max(L)
right = min(R)

if left <= right:
    print(right-left+1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
cannot understand the q
Problem p03274 (python)

Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


'''
https://img.atcoder.jp/arc101/editorial.pdf
https://atcoder.jp/contests/abc107/submissions/5375441

l → r の順：|xl| + |xr-xl|
r → l の順：|xr| + |xr-xl|
'''


N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for i in range(N-K+1):
    left = X[i]
    right = X[i+K-1]
    ans = min(ans, abs(left)+abs(right-left), abs(right)+abs(left-right))

print(ans)

Buggy submission (verdict: Runtime Error):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N, K = map(int, input().split())
X = list(map(int, input().split()))

left = []
right = []

# ある意味もとから累積和
for c in X:
    if c < 0:
        left.append(abs(c*2))
    else:
        right.append(c)

# 番兵
left.append(0)
left.reverse()
#print(left, right)


# i 個、左から取る
ans = float('inf')
for i in range(len(left)):
    remain = K-i

    # 個数足りない
    if len(right[:remain]) < remain:
        continue

    x = left[i] + right[K-i-1]
#    print(x, left[i], right[K-i-1])
    ans = min(ans, x)

print(ans)
Problem p03435 (python)

Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

# http://mkan-0141.hatenablog.com/entry/2018/02/18/224008


C = []
for i in range(3):
    x = list(map(int, input().split()))
    C.append(x)

if(C[0][0] - C[0][1] == C[1][0] - C[1][1] and # a1のb1<>b2 と a2のb1<>b2の比較
   C[1][0] - C[1][1] == C[2][0] - C[2][1] and # a2のとa3の b1<>b2の比較
   C[0][1] - C[0][2] == C[1][1] - C[1][2] and # a0のとa1のb2<>b3の比較
   C[1][1] - C[1][2] == C[2][1] - C[2][2]):   # a2のとa3のb2<>b3の比較
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x
Problem p03472 (python)

Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, H = map(int, input().split())
A = []
B = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

max_a = max(A)

t = B[:]
t.sort(reverse=True)

count = 0
for i in range(N):
    # 先に投げても後で投げても同じなので、最初に全部投げちゃう
    # ただし強いものから投げないと、投げ終わる前に倒すケースで引っかかる
    if t[i] >= max_a:
        H -= t[i]
        count += 1

    if H <= 0:
        print(count)
        exit()


# 近いところまでまとめて引く
x = (H // max_a) - 1
H -= (max_a * x)
count += x

while H > 0:
    H -= max_a
    count += 1


print(count)

Buggy submission (verdict: Runtime Error):

N, H = map(int, input().split())
A = []
B = []

max_a = 0
max_a_b = 0
max_a_i = 0

max_b = 0
max_b_a = 0
max_b_i = 0

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

    if max_a < a:
        max_a = a
        max_a_b = b
        max_a_i = i

    if max_b < b:
        max_b = b
        max_b_a = a
        max_b_i = i

def get_count(N, H, max_a, max_a_b, max_a_i):
    count = 0
    for i in range(N):
        # 残すやつは何もしない
        if i == max_a_i:
            continue

        # 投げる
        if B[i] >= max_a:
            H -= B[i]
            count += 1

    # 近いところまでまとめて引く
    x = ((H-max_a_b) // max_a) - 1
    H -= (max_a * x)
    count += x

    while H > 0:
        if H <= max_a_b:
            # 投げて終わり
            count += 1
            break

        H -= max_a
        count += 1

    return count

ans = INF
count = get_count(N, H, max_a, max_a_b, max_a_i)
if count < ans:
    ans = count

count = get_count(N, H, max_b_a, max_b, max_b_i)
if count < ans:
    ans = count

print(ans)
Problem p03612 (python)

Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())
P = list(map(int,input().split()))

P.append(0) # 番兵

count = 0
for i in range(N):
    if P[i] == i+1:
        x = P[i]
        P[i] = P[i+1]
        P[i+1] = x
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())
P = list(map(int,input().split()))

count = 0
for i in range(N):
    if P[i] == i+1:
        x = P[i]
        P[i] = P[i+1]
        P[i+1] = x
        count += 1

print(count)
Problem p03999 (python)

Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

S = input().rstrip()
l = list(S)
N = len(l)

if S == '1':
    print(1)
    exit()

def getbit(i, length):
    return format(i, '0' + str(length) + 'b')

bits = []
for i in range(2**(N-1)):
    bits.append(getbit(i, N-1))


ans = 0

for i in range(len(bits)):
    s = str(l[0])

    bitlist = list(bits[i])
    for j in range(len(bitlist)):
        if bitlist[j] == '0':
            pass
        else:
            s += '+'

        s += str(l[j+1])

    ans += eval(s)

print(ans)

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

S = input().rstrip()
l = list(S)
N = len(l)

def getbit(i, length):
    return format(i, '0' + str(length) + 'b')

bits = []
for i in range(2**(N-1)):
    bits.append(getbit(i, N-1))


ans = 0

for i in range(len(bits)):
    s = str(l[0])

    bitlist = list(bits[i])
    for j in range(len(bitlist)):
        if bitlist[j] == '0':
            pass
        else:
            s += '+'

        s += str(l[j+1])
    ans += eval(s)

print(ans)
Problem p03032 (python)

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

dp=[[[-1 for i in range(k+1)] for j in range(n+1)] for l in range(n+1)]

def f(a, b, d):
    if d == 0: return 0
    if a == b and d > 1 and v[a] > 0: return v[a]
    if a == b and d > 1 and v[a] <= 0: return 0
    if dp[a][b][d] != -1: return dp[a][b][d]
    maxi = max(v[a] + f(a+1, b, d - 1), v[b] + f(a, b - 1, d - 1))
    if v[a] < 0 and d > 1:
        maxi = max(maxi, f(a + 1, b, d - 2))
    if v[b] < 0 and d > 1:
        maxi = max(maxi, f(a, b - 1, d - 2))
    maxi = max(maxi, 0)
    dp[a][b][d]=maxi
    return maxi


print(f(0, n-1, k))

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

dp=[[[-1 for i in range(k+1)] for j in range(n+1)] for l in range(n+1)]

def f(a, b, d):
    if d == 0: return 0
    if a == b and d > 1 and v[a] > 0: return v[a]
    if dp[a][b][d] != -1: return dp[a][b][d]
    maxi = max(v[a] + f(a+1, b, d - 1), v[b] + f(a, b - 1, d - 1))
    if v[a] < 0 and d > 1:
        maxi = max(maxi, f(a + 1, b, d - 2))
    if v[b] < 0 and d > 1:
        maxi = max(maxi, f(a, b - 1, d - 2))
    maxi = max(maxi, 0)
    dp[a][b][d]=maxi
    return maxi


print(f(0, n-1, k))
Problem p03129 (python)

Fixed submission:
a,b = list(map(int, input().split()))
if a % 2 == 0:
    if a / 2 >= b:
        print("YES")
    else:
        print("NO")
else:
    if (a + 1) / 2 >= b:
        print("YES")
    else:
        print("NO")

Buggy submission (verdict: Runtime Error):
a,b = list(map(int, input().split()))
if a % 2 == 0:
  if a / 2 >= b:
    print("YES")
  else:
    print("NO")
else:
  if (a + 1) / 2 >= b:
    print("YES")
  else:
	print("NO")