Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
import fractions
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = fractions.gcd(i,j)
                           tmp = fractions.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
print(ans)


Fixed submission:
k = int(input())
import math
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = math.gcd(i,j)
                           tmp = math.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 0
for i in range(len(s)-2):
         for j in range(i+1,len(s)-1):
                  for k in range(j+1,len(s)):
                           if (s[i] != s[j] and s[j] != s[k] and s[k] != s[i]) and (j - i != k - j):
                                    ans += 1
print(ans)


Fixed submission:
n = int(input())
s = list(input())
Rcount = 0
Gcount = 0
Bcount = 0
cnt = 0
for i in range(len(s)):
         if s[i] == "R":
                  Rcount += 1
         elif s[i] == "G":
                  Gcount += 1
         elif s[i] == "B":
                  Bcount += 1
RGB = Rcount * Gcount * Bcount
for i in range(1,(len(s)//2)+2):
         for j in range(len(s)):
                  if i * 2 + j >= len(s):
                           break
                  else:
                           if s[j] != s[j+i] and s[j+i] != s[j+i+i] and s[j+i+i] != s[j]:
                                    cnt += 1
print(RGB - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 0
for i in range(len(s)-2):
         for j in range(i+1,len(s)-1):
                  for k in range(j+1,len(s)):
                           if (s[i] != s[j] and s[j] != s[k] and s[k] != s[i]) and (j - i != k - j):
                                    ans += 1
print(ans)


Fixed submission:
n = int(input())
s = list(input())
Rcount = 0
Gcount = 0
Bcount = 0
cnt = 0
for i in range(len(s)):
         if s[i] == "R":
                  Rcount += 1
         elif s[i] == "G":
                  Gcount += 1
         elif s[i] == "B":
                  Bcount += 1
RGB = Rcount * Gcount * Bcount
for i in range(1,(len(s)//2)+2):
         for j in range(len(s)):
                  if i * 2 + j >= len(s):
                           break
                  else:
                           if s[j] != s[j+i] and s[j+i] != s[j+i+i] and s[j+i+i] != s[j]:
                                    cnt += 1
print(RGB - cnt)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
tmp = [-1]*n
for j in range(m):
         if tmp[(sc[j][0]-1)] != sc[j][1]:
                  if tmp[(sc[j][0]-1)] != -1:
                           print(-1)
                           exit()
         tmp[(sc[j][0]-1)] = sc[j][1]
if tmp[0] == -1 and len(tmp) >= 2:
         print(-1)
         exit()
elif tmp[0] == -1 and len(tmp) == 1:
         print(0)
         exit()
else:
         for k in range(n):
                  if tmp[k] == -1:
                           tmp[k] = 0
                  print("{}".format(tmp[k]), end = "")


Fixed submission:
a = []
for i in range(3):
         a.append( list(map(int,input().split())))
n = int(input())
b = [int(input()) for j in range(n)]
for k in range(3):
         for l in range(3):
                  for m in range(n):
                           if a[k][l] == b[m]:
                                    a[k][l] = -1
if a[0][0] == a[0][1] == a[0][2] == -1 or  a[1][0] == a[1][1] == a[1][2] == -1 or  a[2][0] == a[2][1] == a[2][2] == -1 or  a[0][0] == a[1][0] == a[2][0] == -1 or  a[0][1] == a[1][1] == a[2][1] == -1 or  a[0][2] == a[1][2] == a[2][2] == -1 or  a[0][0] == a[1][1] == a[2][2] == -1 or  a[0][2] == a[1][1] == a[2][0] == -1 :
         print("Yes")
else:
         print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
         p[i] = (p[i]+1)/2
ans = 0
for i in range(n-(k-1)):
         if ans < sum(p[i:(i+k)]):
                  ans  = sum(p[i:(i+k)])
print(ans)


Fixed submission:
n,k = map(int,input().split())
p = list(map(int,input().split()))
ps = [0]
for i in range(len(p)):
         ps.append(((p[i] + 1)/2)+ps[i])
ans = 0
for i in range(n+1-k):
         if ans < (ps[i+k] - ps[i]):
                  ans = (ps[i+k] - ps[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
tmp = 0
for i in range(len(a)):
         tmp += a[i]
         if tmp >= (sum(a))//2:
                  break
print(min((abs((sum(a)-tmp)-tmp)),abs((sum(a)-(tmp-a[i]))-(tmp-a[i]))))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
suma = sum(a)
tmp = 0
for i in range(len(a)):
         tmp += a[i]
         if tmp >= suma//2:
                  break
print(min((abs((suma-tmp)-tmp)),abs((suma-(tmp-a[i]))-(tmp-a[i]))))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
yakusuu = []
ans = 1
for i in range (2,min(a,b)+1):
         if a % i == 0 and b% i == 0:
                  yakusuu.append(i)
for j in range(len(yakusuu)):
         for k in range(2,yakusuu[j]**(1/2)):
                  if yakusuu[j] % k == 0:
                           break
         else:
                  ans += 1
print(ans)


Fixed submission:
aa,bb = map(int,input().split())
n = min(aa,bb)
b = max(aa,bb)
ans = 1
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
         if temp%i==0:
                  cnt=0
                  while temp%i==0:
                           cnt+=1
                           temp //= i
                  arr.append(i)

if temp!=1:
         arr.append(temp)

if arr==[] and n != 1:
         arr.append(n)

for j in range(len(arr)):
         if b % arr[j] == 0:
                  ans += 1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
yakusuu = []
ans = 1
for i in range (2,min(a,b)+1):
         if a % i == 0 and b% i == 0:
                  yakusuu.append(i)
for j in range(len(yakusuu)):
         for k in range(2,yakusuu[j]):
                  if yakusuu[j] % k == 0:
                           break
         else:
                  ans += 1
print(ans)


Fixed submission:
aa,bb = map(int,input().split())
n = min(aa,bb)
b = max(aa,bb)
ans = 1
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
         if temp%i==0:
                  cnt=0
                  while temp%i==0:
                           cnt+=1
                           temp //= i
                  arr.append(i)

if temp!=1:
         arr.append(temp)

if arr==[] and n != 1:
         arr.append(n)

for j in range(len(arr)):
         if b % arr[j] == 0:
                  ans += 1
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())
a = list (int(input()) for hogehoge in range(q))
for i in range(1,n+1):
         if a.count(i) >= (q-k+1):
                  print("Yes")
         else:
                  print("No")


Fixed submission:
from collections import Counter
n,k,q = map(int,input().split())
a = list (int(input()) for hogehoge in range(q))
acount = Counter(a)
for i in range(1,n+1):
         if acount[i] >= (q-k+1):
                  print("Yes")
         else:
                  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())
a = list (int(input()) for hogehoge in range(q))
acount = []
for i in range(1,n+1):
         acount.append(a.count(i))
for j in range(n):
         if acount[j] >= (q-k+1):
                  print("Yes")
         else:
                  print("No")


Fixed submission:
from collections import Counter
n,k,q = map(int,input().split())
a = list (int(input()) for hogehoge in range(q))
acount = Counter(a)
for i in range(1,n+1):
         if acount[i] >= (q-k+1):
                  print("Yes")
         else:
                  print("No")
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = (c*d)//math.gcd(c,d)
print(((b-((b//c)+(b//d)-(b//lcm)))-((a-1)-(((a-1)//c)+((a-1)//d)-((a-1)//lcm)))))


Fixed submission:
import fractions
a,b,c,d = map(int,input().split())
lcm = (c*d)//fractions.gcd(c,d)
print(((b-((b//c)+(b//d)-(b//lcm)))-((a-1)-(((a-1)//c)+((a-1)//d)-((a-1)//lcm)))))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())
ans = 0
for i in range(a,b+1):
         if i%c != 0 and i%d != 0:
                  ans += 1
print(ans)


Fixed submission:
import fractions
a,b,c,d = map(int,input().split())
lcm = (c*d)//fractions.gcd(c,d)
print(((b-((b//c)+(b//d)-(b//lcm)))-((a-1)-(((a-1)//c)+((a-1)//d)-((a-1)//lcm)))))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(int(input()) for hoge in range(m))
dan = [a[0]]
ans = 1
for i in range(m-1):
         if (a[i+1]-(a[i]+1)) == 0:
                  print(0)
                  exit()
         dan.append(a[i+1]-(a[i]+1))
dan.append(n-(a[m-1]))
for j in range (len(dan)):
         ans *= ((2 ** (dan[j] //2)))
print(ans%((10 ** 9) +7))



Fixed submission:
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
step_patern = [0,1]
for i in range(n):
         step_patern.append(step_patern[i] + step_patern[i+1])
kankaku = []
tmp = 0
for i in range(len(a)):
         kankaku.append(a[i] - tmp)
         tmp = a[i] +1
kankaku.append(n + 1 - tmp)
ans = 1
for i in kankaku:
         ans *= step_patern[i]
         ans %= (10 ** 9) +7
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
sortl = sorted(l)
ans = 0
for number in sortl:
         ans += number
if ans - sortl(n-1) >= sortl(n-1):
         print("No")
else:
         print("Yes")


Fixed submission:
n = int(input())
l = list(map(int,input().split()))
sortl = sorted(l)
ans = 0
for number in sortl:
         ans += number
if ans - sortl[n-1] > sortl[n-1]:
         print("Yes")
else:
         print("No")
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = [[0]*5 for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           for k in range(max(0,i-1),min(h,(i+1)+1)):
                                    for l in range(max(0,j-1),min(w,(j+1)+1)):
                                             ans[k][l] += 1
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           ans [i][j] = "#"
for i in range(h):
         answer = list(map(str,ans[i]))
         answer=''.join(answer)
         print(answer)



Fixed submission:
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = [[0]*w for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           for k in range(max(0,i-1),min(h,(i+1)+1)):
                                    for l in range(max(0,j-1),min(w,(j+1)+1)):
                                             ans[k][l] += 1
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           ans [i][j] = "#"
for i in range(h):
         answer = list(map(str,ans[i]))
         answer=''.join(answer)
         print(answer)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n = input()
    digit = int(n[-1])

    if digit == 3:
        print('bon')
    elif digit == 0:
        print('pon')
    elif digit == 1:
        print('pon')
    elif digit == 6:
        print('pon')
    elif digit == 8:
        print('pon')
    else:
        print('hon')


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = str(input())
    digit = n[-1]

    if digit == '3':
        print('bon')
    elif digit == '0':
        print('pon')
    elif digit == '1':
        print('pon')
    elif digit == '6':
        print('pon')
    elif digit == '8':
        print('pon')
    else:
        print('hon')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    for i in range(q):
        qi = input().split()

        if qi[0] == '1':
            s = s[::-1]
        else:
            if qi[1] == '1':
                s = qi[2] + s
            else:
                s += qi[2]

    print(s)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    s = input()
    q = int(input())
    d = deque()
    d.append(s)
    reverse_count = 0

    for i in range(q):
        qi = input().split()

        if qi[0] == '1':
            reverse_count += 1
        else:
            if reverse_count % 2 == 0:
                if qi[1] == '1':
                    d.appendleft(qi[2])
                else:
                    d.append(qi[2])

            else:
                if qi[1] == '1':
                    d.append(qi[2])
                else:
                    d.appendleft(qi[2])

    c = ''.join(map(str, d))

    if reverse_count % 2 == 1:
        c = c[::-1]

    print(c)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    for i in range(q):
        qi = input().split()

        if qi[0] == '1':
            s = s[::-1]
        else:
            if qi[1] == '1':
                s = qi[2] + s
            else:
                s += qi[2]

    print(s)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    s = input()
    q = int(input())
    d = deque()
    d.append(s)
    reverse_count = 0

    for i in range(q):
        qi = input().split()

        if qi[0] == '1':
            reverse_count += 1
        else:
            if reverse_count % 2 == 0:
                if qi[1] == '1':
                    d.appendleft(qi[2])
                else:
                    d.append(qi[2])

            else:
                if qi[1] == '1':
                    d.append(qi[2])
                else:
                    d.appendleft(qi[2])

    c = ''.join(map(str, d))

    if reverse_count % 2 == 1:
        c = c[::-1]

    print(c)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    numbers = [list() for _ in range(n)]

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        numbers[si].append(ci)

    ans = list()

    for index, element in enumerate(numbers):
        if n >= 2 and index != 0 and len(element) == 0:
            numbers[index].append(0)

        if n >= 2 and index == 0:
            digit = sorted(set(numbers[0]))

            if len(digit) == 0:
                print(-1)
                exit()
            elif len(digit) == 1 and 0 in digit:
                print(-1)
                exit()
            elif len(digit) >= 2 and 0 in digit:
                ans.append(digit[1])
                continue

        ans.append(min(numbers[index]))

    candidate = ''.join(map(str, ans))

    if len(str(int(candidate))) == len(candidate):
        print(candidate)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    s = list()
    c = list()

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        s.append(si)
        c.append(ci)

    for i in range(1000):
        digit = list(str(i))

        if len(digit) != n:
            continue

        ok = True

        for j in range(m):
            if int(digit[s[j]]) != c[j]:
                ok = False

        if ok:
            print(i)
            exit()

    print(-1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = 1
    ans = 0

    for ai in a:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = 1
    ans = 0

    for ai in a:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = a[0]
    ans = 0

    for ai in a[1:]:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = 1
    ans = 0

    for ai in a:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = a[0]
    ans = 0

    for ai in a[1:]:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai
        ans %= mod

    print(ans % mod)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = 1
    ans = 0

    for ai in a:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = a[0]
    ans = 0

    for ai in a[1:]:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai
        ans %= mod

    print(ans % mod)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = 1
    ans = 0

    for ai in a:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a ** 2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a ** 2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if x == (a ** 2) * b:
        print(0)
    elif 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)
    a_second = sorted_a[-2]

    for ai in a:
        if ai == a_max:
            print(a_second)
        else:
            print(a_max)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    # 1-indexに
    a = [0] + list(map(int, input().split()))
    c = [0 for _ in range(n + 1)]

    # See
    # https://www.youtube.com/watch?v=-o4r74eJzV4
    # 全体の計算量は，O(N^2)のようにみえて，O(NlogN)
    # 箱iの番号が大きいものから見る
    for i in range(n, 0, -1):
        # ボールの個数の和を0で初期化
        ball_count = 0

        # iの倍数の箱を順番に見る
        # ループの範囲を[2 * i, n]として，i個飛ばしで
        for j in range(2 * i, n + 1, i):
            # mod2は，xor（排他的論理和）を使うと言い換えるとスマートに記述できる．
            # ただし，演算の順序に注意が必要
            ball_count ^= c[j]

        # i個ずつみた後の合計(mod2)とa[i]を比べる
        c[i] = a[i] ^ ball_count

    # 出力
    # ボールが入っている箱の個数とその番号
    ans = [index for index, ci in enumerate(c) if ci == 1]
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n, x = map(int, input().split())
    ls = list(map(int, input().split()))
    count = 0
    d = 0

    for i in range(1, n + 2):
        if d > x:
            print(count)
            exit()

        d = d + ls[i - 1]
        count += 1

    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect

    n, x = map(int, input().split())
    ls = list(map(int, input().split()))
    dist = [0]

    for i in range(1, n + 1):
        dist.append(dist[i - 1] + ls[i - 1])

    print(bisect(dist, x))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    s = list(input())

    if len(set(s)) == 1:
        print(0)
    else:
        ans = 0
        i = 0

        while i < n - 1:
            if s[i] == '#' and s[i + 1] == '.':
                ans += 1

                if i + 2 < n:
                    if s[i + 2] == '#':
                        i += 2
                    elif s[i + 2] == '.':
                        i += 3
                else:
                    print(ans)
                    exit()
            else:
                i += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    s = list(input())
    black_count = [0 for _ in range(n + 1)]
    ans = float('inf')

    for i, si in enumerate(s):
        if si == '#':
            black_count[i + 1] = black_count[i] + 1
        else:
            black_count[i + 1] = black_count[i]

    for j in range(n + 1):
        ans = min(ans, black_count[j] + (n - j) - black_count[n] + black_count[j])

    print(ans)


if __name__ == '__main__':
    main()