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

Fixed submission:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
e_most = e_counter.most_common()
o_most = o_counter.most_common()
E1 = e_most[0][0]
E2 = E1
if len(e_most) > 1:
    E2 = e_most[1][0]
O1 = o_most[0][0]
O2 = O1
if len(o_most) > 1:
    O2 = o_most[1][0]
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    if e[0] == o[0]:
        print(n // 2)
    else:
        print(0)
else:
    if E1 != O1:
        print(e_cnt + o_cnt)
    else:
        if E1 == O2:
            e_cnt = n // 2 - e.count(E2)
            print(e_cnt + o_cnt)
        elif E2 == O1:
            o_cnt = n // 2 - o.count(O2)
            print(e_cnt + o_cnt)
        else:
            cnt1 = n // 2 - e.count(E2) + o_cnt
            cnt2 = e_cnt + n // 2 - o.count(O2)
            print(min(cnt1, cnt2))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
e_cnt = n // 2 - max(e.count(E1))
o_cnt = n // 2 - max(o.count(O1))
if e_cnt == 0 and o_cnt == 0:
    print(0)
else:
    print(e_cnt + o_cnt)
Problem p03416 (python)

Fixed submission:
a, b = map(int, input().split())

res = 0
for i in range(a, b + 1):
    i_str = str(i)
    if i_str == i_str[::-1]:
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())

res = 0
for i in range(a, b + 1):
    i_str = str(i)
    if i_str == i_str[::-1]:
        res += 1
print(res)
Problem p03544 (python)

Fixed submission:
n = int(input())

l = [2, 1]
for i in range(2, n+1):
    l.append(l[i - 2] + l[i - 1])
print(l[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
l0 = 2
l1 = 1
if n == 0:
    print(l0)
    return
if n == 1:
    print(l1)
    return

l_prev = l0
l_next = l1

i = 2
while True:
    l_new = l_prev + l_next
    if n == i:
        print(l_new)
        break
    l_prev = l_next
    l_next = l_new
    i += 1

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

l_prev = l0
l_next = l1

l_new = 0
for i in range(2, n+1):
    l_new = l_prev + l_next
    l_prev = l_next
    l_next = l_new
print(l_new)

Buggy submission (verdict: Runtime Error):
n = long(input())
l0 = 2L
l1 = 1L
if n == 0:
    print(l0)
if n == 1:
    print(l1)

l_prev = l0
l_next = l1

l_new = 0L
for i in range(2, n+1):
    l_new = l_prev + l_next
    l_prev = l_next
    l_next = l_new
print(l_new)
Problem p02924 (python)

Fixed submission:
n = int(input())-1
print(int(n*(n+1)//2))

Buggy submission (verdict: Runtime Error):
n = int(input())
print(sum(list(range(n))))
Problem p02947 (python)

Fixed submission:
N = int(input())
s = []
ans = 0
mydict = {}
for i in range(N):
    s = "".join(sorted(list(input())))
    if (s in mydict.keys()):
        ans += mydict[s]
        mydict[s] += 1
    else:
        mydict[s] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
    s.append(sorted(list(input())))

ans = 0
for i in range(N):
    for j in range(N):
        if not i == j:
            if (si == sj):
                ans += 1
print(int(ans/2))
Problem p03071 (python)

Fixed submission:
a, b = map(int, input().split())
c, d = a-1, b-1
l = sorted([a,b,c,d])[::-1]
print(l[0]+l[1])

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c, d = a-1, b-1
l = sorted[a,b,c,d][::-1]
print(l[0]+l[1])
Problem p03408 (python)

Fixed submission:
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
l=list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))

Buggy submission (verdict: Runtime Error):
s = [input() for _ in range(int(input()))]
t = [input() for _ in range(int(input()))]
ls = list(set(s))
temp=0
for l in ls:
    ans=0
    ans += 1 for ss in s if ss == l
    ans -= 1 for tt in t if tt == l
    temp = max(temp, ans)
print(temp)

Buggy submission (verdict: Runtime Error):
s = [input() for _ in range(int(input()))]
t = [input() for _ in range(int(input()))]
ls = list(set(s))
temp=0
for l in ls:
    ans=0
    ans += 1 for ss in s if ss == l
    ans -= 1 for tt in t if tt == l
    temp = ans if ans>temp
print(temp)

Buggy submission (verdict: Runtime Error):
s = [input() for _ in range(int(input()))]
t = [input() for _ in range(int(input()))]
ls = list(set(s))
temp=0
for l in ls:
    ans=0
    ans += 1 for ss in s if l == ss
    ans-=1 for tt in t if tt == l
    temp = ans if ans>temp
print(temp)

Buggy submission (verdict: Runtime Error):
s = [input() for _ in range(int(input()))]
t = [input() for _ in range(int(input()))]
ls = set(s)
temp=0
for l in ls:
    ans=0
    ans += 1 for ss in s if l == ss
    ans-=1 for tt in t if tt == l
    temp = ans if ans>temp
print(temp)

Buggy submission (verdict: Runtime Error):
s = [input() for _ in range(input())]
t = [input() for _ in range(input())]
ls = set(s)
ans=0
temp=0
for l in ls:
    for ss in s:
      ans += 1if l == ss
    ans-=1for tt in t if tt == l
    temp = ans if ans>temp
print(temp)
Problem p03860 (python)

Fixed submission:
print("A"+input()[8]+"C")

Buggy submission (verdict: Runtime Error):
print("A"+{input()[8]}+"C")

Buggy submission (verdict: Runtime Error):
print(f"A{input()[8]}C")
Problem p03998 (python)

Fixed submission:
a = list(input())
b = list(input())
c = list(input())
s = a.pop(0)
ans = "a"
while 1:
    if s == "a":
        if a: s = a.pop(0)
        else: break
    elif s=="b":
        if b: s = b.pop(0)
        else: break
    else:
        if c: s = c.pop(0)
        else: break
print(s.upper())

Buggy submission (verdict: Runtime Error):
S = {i:list(input()) for i in "abc"}
while S[s]: s=S[s].pop(0)
print(s.upper())
Problem p02952 (python)

Fixed submission:
n = int(input())

if(n <= 9):
    print(n)

elif(n <= 99):
    print(9)

elif(n <= 999):
    print(n - 90)

elif(n <= 9999):
    print(909)

elif(n <= 99999):
    print(n - 9090)

else:
    print(90909)

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

if(n <= 9):
    print n

elif(n <= 99):
    print 9

elif(n <= 999):
    print (n - 90)

elif(n <= 9999):
    print 909

elif(n <= 99999):
    print (n - 9090)

else:
    print 90909

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

if(n <= 9):
    return n

elif(n <= 99):
    return 9

elif(n <= 999):
    return (n - 90)

elif(n <= 9999):
    return 909

elif(n <= 99999):
    return (n - 9090)

else:
    return 90909
Problem p02945 (python)

Fixed submission:
a,b = map(int, input().split())
ans = max(a+b,a-b,a*b)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
arr = np.array([[1,2,3],
                [1,2,3],
                [1,2,2]])
uniq, cnt = np.unique(arr, return_counts=True, axis=0)

a,b = map(int, input().split())
ans = max(a+b,a-b,a*b)
print(ans)
Problem p03037 (python)

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

a_max = -1
b_min = 999999999999999

for i in range(m):
    a, b = map(int, input().split())
    
    a_max = max(a_max, a)
    b_min = min(b_min, b)

ans = max(b_min - a_max + 1, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m  = map(int, input().split())

cards = np.array([])
for i in range(m):
    a, b = map(int, input().split())
    cards = np.append(cards, np.arange(a, b+1))
    
count = np.unique(cards, return_counts=True)
ans = sum(count[1] == m)
print(ans)
Problem p03047 (python)

Fixed submission:
n, k = map(int, input().split())
print(n-k+1)

Buggy submission (verdict: Runtime Error):
# BA=0, B=0, A=0, 0
# BA=2, B=0, A=0, 1
# BA=0, B=1, A=0, 0
# BA=0, B=0, A=1, 0
# BA=2, B=1, A=0, 2
# BA=2, B=0, A=1, 2
# BA=2, B=1, A=1, 2

n = int(input())
 
ans = 0
A = 0
B = 0
AB = 0
for _ in range(n):
    s = input()
    ans += s.count('AB')
    
    if s[-1] == 'A' and s[0] != 'B':
        A += 1 
    if s[0] == 'B' and s[-1] != 'A':
        B += 1
    if s[-1] == 'A' and s[0] == 'B':
        AB += 1
    
ans += min(A+AB, B+AB)


if AB>0 and A+B==0:
    ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
 
ans = 0
A = 0
B = 0
AB = 0
for _ in range(n):
    s = input()
    ans += s.count('AB')
    
    if s[-1] == 'A' and s[0] != 'B':
        A += 1 
    if s[0] == 'B' and s[-1] != 'A':
        B += 1
    if s[-1] == 'A' and s[0] == 'B':
        AB += 1
    
ans += min(A+AB, B+AB)


if AB>0 and A==0 and B==0:
    ans -= 1

print(ans)
Problem p03074 (python)

Fixed submission:
import numpy as np

n, k = list(map(int, input().split()))
s = str(input())

arr0 = np.array(list(map(len, s.split('1'))))
arr0 = arr0[arr0!=0]

arr1 = np.array(list(map(len, s.split('0'))))
arr1 = arr1[arr1!=0]


ans = 0

if s[0] == '0':
    for i in range(len(arr0)):
        
        if i == 0:
            length = arr0[i:i+k].sum() + arr1[i:i+k].sum()
        else:
            length = arr0[i:i+k].sum() + arr1[i-1:i+k].sum()
        ans = max(ans, length)
        
        if i+k > len(arr0):
            break
        
        
else:        
    for i in range(len(arr0)):
        
        
        length = arr0[i:i+k].sum() + arr1[i:i+k+1].sum()
        ans = max(ans, length)
        
        if i+k > len(arr0):
            break
        
        

if len(s) == s.count('1'):
    print(len(s))
else:
    print(ans)

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

now = 1
cnt = 0
li = []

# 1-0-1-0-1-0-..... を準備
for i in range(n):
    if s[i] == str(now):
        cnt += 1
    else:
        li.append(cnt)
        now = 1 - now
        cnt = 1
        
if len(li)%2 == 0:
    li.append(cnt)

ans = -1
for i in range(n):
    left = 2*i
    right = 2*i + 2*k + 1
    length = sum(li[left:right])
    ans = max(ans, length)
    
    if end >= len(li):
        break

print(ans)
Problem p03076 (python)

Fixed submission:
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())



ans = 0
for i in [a, b, c, d, e]:
    ans += int(math.ceil(i/10)*10)

    
li = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]

if li == [0, 0, 0, 0, 0]:
    ans = ans + min(li)
    print(ans)
    
else:
    for j in li:
        if j==0:
            li.remove(0)
    ans = ans + min(li) - 10
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())



ans = 0
for i in [a, b, c, d, e]:
    ans += int(math.ceil(i/10)*10)

li = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]
while 0 in li:
    li.remove(0)

ans = ans + min(li) - 10
    
print(ans)
Problem p03078 (python)

Fixed submission:
x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ABC = []
for x, a in enumerate(A):
    if x+1 > 3000:
        break
        
    for y, b in enumerate(B):
        if (x+1)*(y+1) > 3000:
            break
    
        for z, c in enumerate(C):
            if (x+1)*(y+1)*(z+1) > 3000:
                break
            
            ABC.append(a+b+c)
            
ABC.sort(reverse=True)
ABC = ABC[:k]

for abc in ABC:
    print(abc)

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

x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AA, BB = np.meshgrid(A,B)
AB = AA+BB
AB = np.sort(AB.flatten())[::-1]

ABAB, CC = np.meshgrid(AB,C)
ABC = ABAB+CC
ABC = np.sort(ABC.flatten())[::-1]

for abc in ABC:
    print(abc)

Buggy submission (verdict: Runtime Error):
import operator

di = {}

for i, (a, b, c) in enumerate(zip(a_, b_, c_)):
    di['a{}'.format(i)] = a
    di['b{}'.format(i)] = b
    di['c{}'.format(i)] = c

if len(di) > 3000:
    di = sorted(di.items(), reverse=True, key=operator.itemgetter(1))
    di = di[:3000]


a_li = []
b_li = []
c_li = []

for key, value in di.items():
    if 'a' in key:
        a_li.append(value)
    elif 'b' in key:
        b_li.append(value)
    elif 'c' in key:
        c_li.append(value)

ans = []
for a in a_li:
    for b in b_li:
        for c in c_li:
            ans.append(a+b+c)

ans.sort(reverse=True)

if len(ans) > 3000:
    for count, i in enumerate(ans):
        print(i)
        if count==2999:
            break
else:
    for count, i in enumerate(ans):
        print(i)
Problem p03079 (python)

Fixed submission:
abc = list(map(int, input().split()))
if len(set(abc)) == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
abc = list(map(int, input.split()))
if len(set(abc)) == 1:
    print('Yes')
else:
    print('No')
Problem p02995 (python)

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


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


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

# B以下で割り切れる
UB_C = B // C
UB_D = B // D
UB_CD = B // lcm(C, D)

UB = B - (UB_C + UB_D - UB_CD)

# A以下で割り切れる
UA_C = A // C
UA_D = A // D
UA_CD = A // lcm(C, D)

UA = A - (UA_C + UA_D - UA_CD)

ans = UB - UA

if A % C != 0 and A % D != 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math


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


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

# B以下で割り切れる
UB_C = B // C
UB_D = B // D
UB_CD = B // lcm(C, D)

UB = B - (UB_C + UB_D - UB_CD)

# A以下で割り切れる
UA_C = A // C
UA_D = A // D
UA_CD = A // lcm(C, D)

UA = A - (UA_C + UA_D - UA_CD)

ans = UB - UA

if A % C != 0 and A % D != 0:
    ans += 1

print(ans)
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
# 一番でかいやつと二番目のやつを見つける。
# 1番でかいやつが１つなら、基本最大値で、そいつがえらばれたら2番目の値教える。

max_val = max(A)
if len([i for i, x in enumerate(A) if x == max_val]) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)
            
# 一番でかいやつが２つ以上いるなら、つねに1番の値を表示する。

Buggy submission (verdict: Runtime Error):
import pandas as pd
from pandas import Series

N = int(input())
A = [int(input()) for _ in range(N)]
# 一番でかいやつと二番目のやつを見つける。
# 1番でかいやつが１つなら、基本最大値で、そいつがえらばれたら2番目の値教える。

max_val = max(A)
if sum(Series(A) == max_val) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)
            
# 一番でかいやつが２つ以上いるなら、つねに1番の値を表示する。
Problem p02922 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

if __name__ == '__main__':
    A , B = map(int, input().split())

    num = 1
    tap = 0

    if B==1:
        print(0)
        exit()

    while True:
        tap += 1
        num -= 1
        num += A

        if num >=B:
            break

    print(tap)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np

if __name__ == '__main__':
    A , B = map(int, input().split())

    num = 1
    tap = 0

    if B=1:
        print(0)
        exit()

    while True:
        tap += 1
        num -= 1
        num += A

        if num >=B:
            break

    print(tap)
Problem p03633 (python)

Fixed submission:
import fractions
N = int(input())
T = list(int(input()) for _ in range(N))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)

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

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,N):
        A = math.gcd(a, T[i])
        a = a * T[i] // A

    print(a)

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

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,len(T)):
        A = int(math.gcd(int(a), int(T[i])))
        a = a * T[i] / A

    print(int(a))

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

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,len(T)):
        A = math.gcd(int(a), int(T[i]))
        a = a * T[i] / A

    print(int(a))

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

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,len(T)-1):
        A = math.gcd(int(a), int(T[i]))
        a = a * T[i] / A

    print(int(a))
Problem p03069 (python)

Fixed submission:
N=int(input())
S=input()
M=S.count('.')
ans=M

for i in range(N):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
	ans = min(M,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
M=S.count('.')
ans=M

for i in range(N):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
    ans = min(M,ans)
print(ans)
Problem p03352 (python)

Fixed submission:
import math

x=int(input())

if x<4:
	print(x)
else:
	result=2
	for i in range(2,x):
		for j in range(2,x):
			if i**j<=x:
				result=max(result,i**j)
			else:
				break
	print(result)

Buggy submission (verdict: Runtime Error):
import math

x=int(input())

if x<4:
	print(x)
else:
	result=2
	for i in range(2,x):
		for j in range(2,x):
			if i**j<=x:
				result=max(result,i**j)
			else:
				break;
print(result)
Problem p03612 (python)

Fixed submission:
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
if alist[n-1]==n:
	ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
if alist[n-1]=n:
	ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
alist = [int(i) for i in input().split()]
ans=0

for i in range(n):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
print(ans)
Problem p03031 (python)

Fixed submission:
N,M=map(int,input().split())
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
P=list(map(int,input().split()))
ans=0
for i in range(2**N,2**(N+1)):
        B=bin(i)
        count=0
        for j in range(M):
            tet=0
            for l in range(A[j][0]):
                tet+=int(B[A[j][l+1]+2])
            if tet%2==P[j]:
                  count+=1
        if count==M:
            ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
P=list(map(int,input().split()))
ans=0
for i in range(2**N,2**(N+1)):
        B=bin(i)
        count=0
        for j in range(M):
            tet=0
            for l in range(A[j][0]):
                tet+=int(B[A[j][l+1]+2])
            if tet//2==P[j]:
                  count+=1
        if count==M:
            ans+=1
print(ans)
N,M=map(int,input().split())
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
P=list(map(int,input().split()))
ans=0
for i in range(2**N,2**(N+1)):
        B=bin(i)
        count=0
        for j in range(M):
            tet=0
            for l in range(A[j][0]):
                tet+=int(B[A[j][l+1]+2])
            if tet%2==P[j]:
                  count+=1
        if count==M:
            ans+=1
print(ans)
Problem p03050 (python)

Fixed submission:
N=int(input())
count=0
for i in range(1,round(N**(1/2))):
    if N%i==0:
        count+=N//i-1
print(count)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=0
B=0
A=0
count1=0
count2=0
for i in range(N):
    S=input()
    a+=S.count("AB")
    if S[0]=="B"and S[len(S)-1]=="A":
        a+=1
        count1+=1
    elif S[0]=="B":
        B+=1
        count2+=1
    elif S[0]=="A":
        A+=1
        count2+=1
if count1!=0:
    A+=1
    B+=1
if count2==0:
    a=a-1
C=min(A,B)
D=min(C,N-1)
print(a+D)
Problem p03062 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
b=min(B)
c=min(C)
d=min(b,c)
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*c)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
b=min(B)
c=min(C)
d=min(b,c)
if B==[]:
    print(sum(C))
elif len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*c)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*min(min(B),min(C)))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*min(min(B),min(C))
Problem p03068 (python)

Fixed submission:
A =int(input())
B=input()
c=int(input())
d=B[c-1]
E=""
for i in range(A):
    if B[i]==d:
        E=E+d
    else:
        E=E+"*"
print(E)

Buggy submission (verdict: Runtime Error):
A =int(input())
B=input()
c=int(input())
d=B[c]
E=""
for i in range(A):
    if B[i]==d:
        E=E+d
    else:
        E=E+"*"
print(E)
Problem p03502 (python)

Fixed submission:
N=input()
f=0
n=int(N)
for i in range(len(N)):
    f+=int(N[i])
if n%f==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=input()
f=0
for i in range(len(N)):
  f+=int(N[i])
if N%f==0:
  print("Yes")
else:
  print("No")
Problem p03633 (python)

Fixed submission:
#ユークリッドの互除法を用いる
N=int(input())
T=[]
for i in range(0,N):
    T.append(int(input()))
def gcd(a,b):
    while b>0 :
        a0=a
        b0=b
        a=b0
        b=a0%b0
    return a
def lcm_base(x,y):
    return (x*y)//gcd(x,y)
def lcm_reduce(T):
    result=T[0]
    for i in range(1,len(T)):
        result=lcm_base(result,T[i])
    return result
print(lcm_reduce(T))

Buggy submission (verdict: Runtime Error):
import math 
from functools import reduce
#C問題
#最小公倍数
N=int(input())
T=[]
for i in range(0,N):
    T.append(int(input()))
def lcm_base(x,y):
    return (x*y)//math.gcd(x,y)
print(reduce(lcm_base,T))