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

Fixed submission:
n = int(input())
march_l = [0]*5
for _ in range(n):
    s = input()
    s0 = s[0]
    if s0 == 'M':
        march_l[0] += 1
    elif s0 == 'A':
        march_l[1] += 1
    elif s0 == 'R':
        march_l[2] += 1
    elif s0 == 'C':
        march_l[3] += 1
    elif s0 == 'H':
        march_l[4] += 1

cnt =  [i for i in march_l if i != 0]
len_cnt = len(cnt)
ans = 0

if len_cnt > 3:
    for i in range(2**len_cnt):
        tmp = 1
        if str(bin(i)).count('1') == 3:
            for j in range(len_cnt):
                if ((i>>j) & 1):
                    tmp *= cnt[j]
            ans += tmp
elif len_cnt == 3:
    ans = 1
    for i in cnt:
        ans *= i
        
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
march_l = [0]*5
for _ in range(n):
    s = input()
    s0 = s[0]
    if s0 == 'M':
        march_l[0] += 1
    elif s0 == 'A':
        march_l[1] += 1
    elif s0 == 'R':
        march_l[2] += 1
    elif s0 == 'C':
        march_l[3] += 1
    elif s0 == 'H':
        march_l[4] += 1

cnt =  [i for i in march_l if i != 0]
len_cnt = len(cnt)

if len_cnt > 3:
    for i in range(2**len_cnt):
        tmp = 1
        if str(bin(i)).count('1') == 3:
            for j in range(len_cnt):
                if ((i>>j) & 1):
                    tmp *= cnt[j]
            ans += tmp
elif len_cnt == 3:
    ans = 1
    for i in cnt:
        ans *= i
else:
    ans = 0

print(ans)
Problem p03427 (python)

Fixed submission:
n = input()
int_n = int(n)
len_n = len(n)
ans = sum([int(i) for i in n])

for i in range(len_n):
    target = int(n[:i+1][-1]) -1
    if target < 0:
        continue
    tmp_n = n[:i] + str(target) + '9'* (len_n - i - 1)
    tmp_n_ans = sum([int(i) for i in tmp_n])
    ans = max(tmp_n_ans, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
int_n = int(n)
len_n = len(n)
ans = 0

if n[0] == '1' and n[1:] == '0'*(len_n-1):
    print(9 * (len_n - 1))
    exit()

for i in range(len_n):
    target = int(n[:i+1][-1]) -1
    tmp_n = n[:i] + str(target) + '9'* (len_n - i - 1)
    tmp_n_ans = sum([int(i) for i in tmp_n])
    ans = max(tmp_n_ans, ans)
print(ans)
Problem p03544 (python)

Fixed submission:
n = int(input())
l_2 = 2
l_1 = 1
l_now = 1

for _ in range(1,n):
  l_now = l_1 + l_2
  l_2 = l_1
  l_1 = l_now
print(l_now)

Buggy submission (verdict: Runtime Error):
n = int(input())
l_2 = 2
l_1 = 1

for _ in range(1,n):
  l_now = l_1 + l_2
  l_2 = l_1
  l_1 = l_now
print(l_now)
Problem p03605 (python)

Fixed submission:
n=input()
if '9' in n:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n=input()
if ′9′ in n:
  print(′Yes′)
else:
  print(′No′)
Problem p03633 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

n = int(input())

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

t = set()
for _ in range(n):
    t.add(int(input()))

print(lcm_list(t))

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

n = int(input())

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

t = set()
for _ in range(n):
    t.add(int(input()))

print(lcm_list(t))
Problem p03777 (python)

Fixed submission:
a,b = input().split()
if a == 'H':
  print(b)
else:
  print('HD'.replace(b,''))

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
if a == 'H':
  print(b)
else:
  print('HD'.replace(b,''))
Problem p03160 (python)

Fixed submission:
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

def fun(A,N):
    dp = [0]*N
    for pos in range(N):
        if pos == 0:
            dp[pos] = 0
        elif pos == 1:
            dp[pos]  = abs(A[pos-1] - A[pos])
        else:
            dp[pos]= min(abs(A[pos] - A[pos-1]) + dp[pos-1], abs(A[pos] - A[pos-2]) + dp[pos-2])
    return dp[-1]

N = int(input())
A = alele()
print(fun(A,N))

Buggy submission (verdict: Runtime Error):
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

def fun(A,N,dp,pos= 0):
    if pos == N-1:
        return 0
    elif pos == N-2:
        return abs(A[N-1] - A[N-2])
    if dp.get(pos,-1) != -1:
        return dp[pos]
    else:
        dp[pos]= min(abs(A[pos] - A[pos+1]) + fun(A,N,dp,pos+1), abs(A[pos] - A[pos+2]) + fun(A,N,dp,pos+2))
        return dp[pos]
    
dp = {}
N = int(input())
A = alele()
print(fun(A,N,dp))
Problem p03165 (python)

Fixed submission:
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])
      
def fun(A,B,m,n,dp):
    for i in range(1,m+1):
        for j in range(1,n+1):
            if A[i-1] == B[j-1]:
                dp[i][j] = 1 + dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i][j-1],dp[i-1][j])
    return dp
                
def longestsub(A,B):
    m = len(A)
    n = len(B)
    if m==0 or n==0:
        return ""
    temp = [0]*(n+1)
    dp = [temp.copy() for i in range(m+1)]
    d = fun(A,B,m,n,dp)
    i= m;j = n;Ans = ""
    while i>0 and j>0:
        if A[i-1] == B[j-1]:
            Ans += A[i-1]
            i-=1;j-=1
        else:
            a = d[i][j-1] ; b =d[i-1][j]
            if a > b:
                j-=1
            else:
                i-=1
    return Ans[::-1]

A = input()
B = input()
print(longestsub(A,B))

Buggy submission (verdict: Runtime Error):
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])
      
def fun(S1,S2,n,m,dp):
    if n == 0 or m == 0:
        return ""
    if dp.get((n,m),-1) != -1:
        return dp[(n,m)]
    else:
        if S1[n-1] == S2[m-1]:
            dp[(n,m)] =  S1[n-1] + fun(S1,S2,n-1,m-1,dp)
        else:
            a = fun(S1,S2,n-1,m,dp)
            b= fun(S1,S2,n,m-1,dp)
            if len(a) > len(b):
                dp[(n,m)] = a
            else:
                dp[(n,m)] = b
        return dp[(n,m)]

S1 = input()
S2 = input()
n = len(S1)
m = len(S2)
s = ""
dp = {}
print(fun(S1,S2,n,m,dp)[::-1])
Problem p02606 (python)

Fixed submission:
def main():
    l, r, d = map(int, input().split(' '))
    count = 0
    for i in range(l, r + 1):
        if i % d == 0:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
l, r, d = map(int, input().split(' '))
count = 0
for i range(l, r + 1):
  if i % d == 0:
    count += 1
print(count)
Problem p02603 (python)

Fixed submission:
n = int(input())
a = list(map(int, (input().split())))
a.append(0)
mon = 1000
kab = 0
x = 0
for i in range(n):
    if a[i] <= a[i+1]:
        kab = mon//a[i]
        mon += kab*(a[i+1]-a[i])
print(mon)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, (input().split())))
a.append(0)
mon = 1000
kab = 0
x = 0
z = 0
while z <= n-1:
    if x == 0:
        while a[z+1] < a[z]:
            z += 1
            if z == n-1:
                break
        kab += mon//a[z]
        ans = mon
        mon -= kab*a[z]
        x = 1
        if z < n-1:
            z += 1
        else:
            break
    elif x == 1:
        while a[z+1] > a[z]:
            z += 1
            if z == n-1:
                break
        mon += kab*a[z]
        kab = 0
        x = 0
        if z < n-1:
            z += 1
        else:
            break
print(max(ans, mon))
Problem p02646 (python)

Fixed submission:
a, v= map(int, input().split())
b, w= map(int, input().split())
t = int(input())
l = abs(b-a)
s = v-w
print('YES' if l<=s*t else 'NO')

Buggy submission (verdict: Runtime Error):
a, v= map(int, input().split())
b, w= map(int, input().split())
t = int(input())
l = b-a
s = v-w

    print('YES' if l<=s*t else 'NO')
Problem p02658 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [i for i in a if i != 1]
ans = 1
if len(b) < 100:
    for i in range(len(b)):
        ans *= b[i]
else:
    ans = 10**18+1
if 0 in b:
    ans = 0
print(ans if ans <= 10**18 else '-1')

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = list(map(float, input().split()))
ans = int(np.prod(a))
print(ans if ans <= 10**18 else '-1')
Problem p02660 (python)

Fixed submission:
n = int(input())
b = n
def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
l = list(set(pf(n)))
cnt = 0
for i in l:
    n = b
    t = 1
    j = i
    while i <= n:
        if n % i == 0:
            cnt += 1
            n = n // i
        i *= j
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
b = n
def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
l = list(set(pf(n)))
cnt = 0
for i in l:
    n = b
    t = 1
    j = i
    while i <= n:
        if n % i == 0:
            cnt += 1
            n = n // i
            a.append(i)
        i *= j
print(cnt)
Problem p02812 (python)

Fixed submission:
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
cnt = 0
for i in range(n):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        cnt += 1
print(cnt)
Problem p02817 (python)

Fixed submission:
s, t = input().split()
print(t+s)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
if a >= k:
    a -= k
elif a < k and a + b >= k:
    b = b - (k-a)
    a = 0
else:
    a = 0
    b = 0
print(a, b)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
if a >= k:
    a -= k
elif a + b >= k:
    b = b - (k-a)
    a = 0
else:
    a = 0
    b = 0
print(a, b)
Problem p03645 (python)

Fixed submission:
n, m = map(int, input().split())
c = [[] for _ in range(n+1)]
for i in range(m):
  a, b = map(int, input().split())
  c[a].append(b)
  c[b].append(a)

for i in c[1]:
  if n in c[i]:
    print('POSSIBLE')
    exit()

print('IMPOSSIBLE')

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

for i in c[1]:
  if n in c[i]:
    print('POSSIBLE')
    exit()

print('IMPOSSIBLE')
Problem p02724 (python)

Fixed submission:
import math
a=int(input())
n = math.floor(a/500)
m = math.floor((a - n * 500)/5)
total_price= n * 1000 + m*5
print(total_price)

Buggy submission (verdict: Runtime Error):
a=int(input())
n = math.floor(a/500)
total_price= n * 1000 + (a - n * 500)
print(total_price)
Problem p02789 (python)

Fixed submission:
n = input()
(p,q) = n.split()
a='Yes'
b='No'
if p == q:
    print(a)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = map(int, input().split())
b_list = list(b)
count = 0
for i in range(len(b_list)):
    if b_list[i] == min(b_list[:i+1]):
        count += 1
        
print(count)
Problem p02813 (python)

Fixed submission:
import math
n = int(input())
def pos_num(l):
    l_sort = l.copy()
    l_len = len(l)
    l_sort.sort()
    if l_len == 1:
        an = 0
    else:
        #print(l_sort.index(l[0])+1)
        an = (l_sort.index(l[0]))*math.factorial(l_len-1)
    #print(an)
    return an 

    

ls = list(map(int, input().split()))
an = 0
for i in range(n-1):
    b = pos_num(ls[i:])
    an += b
    #print(an)
    

ll = list(map(int, input().split()))
bn = 0
for i in range(n-1):
    b = pos_num(ll[i:])
    bn += b
    #print(bn)

print(abs(an-bn))

Buggy submission (verdict: Runtime Error):
n = int(input())
def pos_num(l):
    l_sort = l.copy()
    l_len = len(l)
    l_sort.sort()
    if l_len == 1:
        an = 0
    else:
        #print(l_sort.index(l[0])+1)
        an = (l_sort.index(l[0]))*math.factorial(l_len-1)
    #print(an)
    return an 

    

ls = list(map(int, input().split()))
an = 0
for i in range(n-1):
    b = pos_num(ls[i:])
    an += b
    #print(an)
    
print()
ll = list(map(int, input().split()))
bn = 0
for i in range(n-1):
    b = pos_num(ll[i:])
    bn += b
    #print(bn)

print(abs(an-bn))
Problem p02837 (python)

Fixed submission:
n = int(input())
ls = [0]*n
param_list = [0]*2**n
for i in range(2**n):
    l = [False]*n
    for id_r, row in enumerate(ls):
        if i & (2 ** id_r) >0:
            l[id_r] = True
    param_list[i] = l 


for i in range(n):
    A = int(input())
    for k in range(A):
        a,b = map(int, input().split())
        b = (1==b)
        new_param =[]
        for d in param_list:
            if d[i]:
                if d[a-1] == b:
                    new_param.append(d)
                    pass
                else:
                    #print(2)
                    pass
            else:
                new_param.append(d)
                #if d[a-1] is b:
                    #print(3)
                    #pass
                #else:
                    #print(4)
                    #new_param.append(d)
                    #pass
            
        param_list = new_param
        #print(param_list)
            
ans = 0    
for d in param_list:
    ans = max(ans, d.count(True))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ls = [0]*n
param_list = [0]*2**n
for i in range(2**n):
    l = [False]*n
    for id_r, row in enumerate(ls):
        if i & (2 ** id_r) >0:
            l[id_r] = True
    param_list[i] = l 
#1print(param_list)
"""
for i in range(2**(n-1)):
    l = [True]+[False]*(n-1)
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i+2**(n-1)] = l 
print()
print(len(param_list))
print(param_list)
a_list = get_unique_list(param_list)
print(len(a_list))
print(a_list)"""

for i in range(n):
    A = int(input())
    for k in range(A):
        a,b = map(int, input().split())
        b = (1==b)
        new_param =[]
        for d in a_list:
            if d[i]:
                if d[a-1] == b:
                    new_param.append(d)
                    pass
                else:
                    #print(2)
                    pass
            else:
                new_param.append(d)
                #if d[a-1] is b:
                    #print(3)
                    #pass
                #else:
                    #print(4)
                    #new_param.append(d)
                    #pass
            
        param_list = new_param
        #print(param_list)
            
ans = 0    
for d in param_list:
    ans = max(ans, d.count(True))
print(ans)
Problem p02922 (python)

Fixed submission:
import math
p,q= input().split()
a,b =(int(p), int(q))
count = 1

for i in range(math.floor((b/a)**2 + 4)):
    if count < b:
        count += a -1
    else:
        print(i)
        ans = i
        break

Buggy submission (verdict: Runtime Error):
import math
p,q= input().split()
a,b =(int(p), int(q))
count = 1

for i in range(math.floor(b/a  + 4)):
    if count < b:
        count += a -1
    else:
        ans = i
        break

print(ans)
Problem p02995 (python)

Fixed submission:
import math
a,b,c,d=list(map(int,input().split()))
a-=1
def calculation(x,c,d):
	x=x-(x//c)-(x//d)+(x//((c*d)//math.gcd(c,d)))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))

Buggy submission (verdict: Runtime Error):
from math
a,b,c,d=list(map(int,input().split()))
a-=1
def calculation(x,c,d):
	x=x-(x//c)-(x//d)+(x//((c*d)//math.gcd(c,d)))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))
Problem p03059 (python)

Fixed submission:
import math 

a,b,c= input().split()
x,y,z=(int(a),int(b),int(c))
p = math.floor(z / x)
print(int(p * y))

Buggy submission (verdict: Runtime Error):
mport math 

a,b,c= input().split()
x,y,z=(int(a),int(b),int(c))
p = math.floor(z / x)
print(int(p * y))
Problem p03086 (python)

Fixed submission:
a = input()
check = 'ACGT'
ans_list = []
for p in range(len(a)):
    for q in range(len(a)-1):
        
        count = 0
        for r in range(len(a[p:len(a)-q])):
            
            if a[p:len(a)-q][r] in check:
                count += 1
                if count == len(a[p:len(a)-q]):
                    ans_list.append(a[p:len(a)-q])
                    break
ls =[]
for i in range(len(ans_list)):
    ls.append(len(ans_list[i]))
if len(ls) == 0:
    if a[0] in check:
        print(1)
    else:
        print(0)
else:
    print(max(ls))

Buggy submission (verdict: Runtime Error):
a = input()
check = 'ACGT'
ans_list = []
for p in range(len(a)):
    for q in range(len(a)-1):
        
        count = 0
        for r in range(len(a[p:len(a)-q])):
            
            if a[p:len(a)-q][r] in check:
                count += 1
                if count == len(a[p:len(a)-q]):
                    ans_list.append(a[p:len(a)-q])
                    
                    break
ls =[]
for i in range(len(ans_list)):
    ls.append(len(ans_list[i]))

print(max(ls))
Problem p03087 (python)

Fixed submission:

n,q = list(map(int, input().split()))
s = input()
ans = [0]*(n+1)
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(1,n):
    
    if s[i-1]=='A' and s[i]=='C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1]= ans[i]
#print(ans)
for i in range(q):
    print(ans[lr[i][1]]-ans[lr[i][0]])

Buggy submission (verdict: Runtime Error):
n,q = list(map(int, input().split()))
s = input()
s_ps=[]

a =s[0]
for i in range(n):
    b = a
    a = s[i]
    if b+a=='AC':
        s_ps.append(i)
#print(s_ps)
len_s = len(s_ps)


for _ in range(q):
    l,r=list(map(int, input().split()))
    count =0
    for i in s_ps:
        if l<=i:
            low =i
            break
    for i in s_ps[::-1]:
        if i < r:
            high=i
            break
    print(s_ps.index(high)-s_ps.index(low)+1)
Problem p03273 (python)

Fixed submission:
p,q= input().split()
a,b =(int(p), int(q))
a_list = []
count_row = 0
b_h ='.'*b

for i in range(a):
    c = input()
    
    if c == b_h:
        count_row+=1
    else:
        a_list.append(c)

ans_list=[]
for i in range(b):
    count_clm = 0
    
    for j in range(a-count_row):
        if a_list[j][i] == '.':
            count_clm+=1
    
    
        if count_clm == (a-count_row):        
            ans_list.append(i)



for j in range(a-count_row):
    total=''
    for i in range(b):
        if i in ans_list:
            ds = 0
        else:
            total +=a_list[j][i]
            
    print(total)

Buggy submission (verdict: Runtime Error):
p,q= input().split()
a,b =(int(p), int(q))
a_list = []
count_row = 0
for i in range(a):
    c = input()
    
    if c == '.'*b:
        count_row+=1
    else:
        a_list.append(c)
for i in range(b):
    count_clm = 0
    
    for j in range(a-count):
        if a_list[j][i] == '.':
            count_clm+=1
        else:
            break
    if count_clm == (b-count_clm):
        for j in range(a-count_row):
            a_list[j].pop(i)
            
            
for i in range(a-count_row):
    print(a_list[i])
Problem p03274 (python)

Fixed submission:
n,k= list(map(int,input().split()))
pos= list(map(int,input().split()))
ans = 10**13
for i in range(n-k+1):
    a1 = abs(pos[i]) + abs(pos[i] - pos[i+k-1])
    a2 = abs(pos[i+k-1]) + abs(pos[i] - pos[i+k-1])
    ans = min(ans, a1,a2)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k= list(map(int,input().split()))
pos= list(map(int,input().split()))
pos_abs =list(map(abs, pos))
pos_abs.sort()
#print(pos_abs)
ls = pos_abs[:k]
high = 0
low = 0
count =0
for a in ls[::-1]:
    if a in pos and high == 0:
        high = a
        count += 1
    elif a not in pos and low ==0:
        low = a
        count += 1
        
    if count == 2:
        break 
if low ==0 and ls.count(ls[-2])==2:
    low = ls[-2]
#print(high,low)
if high >=low:
    print(high+ low*2)
else:
    print(high*2+low)
Problem p03294 (python)

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

print(sum(ans)-n)

Buggy submission (verdict: Runtime Error):
#最小公倍数でループ
import math
n = int(input())
ans = list(map(int,input().split()))
lcm = ans[0]
for k in ans:
    gcd = math.gcd(lcm, k)
    lcm = round(lcm*k/gcd)
    print(lcm)


an =0
for k in ans:
    an += (lcm-1)%k
        
print(an)

Buggy submission (verdict: Runtime Error):
#最小公倍数でループ
import math
n = int(input())
ans = list(map(int,input().split()))
lcm = ans[0]
for k in ans:
    gcd = math.gcd(lcm, k)
    lcm = int(lcm*k/gcd)
#print(lcm)

an =0
for k in ans:
    an += (lcm-1)%k
        
print(an)
Problem p03309 (python)

Fixed submission:
import math
n = int(input())
ls = list(map(int,input().split()))
bs = [ls[i]-i-1 for i in range(n)]
bs.sort()
#print(bs)
if n %2 ==0:
    a = round(n/2)
    #print(a)
    can = [bs[a],bs[a-1],math.floor((bs[a] +bs[a-1])/2),math.ceil((bs[a] +bs[a-1])/2)]
elif n ==1:
    can = [bs[0],bs[0]]
else:
    a = math.floor(n/2)
    #print(a)
    can = [bs[a+1],bs[a-1],bs[a]]

#print(can)
result = 10**27
for k in can:
    ans =0
    for kn in bs:
        ans += abs(kn-k)
    #print(ans)
    result = min(result, ans)
    
print(result)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ls = list(map(int,input().split()))
bs = [ls[i]-i-1 for i in range(n)]
bs.sort()

if n %2 ==0:
    a = int(n/2)
    can = [bs[a],bs[a-1],bs[a+1]]
else:
    a = math.floor(n/2)
    can = [bs[a], bs[a+1],bs[a-1]]

#print(can)
result = 10**10
for k in can:
    ans =0
    for kn in bs:
        ans += abs(kn-k)
    
    result = min(result, ans)
print(result)
Problem p02642 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

A = set(A)
MAX_A = 10 ** 6
X = [0] * (MAX_A + 1)
for a in A:
    for i in range(a, MAX_A + 1, a):
        X[i] += 1

ans = len([a for a in A if (X[a] == 1) and (C[a] == 1)])
print(ans)

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

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

C=Counter(A)

A=set(A)

MAX_A=10**6

X=[0]*(MAX_A+1)

for a in A:
    for i in range(a,MAX_A+1,a):
        X[i]+=1

ans=len([a for a in A if (X[1]==1) and (C[a]==1)])

print(ans)