Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
p = l_inpl()

ans = 0
for i in range(N):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1

if p[-1] == N:
    ans += 1

print(ans)

Fixed submission:
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
p = l_inpl()

ans = 0
for i in range(N-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1

if p[-1] == N:
    ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n, m= map(int,input().split())
one_fune = []
n_fune = []
for _ in range(m):
    li = list(map(int,input().split()))
    if 1 in li:
        li.remove(1)
        one_fune.append(li[0])
    elif n in li:
        li.remove(n)
        n_fune.append(li[0])

flag = False
for o in one_fune:
    if o in n_fune:
        flag = True
        break

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n, m= map(int,input().split())
fune = []
for _ in range(m):
    li = list(map(int,input().split()))
    if 1 in li:
        li.remove(1)
        fune.append(li[0])
    elif n in li:
        li.remove(n)
        fune.append(li[0])

if len(fune)-len(set(fune))>0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n = int(input())
a = list(map(int,input().split()))

ans = 10**100
for i in range(1, n):
    if ans>abs(sum(a[:i])-sum(a[i:])):
        ans = abs(sum(a[:i])-sum(a[i:]))

print(ans)

Fixed submission:

from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n = int(input())
a = list(map(int,input().split()))

ans = 10**100
res = np.cumsum(a)

print(min([abs(res[-1]-res[i]-res[i]) for i in range(len(res)-1)]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n = int(input())
a = list(map(int,input().split()))

ans = 10**100
for i in range(1, n):
    if ans>abs(sum(a[:i])-sum(a[i:])):
        ans = abs(sum(a[:i])-sum(a[i:]))

print(ans)

Fixed submission:

from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n = int(input())
a = list(map(int,input().split()))

ans = 10**100
res = np.cumsum(a)

print(min([abs(res[-1]-res[i]-res[i]) for i in range(len(res)-1)]))
Buggy python submission (verdict: Time Limit Exceeded):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

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

#### START
n = int(input())
a = list(map(int,input().split()))

b = []
for a_i in a:
  b.append(a_i)
  b.reverse()

print(*b, sep=" ")

Fixed submission:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

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

#### START
n = int(input())
a = list(map(int,input().split()))

b = a[::2]
c = a[1::2]

if n%2 == 0:
  ans = list(reversed(c)) + b
  print(*ans, sep=" ")
else:
  ans = list(reversed(b)) + c
  print(*ans, sep=" ")
Buggy python submission (verdict: Runtime Error):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def check(h, x, A, B):
    h = [ hi - B * x for hi in h ]
    c = 0
    for hi in h:
        if hi <= 0:
            continue
        c += math.ceil(hi/(A-B))
    return c <= x

def main():
    N, A, B = l_inpl()
    h = line_inpl(N)

    l, r = 0, max(h)//B + 1000
    while l + 1 != r:
        mid = (l+r) // 2
        if check(h, mid, A, B):
            r = mid
        else:
            l = mid
    
    print(r)

if __name__ == "__main__":
    main()


Fixed submission:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def check(h, x, A, B):
    h = [ hi - B * x for hi in h ]
    c = 0
    for hi in h:
        if hi <= 0:
            continue
        c += math.ceil(hi/(A-B))
    return c <= x

def main():
    N, A, B = l_inpl()
    h = line_inpl(N)

    l, r = 0, max(h)//B + 1000
    while l + 1 != r:
        mid = (l+r) // 2
        if check(h, mid, A, B):
            r = mid
        else:
            l = mid
    
    print(r)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N, A, B = l_inpl()
v = l_inpl()

sort_v = sorted(v, reverse=True)
ans_1 = sum(sort_v[:A])/A
print(ans_1)

max_v = sort_v[A-1]
max_v_count = sort_v.count(max_v)
max_v_count_in_ans = sort_v[:A].count(max_v)

if max_v != sort_v[0]: # 1つでも増やすと平均が減少する場合
    ans = comb(max_v_count, max_v_count_in_ans)
else:
    ans = 0
    for i in range(A, min(B, max_v_count) + 1):
        ans += comb(max_v_count, i)

print(int(ans))


Fixed submission:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

def C(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))

N, A, B = l_inpl()
v = l_inpl()

sort_v = sorted(v, reverse=True)
ans_1 = sum(sort_v[:A])/A
print(ans_1)

max_v = sort_v[A-1]
max_v_count = sort_v.count(max_v)
max_v_count_in_ans = sort_v[:A].count(max_v)

if max_v != sort_v[0]: # 1つでも増やすと平均が減少する場合
    ans = C(max_v_count, max_v_count_in_ans)
else:
    ans = 0
    for i in range(A, min(B, max_v_count) + 1):
        ans += C(max_v_count, i)

print(int(ans))
Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)


Fixed submission:
import fractions 
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd


ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)

print(ans)


Fixed submission:
import fractions 
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd


ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)

print(ans)


Fixed submission:
import fractions 
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(2)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[1][-1]-cum_M[1][b])
        
print(int(counter))


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
counter = 0
for b in B:
    counter += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))

print(counter)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(3)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][B[i]] += 1
    M[2][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[2][-1]-cum_M[2][b])
        
print(counter)


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
counter = 0
for b in B:
    counter += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))

print(counter)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(3)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][B[i]] += 1
    M[2][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[2][-1]-cum_M[2][b])
        
print(counter)


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
counter = 0
for b in B:
    counter += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
seq = []
for i in range(N):
    a, b = map(int, input().split())
    for j in range(b):
        seq.append(a)

seq.sort()
print(seq[K-1])


Fixed submission:
from collections import defaultdict
N, K = map(int, input().split())
seq = defaultdict(lambda: 0) 
for i in range(N):
    a, b = map(int, input().split())
    seq[a] += b

values = list(seq.keys())

values.sort()
ans = 0
for i in range(len(values)):
    K -= seq[values[i]]
    if(K<=0):
        print(values[i])
        break
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
tmp_sum = a1[0]
operate_num1 = 0
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num1 =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num1
        a1[i] += tmp_operate_num1
    else:
        tmp_operate_num1 = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num1
        a1[i] -= tmp_operate_num1
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
tmp_sum = a2[0]
operate_num2 = 0
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num2 =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num2
        a2[i-1] -= tmp_operate_num2
        tmp_sum -= tmp_operate_num2
    else:
        tmp_operate_num2 = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num2
        a2[i-1] += tmp_operate_num2
        tmp_sum += tmp_operate_num2
    tmp_sum += a2[i]
print(min(operate_num1, operate_num2))        


Fixed submission:
import copy
n = int(input())
a = list(map(int, input().split()))

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
operate_num1 = 0
if a1[0]==0:
    a1[0] = 1
    operate_num1 += 1
tmp_sum = a1[0]
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num
        a1[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num
        a1[i] -= tmp_operate_num
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
operate_num2 = 0
if a2[0]<0:
    operate_num2 += 1 - a2[0]
    a2[0] += operate_num2
else:
    operate_num2 += a2[0] + 1
    a2[0] -= operate_num2

tmp_sum = a2[0]

for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num
        a2[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num
        a2[i] -= tmp_operate_num
    tmp_sum += a2[i]

print(min(operate_num1, operate_num2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 1
def incr(a,b):
    if a>b:
        return -1
    elif a==b:
        return 0
    else:
        return 1
init = incr(a[0], a[1])
flag = True
for i in range(1, n-1):
    tmp = incr(a[i], a[i+1])
    #print("a[i]=", a[i]," a[i+1]=", a[i+1], " init=", init, " tmp=", tmp)
    if tmp==0:
        tmp = init
    if init*tmp<0 and flag:
        ans += 1
        init = tmp
        flag = False
        #print(i)
        continue
    init = tmp
    flag = True
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
incr = None
for i, x in enumerate(a):
    if i==0:
        before = x
        continue
    if incr==None:
        if x > before:
            incr = 1
        elif x < before:
            incr = -1
        before = x
        continue
    if (incr==1)and(x < before):
        ans += 1
        incr = None
    elif (incr==-1)and(x > before):
        ans += 1
        incr = None
    before = x    
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
del_a = [a[i+1]-a[i] for i in range(n-1)]
ans = 1
tmp = 0
before = del_a[0]
length = 1 
for i in range(1,n-1):
    tmp = del_a[i]
    if(before*tmp<0)and(length>1):
        length = 1
        ans += 1
    elif(before*tmp<0)and(i==n-2):
        ans+=1
    else:
        length += 1
    before = del_a[i]
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
incr = None
for i, x in enumerate(a):
    if i==0:
        before = x
        continue
    if incr==None:
        if x > before:
            incr = 1
        elif x < before:
            incr = -1
        before = x
        continue
    if (incr==1)and(x < before):
        ans += 1
        incr = None
    elif (incr==-1)and(x > before):
        ans += 1
        incr = None
    before = x    
print(ans)
Buggy python submission (verdict: Runtime Error):
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        ans = [i for i in range(2, n, 2) for j in range(2)]
        ans.insert(0, 0)
        if ans != a:
            print(0)
            flag = False
    if flag:
        print((2**((n - 1) // 2)) % (1e9 + 7))

else:
    ans = [i for i in range(1, n, 2) for j in range(2)]
    if ans != a:
        print(0)
        flag = False
    if flag:
        print((2**(n // 2)) % (1e9 + 7))


Fixed submission:
print(eval(input()))
Buggy python submission (verdict: Runtime Error):
def solve(A: int, B: int):
    ans = max(0, A - (2 * B))
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    ans = max(0, A - (2 * B))
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()