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

Fixed submission:
from sys import stdin

# 標準入力の受取
sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
l = list(sdi)
l.reverse()
start = len(l)
i = 0
while len(l) - 1 >= i + 1:
    if l[i] != l[i + 1]:
        l.pop(i + 1)
        l.pop(i)
        i = max(i - 2, 0)
        continue
    i += 1
print(start - len(l))

Buggy submission (verdict: Runtime Error):
from sys import stdin

# 標準入力の受取
sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
l = list(sdi)
l.reverse()
start = len(l)
i = 0
while len(l) - 1 >= i + 1:
    print(l)
    if l[i] != l[i + 1]:
        l.pop(i + 1)
        l.pop(i)
        i = max(i - 2, 0)
        continue
    i += 1
print(start - len(l))

Buggy submission (verdict: Runtime Error):
from sys import stdin

# 標準入力の受取
sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]

l = list(sdi)
l.reverse()
start = len(l)
r = 0
i = 0
while len(l) >= i + 2:
    print(i, l)
    if l[i] != l[i + 1]:
        l.pop(i + 1)
        l.pop(i)
        print("cut", i, i+1)
        i = max(i-2, 0)
    i += 1

print(start - len(l))
Problem p03207 (python)

Fixed submission:
#!/usr/bin/env python3
# Christmas Eve Eve

N = int(input().strip())
i = 0
p = []
while i < N:
  pi = int(input().strip())
  p.append(pi)
  i += 1
p = sorted(p)
p[-1] = p[-1]/2
print(int(sum(p)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# Christmas Eve Eve

N = int(input().strip())
i = 0
p = []
while i < N:
  pi = int(input().strip())
  p.append(pi)
  i += 1
p = sorted(p)
p[-1] = p[-1]/2
print(int(sum(p))
Problem p03135 (python)

Fixed submission:
T,X = list(map(int, input().split()))
print(T/X)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K =list(map(int, input().split()))
X = input().split()
for i in range(len(X)):
    X[i] = int(X[i])
X = np.array(X)

keta = len(bin(K))-2
matrix = np.zeros(keta*N).reshape(N,keta)
i_count=0
for i in X:
    for j in range(min(len(bin(i)[2:]),keta)):
        matrix[i_count,-j-1] = bin(i)[-j-1]
    i_count+=1
    
    

tot = np.zeros(keta)
for i in range(keta):
    tot[i]=sum(matrix[:,i])

ans = np.zeros(keta)
for i in range(len(tot)):
    if int(tot[i]) < N/2:
        ans[i]=int(1)




answer = ''

for i in ans:
    answer += str(int(i))

an=int(answer,2)




ind =100
if an > K:
    cand = np.where(ans==1)[0]
    ind = -1
    
    while an > K:
        lis = list(ans)
        lis[cand[ind]] = 0
        answer = ''
        for i in lis:
            answer += str(int(i))
        lis[cand[ind]] = 1
        an=int(answer,2)
        ind -= 1
        
    ind +=1
    

j = tot
for i in range(len(j)):
    j[i] = max(j[i],N-j[i])
if ind<50:
    j[ind] = N-j[ind]

b = 0
for i in range(len(j)):
    b  += int(j[-i-1])*(2**i)
print(b)
Problem p03107 (python)

Fixed submission:
s = list(map(int, input()))
print(min(len(s)-sum(s), sum(s))*2)

Buggy submission (verdict: Runtime Error):
s = list(map(int, input()))0
print(min(len(s)-sum(s), sum(s))*2)
Problem p03127 (python)

Fixed submission:
from functools import reduce

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

n = int(input())
enemies = list(map(int,input().split()))
print(reduce(gcd, enemies))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

n = int(input())
enemies = list(map(int,input().split()))
print(reduce(math.gcd, enemies))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

n = int(input())
enemies = list(map(int,input().split()))
gcd(reduce(math.gcd, enemies))
Problem p03326 (python)

Fixed submission:
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    for msk in range(8):
        dp[i][0][msk] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(8):
    dp[0][0][i] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, i + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))
Problem p03107 (python)

Fixed submission:
s=input()
z,o=0,0
for i in range(len(s)):
  if s[i]=="0":
    z+=1
  else:
    o+=1
print(2*min(z,o))

Buggy submission (verdict: Runtime Error):
    s=input()
  	z,o=0,0
    for i in range(len(s)):
      if s[i]=="0":
        z+=1
      else:
        o+=1
    print(2*min(z,o))

Buggy submission (verdict: Runtime Error):
s=input()
for i in range(len(s)):
  if s[i]=="0":
    z+=1
  else:
    o+=1
print(2*min(0,1))
Problem p03250 (python)

Fixed submission:
import numpy as np,math,itertools

a,b,c=map(int,input().split())

print(max([10*a+b+c,a+10*b+c,a+b+10*c]))

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

a=[int(i) for i in input()]
b=a[1]
c=a[2]
d=a[0]
print(max([10*d+b+c,d+10*b+c]))
Problem p03135 (python)

Fixed submission:
T, X = list(map(int, input().split()))

print(float(T)/float(X))

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

XS = sorted(X)
XD = []
for i in range(0, len(XS)-1):
    XD.append(XS[i + 1] - XS[i])

XD2 = sorted(XD)
print(sum(XD2[:M-N]))
Problem p03805 (python)

Fixed submission:
N, M = map(int, input().split())
r = [[] * N for i in range(N)]
reached = [0] * N
reached[0] = 1
count = 0
 
def dfs(now):
    global count
    if all(reached):
        count += 1
    for next in r[now]:
        if reached[next] == 0:
            reached[next] = 1
            dfs(next)
            reached[next] = 0
 
for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    r[a].append(b)
    r[b].append(a)
 
dfs(0)
 
print(count)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)

d = [0]*n
d[0] = 1
cnt = 0


def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0


dfs(0)
print(cnt)
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)

d = [0]*n
d[0] = 1
cnt = 0


def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0


dfs(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)
 
d = [0]*n
d[0] = 1
cnt = 0
 
 
def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0
 
 
dfs(0)
print(cnt)
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)
 
d = [0]*n
d[0] = 1
cnt = 0
 
 
def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0
 
 
dfs(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)

d = [0]*n
d[0] = 1
cnt = 0


def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0


dfs(0)
print(cnt)
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)

d = [0]*n
d[0] = 1
cnt = 0


def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0


dfs(0)
print(cnt)
Problem p03775 (python)

Fixed submission:
n = int(input())
ans = 1e9
for i in range(1,int(n**0.5)+1):
  if n % i == 0:
    ans = min( ans, max( len(str(i)), len(str(n//i)) ) )
print(ans)

Buggy submission (verdict: Runtime Error):
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N = int(input())
prime_list = prime_factors(N)

X = 0
Y = 0

if prime_list:
    X = prime_list.pop(0)
    Y = prime_list.pop(-1)
    for L in prime_list:
        if X < Y:
            X = X*L
        else:
            Y = Y*L

if X >= Y:
    print(len(str(X)))
else:
    print(len(str(Y)))

Buggy submission (verdict: Runtime Error):
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N = int(input())
prime_list = prime_factors(N)
 
X = prime_list.pop(0)
Y = prime_list.pop(-1)
for L in prime_list:
    if X < Y:
        X = X*L
    else:
        Y = Y*L

if X >= Y:
    print(len(str(X)))
else:
    print(len(str(Y)))

Buggy submission (verdict: Runtime Error):
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N = input()
prime_list = prime_factors(N)

X = prime_list.pop(0)
Y = prime_list.pop(-1)
for L in prime_list:
    if X < Y:
        X = X*L
    else:
        Y = Y*L

if X >= Y:
    print(len(str(X)))
else:
    print(len(str(Y)))
Problem p03242 (python)

Fixed submission:
a=int(input())
b=str(a).replace('1','a').replace('9','b')
c=b.replace('a','9').replace('b','1')
print(int(c))

Buggy submission (verdict: Runtime Error):
a=int(input())
for i in a:
  if i ==1:
    i=9
  elif i ==9:
    i=1
  print(int(a))

Buggy submission (verdict: Runtime Error):
a=int(input())
print(a.replace(1,9).replace(9,1))

Buggy submission (verdict: Runtime Error):
print(int(input()).replace(1,9).replace(9,1))

Buggy submission (verdict: Runtime Error):
print(input().replace(1,9).replace(9,1))
Problem p03250 (python)

Fixed submission:
a = input().split()
b = [int(i) for i in a]
c=sorted(b,reverse=True)
d =10*c[0]+c[1]+c[2]
print(d)

Buggy submission (verdict: Runtime Error):
a = list(input())
b = [int(i) for i in a]
c=sorted(b,reverse=True)
d =10*c[0]+c[1]+c[2]
print(int(d))

Buggy submission (verdict: Runtime Error):
 = list(input())
b = [int(i) for i in a]
c=sorted(b,reverse=True)
d =10*c[0]+c[1]+c[2]
print(d)
Problem p03307 (python)

Fixed submission:
a=int(input())
if a%2==0:
  print(a)
else:
  print(2*a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a%2==0:
  print(a)
else:
  print(2a)
Problem p03631 (python)

Fixed submission:
a=input();print('Yes' if a[0]==a[2] else 'No')

Buggy submission (verdict: Runtime Error):
a=int(input());print('Yes' if a[0]==a[2] else 'No')
Problem p03803 (python)

Fixed submission:
x,y=map(int,input().split())
a = (x + 13) % 15
b = (y + 13) % 15
print('Alice' if a > b else 'Bob' if a < b else 'Draw')

Buggy submission (verdict: Runtime Error):
a = (int(input())+13) % 15
b = (int(input())+13) % 15

print('Alice' if a > b else 'Bob' if a < b else 'Draw')

Buggy submission (verdict: Runtime Error):
a=(int(input())+13)%15;b=(int(input())+13)%15;print('Alice' if a>b else 'Bob' if a<b else 'Draw')

Buggy submission (verdict: Runtime Error):
a,b=(map(int,input().split())+13)%15;print('Alice' if a>b else 'Bob' if a<b else 'Draw')

Buggy submission (verdict: Runtime Error):
a,b=(map(int,input().split())+13)%15;print('Alice' if a>b else 'Bob' if a<b else 'Draw)
Problem p03127 (python)

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

def gcd(l):
    ans=l[0]
    for i in l:
        ans=gcd_(ans,i)
    return ans  
  
N=int(input())
A=list(map(int,input().split()))
print(gcd(A))

Buggy submission (verdict: Runtime Error):
import math

def gcd(A):
    s=A[0]
    for i in A:
        s=math.gcd(s,i)
    return s

N=int(input())
A=list(map(int,input().split()))
print(gcd(A))
Problem p03208 (python)

Fixed submission:
import numpy as np
 
N,K=list(map(int,input().split()))
h=np.zeros(N)
for i in range(N):
    h[i]=int(input())
    
h=np.sort(h)
dh_min=10**9
for i in range(N-K+1):
    dh=h[i+K-1]-h[i]
    if dh<dh_min:
        dh_min=dh
print(int(dh_min))

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

N,K=list(map(int,input().split()))
h=np.zeros(N)
for i in range(N):
    h[i]=int(input())
    
h=np.sort(h)
h_min=10**9
for i in range(N-K+1):
    dh=h[i+K-1]-h[i]
    if dh<dh_min:
        dh_min=dh
print(dh_min)
Problem p03317 (python)

Fixed submission:
import numpy as np

def f(m,n):
    ret=m/n
    ret_=int(ret)
    if ret_==ret:
        return ret_
    else:
        return ret_+1
      
N,K=list(map(int,input().split()))
a=np.array(list(map(int,input().split())))
print(f(np.sum(a!=min(a)),K-1))

Buggy submission (verdict: Runtime Error):
def f(m,n):
    ret=m/n
    ret_=int(ret)
    if ret_==ret:
        return ret_
    else:
        return ret_+1
      
N,K=list(map(int,input().split()))
a=np.array(list(map(int,input().split())))
print(f(np.sum(a!=min(a)),K-1))
Problem p03221 (python)

Fixed submission:
import bisect

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

P = []
Y = []
PY = []
dic = {}
for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)

    dic[y] = ''

    PY.append((p,y))

PY = sorted(PY)
P  = sorted(P)
lenP = len(P)
left = 0
righ = 0
for i in range(1,N+1):

    t_list = []

    left = bisect.bisect_left(P,i,0,lenP)
    righ = bisect.bisect_right(P,i,0,lenP)

    # print(i,P)
    # print(left,righ)

    if i == P[left]:
        for j in range(left,righ):
            t_list.append(PY[j][1])
        t_list = sorted(t_list)
        for k in range(len(t_list)):
            y = t_list[k]
            dic[y] = str(i).zfill(6) + str(k+1).zfill(6)

    if lenP == righ:
        # print('break')
        break

for y in Y:
    print(dic[y])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import bisect

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

P = []
Y = []
PY = []
dic = {}
for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)

    dic[y] = ''

    PY.append((p,y))

PY = sorted(PY)
P  = sorted(P)
lenP = len(P)
left = 0
righ = 0
for i in range(1,N+1):

    t_list = []

    left = bisect.bisect_left(P,i,righ,lenP)
    righ = bisect.bisect_right(P,i,left,lenP)

    # print(i,P)
    # print(left,righ)

    if i == P[left]:
        for j in range(left,righ):
            t_list.append(PY[j][1])
        t_list = sorted(t_list)
        for k in range(len(t_list)):
            y = t_list[k]
            dic[y] = str(i).zfill(6) + str(k+1).zfill(6)

for y in Y:
    print(dic[y])
Problem p03329 (python)

Fixed submission:
import numpy as np

N = int(input())

ans = N
res = 0
for i in range(N+1):
    res = 0
    t = i
    while t > 0:
        res += t%6
        t //= 6
    t = N - i
    while t > 0:
        res += t%9
        t //= 9

    if res < ans:
        ans = res



print(ans)

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

N = int(input())

pow6 = [6]
pow9 = [9]

i=0
while pow6[i]*6 < N:
    pow6.append(6*pow6[i])
    i += 1

i=0
while pow9[i]*9 < N:
    pow9.append(9*pow9[i])
    i += 1

ans = 0
while N > 6:

    tmp_6 = [i for i in pow6 if i < N]
    tmp_9 = [i for i in pow9 if i < N]

    if tmp_9[-1] >= tmp_6[-1]:
        N -= tmp_9[-1]
    else:
        N -= tmp_6[-1]
    ans = ans + 1

ans = ans + N
print(ans)
Problem p03346 (python)

Fixed submission:
def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]

    #f1(N, P)
    editorial(N, P)


def editorial(N, P):
    """
    入力例3
        N=8
        P=63127485
         |6   7 8 |
         | 3   4 5|
         |  12    |
        上記の3つの列は要素ai+1=aiである部分列
            連続する列が長いほど、移動しなくて済む要素は多い
            連続するためには、最小未満は左・最大より大きいものは末尾に移動する
        部分列(wikipediaより)
            残った要素がもとの数列における相対的な序列を保つ
            与えられた列からいくつかの要素を取り去ることによって得られる列
    ksomemo様にお借りしました
    """
    if N == 1:
        print(0)
        return

    # WA(N, P)
    a = [0] * (N+1)
    for i, p in enumerate(P):
        a[p] = i

    tmp = 1
    max_len = 1
    for i in range(1, N):
        if a[i] < a[i+1]:
            tmp += 1
            max_len = max(max_len, tmp)
        else:
            tmp = 1
    ans = N - max_len
    print(ans)


def WA(N, P):
    tmp = 0
    ans = 0
    for i, p in enumerate(P):
        if i == 0 or P[i-1] + 1 == p:
            tmp += 1
        else:
            ans = max(ans, tmp)
            tmp = 1

    print(N - ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
P = [input() for i in range(N)]

P = list(map(int,P))

ans = 0
if N == 1:
    print(1)
    sys.exti()
err = [1]
P_lft = []
P_rgh = []
while len(err) > 0:
#    print(P)
    del err
    err = []
    del P_lft

    P_lft = P[:N//2]

    for i in P_lft:
        if i > N//2:
            err.append(i)
            P.remove(i)

    ans = ans + len(err)

    err.sort()
    P = P + err


P_lft = P[:N//2]
tmp = [int(i+1) for i in range(N//2)]

while tmp != P_lft:
    ans = ans + 1
    if P_lft[0] != 1:
        P_lft.remove(P_lft[0]-1)
        P_lft.insert(0,P_lft[0]-1)
    else:
        P_lft.remove(N//2)
        P_lft.insert(0,N//2)

del P_lft
P_lft = P[N//2:]
tmp =[]
tmp = [int(i+N//2+1) for i in range(N//2)]

while tmp != P_lft:

    ans = ans + 1
    if P_lft[-1] != N:
        P_lft.remove(P_lft[-1]+1)
        P_lft.append(P_lft[-1]+1)
    else:
        P_lft.remove(N//2+1)
        P_lft.append(P_lft[-1]+1)

print(ans)
Problem p03745 (python)

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

if N == 1:
    print(1)
    exit()
ans = 1
pm = 1

i = 0
tmp = []
while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
            if pm == 0 and A[i] != A[i-1]:
                if A[i-1] < A[i]:
                    pm = 1
                else:
                    pm = -1
        else:
            i += 1
            if N <= i:
                ans += 1
                break

            if A[i-1] == A[i]:
                pm = 0
            elif A[i-1] < A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)

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

ans = 1
pm = 1

i = 0
tmp = []
while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
            if pm == 0 and A[i] != A[i-1]:
                if A[i-1] < A[i]:
                    pm = 1
                else:
                    pm = -1
        else:
            i += 1
            if N <= i:
                ans += 1
                break

            if A[i-1] == A[i]:
                pm = 0
            elif A[i-1] < A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)

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

ans = 1
pm = 1

i = 0

while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
        else:
            i += 1
            if N <= i:
                ans += 1
                break
            if A[i-1] <= A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)
Problem p03221 (python)

Fixed submission:
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))
Problem p03127 (python)

Fixed submission:
def solve():
  def gcd(x, y):
   while(y): 
       x, y = y, x % y 
   return x

  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(i,o)
  print(o)

if __name__=="__main__":
  solve()

Buggy submission (verdict: Runtime Error):
from math import gcd

def solve(): 
  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(o,i)
  print(o)

if __name__=="__main__":
  solve()

Buggy submission (verdict: Runtime Error):
from math import gcd

N = int(input().strip())
o = 0
for i in map(int, input().split()):
	o = gcd(o,i)
print(o)
Problem p03107 (python)

Fixed submission:
S = list(input())
count_bule = S.count('0')
count_red = S.count('1')
count_min = min(count_bule, count_red)
print(2 * count_min)

Buggy submission (verdict: Runtime Error):
buffer = list(input())
S = list(map(int, buffer))
N = len(S)
i = 0
count = 0
while(1):
    if(S == [] or N == 1):
        break
    elif((S[i] + S[i + 1]) == 1):
        S.pop(i)
        S.pop(i)
        i = i - 1
        count += 2
        N = len(S)
    else:
        i += 1
        if(i == (N - 1)):
            break
print(count)
Problem p03207 (python)

Fixed submission:
N=int(input())
cnt=0
ans=0
max=0
while cnt<N:
  cnt+=1
  p=int(input())
  ans += p
  if p>max:
    max=p
ans-=int(max/2)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
cnt=0
ans=0
max=0
while cnt<N:
  cnt++
  p=int(input())
  ans += p
  if p>max:
    max=p
ans-=(max/2)
print(ans)
Problem p03107 (python)

Fixed submission:
s = input()
a = s.count('1')
b = s.count('0')
print(min(a,b)*2)

Buggy submission (verdict: Runtime Error):
s = input()
s = list(s)
i = 0
j = 0
flg =0

if len(s) >1:
    while(1):
        for i in range(len(s)+1):
            if s[i] != s[i+1]:
                s.pop(i+1)
                s.pop(i)
                j+=2
                break
            elif len(s) == 2:
                flg = 1
                break
        
        if len(s) ==0 or flg==1:
            break
        
print(j)