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

Fixed submission:
import numpy as np

def SolveNegBinary(N):
    if N == 0:
        print "0"
    else:
        r = N
        # ansTrue allocates the "True" index for -2nary expression
        ansTrue = []

        while r != 0:
            ind = (- np.sign(r) + 1)/2
            s = (-2)**ind
            while np.abs(s) < np.abs(r):
                ind +=2
                s += (-2)**ind

            ansTrue.insert(0,ind)
            r = r - (-2)**ind

        disAnswer = ""
        for k in range(ansTrue[-1] + 1)[::-1]:
            if k in ansTrue:
                disAnswer += "1"
            else:
                disAnswer += "0"


        print disAnswer
    

N = input()
SolveNegBinary(N)

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

def SolveNegBinary(N):
    r = N
    # ansTrue allocates the "True" index for -2nary expression
    ansTrue = []
    
    while r != 0:
        ind = (- np.sign(r) + 1)/2
        s = (-2)**ind
        while np.abs(s) < np.abs(r):
            ind +=2
            s += (-2)**ind

        ansTrue.insert(0,ind)
        r = r - (-2)**ind

    displayAnswer = ""
    for k in range(ansTrue[-1] + 1)[::-1]:
        if k in ansTrue:
            displayAnswer += "1"
        else:
            displayAnswer += "0"
        
    
    print displayAnswer
    

n = input()
SolveNegBinary(n)
Problem p03286 (python)

Fixed submission:
N = float(input())

if N==0:
  print(0)
else:
  q = N
  r_s = []

  while q!=1:
    hoge = (q-1) / (-2)
    if hoge.is_integer():
      r = int(1)
      q = float(hoge)
    else:
      r = int(0)
      q = float(q/(-2))
  
    r_s.append(r)
  r_s.append(1)
  r_s = r_s[::-1]

  for i in range(len(r_s)):
    print(r_s[i], end="")

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

if N==0:
  print(0)
else:
q = N
r_s = []

while q!=1:
  hoge = (q-1) / (-2)
  if hoge.is_integer():
    r = int(1)
    q = float(hoge)
  else:
    r = int(0)
    q = float(q/(-2))
  
  r_s.append(r)
r_s.append(1)
r_s = r_s[::-1]

for i in range(len(r_s)):
  print(r_s[i], end="")

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

q = N
r_s = []
while q!=1:
  hoge = (q-1) / (-2)
  if hoge.is_integer():
    r = int(1)
    q = float(hoge)
  else:
    r = int(0)
    q = float(q/(-2))
  
  r_s.append(r)
r_s = r_s.append(1)
r_s = r_s[::-1]

for i in range(len(r_s)):
  print(r_s[i], end="")

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

q = N
r_s = []
while q!=1:
  hoge = (q-1) / (-2)
  if hoge.is_integer():
    r = int(1)
    q = float(hoge)
  else:
    r = int(0)
    q = float(q/(-2))
  
  r_s = r_s.append(r)
r_s = r_s[::-1]
for i in range(r_s):
  print(i, end="")
Problem p03805 (python)

Fixed submission:
def search(node):
    global ans

    if sum(is_visit) == n:
        ans += 1

    for i in range(n):
        if is_neighbor[node][i]:
            if not is_visit[i]:
                is_visit[i] = True
                search(i)
                is_visit[i] = False

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

is_neighbor = [[False for j in range(n)] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    is_neighbor[a - 1][b - 1] = True
    is_neighbor[b - 1][a - 1] = True

is_visit = [False for _ in range(n)]

ans = 0

is_visit[0] = True
search(0)
print(ans)

Buggy submission (verdict: Runtime Error):
def search(node):
    global ans

    if sum(is_visit) == n:
        ans += 1

    for i in range(n):
        if is_neighbor[node][i]:
            if not is_visit[i]:
                is_visit[i] = True
                search(i)
                is_visit[i] = False

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

is_neighbor = [[False for j in range(n)] for i in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    is_neighbor[a - 1][b - 1] = True
    is_neighbor[b - 1][a - 1] = True

is_visit = [False for _ in range(n)]

ans = 0

is_visit[0] = True
search(0)
print(ans)
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
from math import gcd, gcd
n = int(input())
print(2*n // gcd(2,n))

Buggy submission (verdict: Runtime Error):
from math import gcd, gcd
n = int(input())
print(2*n // gcd(2,n))
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
n = int(input())
while True:
    if i % 2 == 0 and i % n == 0:
      	print(i)
        break
    i += 1

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

for i in range(n, 1e9+1):
    if i % n == 0 && i % 2 == 0:
        print(i)
        break
Problem p03835 (python)

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

counter = 0
for x in range(K + 1):
  for y in range(K + 1):
    z = S - (x + y)
    if z >= 0 and z <= K:
      counter += 1

print(counter)

Buggy submission (verdict: Runtime Error):
counter = 0
for x in range(K + 1):
  for y in range(K + 1):
    if S - (x + y) <= K:
      z = S - (x + y)
      if z >= 0 and z <= K:
        counter += 1

print(counter)
Problem p03326 (python)

Fixed submission:
from itertools import product

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

cakes = []
for _ in range(N):
    cakes.append(list(map(int, input().split())))

def _eval1(op):
    def _eval2(x):
        return eval(''.join(['{}{}'.format(op[i], x[i]) for i in range(3)]))

    return _eval2

answer = 0
for op in product('+-', repeat=3):
    answer = max(answer, sum([abs(sum([cake[j] for cake in sorted(cakes, key=_eval1(op))[:M]])) for j in range(3)]))

print(answer)

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

cakes = []  
for _ in range(N):
    cakes.append(list(map(int, input().split())))

memo = dict()

def pick_cake(picked):
    key = ','.join([str(p) for p in sorted(picked)])
    if key in memo: 
        return memo[key]

    if len(picked) == M:
        memo[key] = sum([abs(sum([cakes[i][j] for i in picked])) for j in range(3)])
        return memo[key]

    answer = 0 
    for i in range(N):
        if i in picked:
            continue
        answer = max(answer, pick_cake(picked + [i]))
    return answer

print(pick_cake([]))
Problem p03329 (python)

Fixed submission:
import sys

N = int(input())
sys.setrecursionlimit(N*10)

memo = dict()
INF = N

def withdraw(amount):
    if amount == 0:
        return 0
    if amount in memo:
        return memo[amount]

    answer = amount
    
    unit = 6
    while unit <= amount:
        answer = min(answer, withdraw(amount-unit)+1)
        unit *= 6

    unit = 9
    while unit <= amount:
        answer = min(answer, withdraw(amount-unit)+1)
        unit *= 9

    memo[amount] = answer
    return answer

print(withdraw(N))

Buggy submission (verdict: Runtime Error):
import sys 

N = int(input())
sys.setrecursionlimit(N+1)

memo = dict()
INF = N 

def withdraw(ammount):
    if ammount == 0:
        return 0
    if ammount in memo:
        return memo[ammount]

    answer = INF 
    answer = ammount

    unit = 6 
    while unit < ammount:
        answer = min(answer, withdraw(ammount-unit)+1)
        unit *= 6

    unit = 9 
    while unit < ammount:
        answer = min(answer, withdraw(ammount-unit)+1)
        unit *= 9

    memo[ammount] = answer
    return answer

print(withdraw(N))
Problem p03307 (python)

Fixed submission:
N = int(input())

if N%2 == 0:
    print(N)
else:
    print(N*2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [it - (idx + 1) for idx, it in enumerate(A)]
S = []

for b in B:
    C = [abs(i-b) for i in B]
    s = sum(C)
    S.append(s)
    
print(min(S))
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
x = input()
if x % 2 == 0:
	print(x)
else:
	print(x*2)
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
n = int(input())
i = n % 2

if i == 0:
  print(n)
else
  print(n*2)
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
l=list(map(lambda x:int(x),input().split(' ')))
l=[l[i]-(i+1) for i in range(N)]
dl=collections.Counter(l)
ans=[0]*(len(dl)//2)
for i in range(len(dl)//2):
    k=dl.most_common()[i][0] 
    k*=-1
    ans[i]=sum([abs(l[j]+k) for j in range(N)])
print(min(ans))
Problem p03835 (python)

Fixed submission:
k,s = map(int,input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-(i+j) <=k:
            count += 1
print(count)

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


count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k = S:
                count += 1
                
print(count)

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

count = 0
for i in range(K+1):
  for j in range(K+1):
    if 0 <= S-(i+j) <= K
      count += 1
print(count)

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

count = 0
for i in range(K):
  for j in range(K):
    for l in range(K):
      if i+j+l = S:
        count += 1

print(count)
Problem p03631 (python)

Fixed submission:
n = input()
if n[0] == n[2]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
if n(0) == n(2):
    print("Yes")
else:
    print("No")
Problem p03329 (python)

Fixed submission:
from itertools import count, takewhile, dropwhile
 
def dfs(n, max9, max6, d={0:0}):
    if n in d: 
      return d[n]
  
    max9 = next(dropwhile(lambda x: x>n, (max9 / 9**i for i in count())))
    max6 = next(dropwhile(lambda x: x>n, (max6 / 6**i for i in count())))
    d[n] = min(dfs(n-max9, max9, max6), dfs(n-max6, max9, max6)) + 1
    return d[n]
 
n = int(input())
 
max9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))
max6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))
 
print(dfs(n, max9, max6))

Buggy submission (verdict: Runtime Error):
def tans(N, sei):
  import math
  sin = int(math.log(N,9))
  cos = int(math.log(N,6))
  count = sei
  if ((sin != 0) and (cos != 0)):
    if N < 15:
      if N >= 12:
        count += 2
        b2 = N - 12
        return tans(b2, count)
    elif (math.pow(9, sin) > math.pow(6,cos)):
      c = int(N - math.pow(9,sin))
      count += 1
      return tans (c, count)
    else:
      c2 = int(N - math.pow(6,cos))
      count += 1
      return tans (c2, count)
  else:
    count += N
    return count

n1 = int(input())
print(tans(n1, 0))
Problem p03295 (python)

Fixed submission:
import sys

N, M = map(int, input().split())
A = [0 for i in range(N+1)]
for i in range(M):
	A1, A2 = map(int, input().split())
	if A[A1] > A2 or A[A1] == 0:
		A[A1] = A2
	
ans = 0
min_dir = sys.maxsize
for i in range(1, N+1):
	if A[i] != 0:
		min_dir = min(A[i], min_dir)
	if i >= min_dir:
		ans += 1
		if A[i] != 0:
			min_dir = A[i]
		else:
			min_dir = sys.maxsize
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
A = [0 for i in range(N+1)]
for i in range(M):
	A1, A2 = map(int, input().split())
	A[A1] = A2
	
ans = 0
min_dir = sys.maxint
for i in range(1, N+1):
	if A[i] != 0:
		min_dir = min(A[i], min_dir)
	if i >= min_dir:
		ans += 1
		if A[i] != 0:
			min_dir = A[i]
		else:
			min_dir = sys.maxint
print(ans)
Problem p03329 (python)

Fixed submission:

# coding: utf-8

# In[243]:


N = int(input())


# In[244]:


list_9 = [9]
for i in range(4):
    list_9.append(list_9[i] * 9)
    
list_6 = [6]
for i in range(5):
    list_6.append(list_6[i] * 6)


# In[245]:


amount_list = list_9 + list_6 + [1]
amount_list.sort(reverse=True)


# In[247]:


dp = [10**9] * (N+1)
dp[0] = 0


# In[248]:


for i in range(len(dp)):
    for amount in amount_list:
        if i >= amount:
            dp[i] = min(dp[i],dp[i-amount]+1)
print(dp[N])

Buggy submission (verdict: Runtime Error):

# coding: utf-8

# In[243]:


N = int(input())


# In[244]:


list_9 = [9]
for i in range(4):
    list_9.append(list_9[i] * 9)
    
list_6 = [6]
for i in range(5):
    list_6.append(list_6[i] * 6)


# In[245]:


amount_list = list_9 + list_6 + [1]
amount_list.sort(reverse=True)


# In[247]:


import math
dp = [math.inf] * (N+1)
dp[0] = 0


# In[248]:


for i in range(len(dp)):
    for amount in amount_list:
        if i >= amount:
            dp[i] = min(dp[i],dp[i-amount]+1)
print(dp[N])
Problem p03346 (python)

Fixed submission:
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


N = ii()
P = []
for _ in range(N):
    p = ii()
    P.append(p-1)

Q = [0 for i in range(N)]
for i in range(N):
    Q[P[i]] = i

maxcnt = 1
cnt = 1
for i in range(1, N):
    if Q[i] > Q[i-1]:
        cnt += 1
    else:
        cnt = 1

    maxcnt = max(maxcnt, cnt)

print(N - maxcnt)

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



def ii():
    return int(input())




def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l



N = ii()

P = lvi(N)

'''
P = []
for _ in range(N):
    p = ii()
    P.append(p -1)

print(P)
'''

#fill( Q, Q + N, 0)
Q = [0 for i in range(N)]


#print( 'Q', Q)

for i in range(1, N):
    Q[P[i - 1]] = i


maxcnt = 1
cnt = 1

print( 'Q', Q)

for i in range(1, N):
    if Q[i] > Q[i - 1]:
        cnt += 1
    else:
        cnt = 1

    maxcnt = max( maxcnt, cnt)


print(N - maxcnt)
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
l_abs = []
max_v = 0
for i, a_i in enumerate(a):
    if(max_v < a_i):
        max_v = a_i
    l_abs.append(abs((i+1)-a_i))

min = 10 ** 16
if sum(l_abs) == 0:
    min = 0
else:
    for b in range(-(max_v+1), max_v+1):
        sum = 0
        for j, a_j in enumerate(a):
            sum += abs(a_j-(b+j+1))
        if(min > sum):
            min = sum
print(min)
Problem p03332 (python)

Fixed submission:
import math
n,a,b,k = map(int, input().split())
un = 998244353
f = [0]*(n+1)
inv = [0] * (n+1)
f[0] = f[1] = 1

for i in range(2, n+1):
    f[i] = (f[i-1] * i ) % un

inv[n] = pow(f[n], un-2, un)
for i in range(n, 0, -1):
    inv[i-1] = (inv[i] * i) % un

#フェルマーの小定理の利用
def nCr(n,r):
    global f, inv
    return (f[n] * inv[r]) % un * inv[n-r] % un

total = 0
for i in range(n+1):
    if((k-a*i)%b==0):
        count_b = (k-a*i)//b
        if(count_b >= 0 and count_b <= n):
            total += nCr(n, i) * nCr(n, count_b)

print(str(total % un))

Buggy submission (verdict: Runtime Error):
import math
n,a,b,k = map(int, input().split())
un = 998244353
def combination(n,r):
    return math.factorial(n)//(math.factorial(r) * math.factorial(n-r))

total = 0
for i in range(n+1):
    if((k-a*i)%b==0):
        count_b = (k-a*i)//b
        total += combination(n, i) * combination(n, count_b)

print(str(total % un))
Problem p03307 (python)

Fixed submission:
N = int(input())

if N % 2 == 0 :
    print(N)
else :
    print(N * 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = input().split()
for i in range(len(A)) :
    A[i] = int(A[i])
print(max(A)-min(A))
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
from itertools import accumulate, islice
from bisect import bisect_left
 
n = int(input())
xs = [int(x) for x in input().split()]
 
ys = list(accumulate(xs))
zs, total = ys[:-1], ys[-1]
 
res = max(xs) - min(xs)
for i, z in islice(enumerate(zs), 1, n-1):
    j = bisect_left(zs, z//2)
    splits = ((zs[j+k], z - zs[j+k]) for k in (-1, 0, 1) if 0 <= j+k <= i)
    a, b = min(splits, key=lambda s:abs(s[0]-s[1]))
 
    j = bisect_left(zs, (total - z)//2 + z)
    splits = ((zs[j+k] - z, total - zs[j+k]) for k in (-1, 0, 1) if i <= j+k <= n-2)
    c, d = min(splits, key=lambda s:abs(s[0]-s[1]))
 
    minn, _, _, maxx = sorted((a,b,c,d))
    if maxx - minn < res:
        res = maxx - minn
 
print(res)
Problem p03329 (python)

Fixed submission:
from itertools import takewhile, chain, count
 
n = int(input())
 
def powers(a, n):
   return takewhile(lambda x: x<=n, (a**i for i in count(1)))
 
draws = sorted(set(chain([1], powers(6, n), powers(9, n))))
d = {}
for draw, last_draw in zip(draws[1:], draws):
  d[draw, 0] = 0
  for i in range(1, n+1):
    d[draw, i] = min(d.get((draw, i-draw), n)+1, d.get((last_draw, i), i))
 
print(d.get((max(draws), n), n))

Buggy submission (verdict: Runtime Error):
from itertools import takewhile, chain, count

n = int(input())

def powers(a, n):
   return takewhile(lambda x: x<=n, (a**i for i in count(1)))

draws = sorted(set(chain([1], powers(6, n), powers(9, n))))
d = {}
for draw, last_draw in zip(draws[1:], draws):
  d[draw, 0] = 0
  for i in range(1, n+1):
    d[draw, i] = min(d.get((draw, i-draw), n)+1, d.get((last_draw, i), i))

print(d[max(draws), n])
Problem p03803 (python)

Fixed submission:
a, b = [int('14' if x == '1' else x) for x in input().split()]
print('Alice' if a > b else 'Bob' if b > a else 'Draw')

Buggy submission (verdict: Runtime Error):
a, b = [int('14' if x == '1' else x) for x in input().split()
print('Alice' if a > b else 'Bob' if b > a else 'Draw')
Problem p03329 (python)

Fixed submission:
N = int(input())
ans = N
for i in range(0, N + 1, 6):
    cnt = 0
    j = N - i
    while i > 0:
        cnt += i % 6
        i //= 6
    while j > 0:
        cnt += j % 9
        j //= 9
    ans = min(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import log
# 引き出したいお金の額を入力する
N = int(input())

# 整数aの累乗のうち、整数N以下かつ最も大きいものを返す関数を定義
def func(N, a):
    index = int(log(N) / log(a))
    return a ** index

# 引き出し回数を再帰的に求める関数を定義
def search_times_re(N):
    times = 0
    if N < 6:
        times = N
        return times
    elif N < 9:
        times = 1 + (N - 6)
    else:
        N1 = search_times_re(N - func(N, 6))
        N2 = search_times_re(N - func(N, 9))
        if N1 < N2:
            return 1 + N1
        else:
            return 1 + N2

print(search_times_re(N))
Problem p03775 (python)

Fixed submission:
import numpy as np

# 整数Nを入力する
N = int(input())

# 整数A、Bの桁数のうち、大きい方を返す関数F(A, B)を定義
def F(A, B):
    C = np.vstack((A, B))
    digit_C = np.array(np.log10(C) + 1, dtype = int)
    return np.max(digit_C, axis = 0)

# 除数の配列を作成
divisor = np.arange(1, int(N ** 0.5) + 1)
# 商および余りを計算
quotient = N // divisor
residue = N % divisor

# N = A * B となるようなAおよびBの配列を作成
A = divisor[residue == 0]
B = quotient[residue == 0]

# F(A, B)の最小値を返す
print(np.min(F(A, B)))

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

# 整数Nを入力する
N = int(input())
print(N)

# 整数A、Bの桁数のうち、大きい方を返す関数F(A, B)を定義
def F(A, B):
    C = np.vstack((A, B))
    digit_C = np.array(np.log10(C) + 1, dtype = int)
    return np.max(digit_C, axis = 0)

# 被除数の配列を作成
dividend = np.ones(N) * N
# 除数の配列を作成
divisor = np.arange(1, N + 1)
# 商および余りを計算
residue = dividend % divisor

# N = A * B となるようなAおよびBの配列を作成
A = divisor[residue == 0]
B = quotient[residue == 0]

# F(A, B)の最小値を返す
print(np.min(F(A, B)))

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

# 整数Nを入力する
N = int(input())

# 整数A、Bの桁数のうち、大きい方を返す関数F(A, B)を定義
def F(A, B):
    C = np.vstack((A, B))
    digit_C = np.array(np.log10(C) + 1, dtype = int)
    return np.max(digit_C, axis = 0)

# 被除数の配列を作成
dividend = np.ones(N, dtype = int) * N
# 除数の配列を作成
divisor = np.arange(1, N + 1)
# 商および余りを計算
quotient = dividend // divisor
residue = dividend % divisor

# N = A * B となるようなAおよびBの配列を作成
A = divisor[residue == 0]
B = quotient[residue == 0]

# F(A, B)の最小値を返す
print(np.min(F(A, B)))
Problem p03307 (python)

Fixed submission:
A = int(input())

if A % 2 == 0:
    print(A)
else:
    print(A*2)

Buggy submission (verdict: Runtime Error):
import sys
import math
N = input()
AList = list(map(int, input().split()))
listnum = 1000000000

low = -1000000000
high = 1000000000

mode = 1
a1 = 0
a2 = 0
while(True):
    p1 = math.floor((abs(low) + abs(high))/3) + low
    p2 = high - math.floor((abs(low) + abs(high))/3) 

    for j in range(1,int(N)+1):
        a1 += abs(AList[j-1] -(p1 + j))
    for j in range(1,int(N)+1):
        a2 += abs(AList[j-1] -(p2 + j))

    if a1 == a2 or abs(a1-a2) == 1:
        print(min(a1,a2))
        sys.exit()
    elif a1 < a2:
        high = p2
    else:
        low = p1        
    a1 = 0
    a2 = 0
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input()
b = A.split(" ")
c = []
for i in range(0,N):
    c.append(abs(int(b[i])))
c.sort

print(c[-1]-c[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input()
b = A.split(" ")
c = []
for i in range(0,N):
    c.append(abs(int(b[i])))

c.sort

print(int(c[-1])-int(c[0]))
Problem p03315 (python)

Fixed submission:
a = 0
s = input()

for i in range(0,4):
    if s[i] == "+":
        a = a+1
    if s[i] == "-":
        a = a-1
        
print(int(a))

Buggy submission (verdict: Runtime Error):

a = 0
s = input()
n = len(S)

for i in range(0,n):
    if s[i] == "+":
        a = a+1
    if s[i] == "-":
        a = a-1
        
print(a)
Problem p03327 (python)

Fixed submission:
i = int(input())
if i <= 999:
    print("ABC")
else:
    print("ABD")

Buggy submission (verdict: Runtime Error):
c = 0
A = input()
B = A.split(" ")
a,b = int(B[0]),int(B[1])
for i in range(1,a-b):
    c = c + i
print(c - a)

Buggy submission (verdict: Runtime Error):
c = 0
a,b = map(int,input())
for i in range(1,a-b):
    c = c + i
print(a-c)
Problem p03315 (python)

Fixed submission:
S=list(input())
counter = 0
for i in range(len(S)):
    if S[i] == '+':
        counter += 1
    elif S[i] == '-':
        counter -= 1

print(counter)

Buggy submission (verdict: Runtime Error):
S=list(input())
counter = 0
for i in range(len(S):
    if S[i] == '+':
        counter += 1
    else:
        counter -= 1

print(counter)

Buggy submission (verdict: Runtime Error):
S=list(input())
counter = 0
for i in len(S):
    if S[i] == '+':
        counter += 1
    else:
        counter -= 1

print(counter)

Buggy submission (verdict: Runtime Error):
S=input()
counter = 0
for i in len(S):
    if S[i] == '+':
        counter += 1
    else:
        counter -= 1

print(counter)

Buggy submission (verdict: Runtime Error):
S=input()
counter
for i in len(S):
    if S[i] == '+':
        counter += 1
    else:
        counter -= 1

print(counter)
Problem p03307 (python)

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

def lcm(a, b):
    return int(a*b/gcd(a,b))

if __name__ == '__main__':
    r = int(input())
    print(lcm(2, r))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

def S(a, b):
    return cl[b] - (0 if a == 0 else cl[a-1])

def partial(start, end, last):
    odiff = None
    for c in range(start, end+1):
        p = S(start,c)
        q = S(c+1,end)
        diff = abs(p-q)
        if odiff is None:
            odiff = diff
        if odiff < diff:
            return c, mp, mq
        odiff = diff
        mp = p
        mq = q

if __name__ == '__main__':
    # read input
    n = int(input())
    l = list(map(int, input().split()))
    # create cumlative list first
    cl = list(accumulate(l))
    clen = len(l)

    #  0  F(i)      i i+1 G(i)      len-1
    #  |------|------|-------|-------|
    #         c0    c1       c2
    #  <-----L------> <------R------->
    # pick up a c1 (i:i+1) and evaluate
    result = None
    c1 = 1
    c3 = 3
    for i in range(1,clen-2):
        # LEFT
        (c1, mb, mc) = partial(0, i, c1)
        # RIGHT
        c3, md, me = partial(i+1, clen-1, c3)

        # evaluate
        diff = abs(max(mb, mc, md, me) - min(mb, mc, md, me))
        if result is None:
            result = diff
        else:
            if result > diff:
                result = diff

    print(result)