Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
s2 = ''
cnt = 0

while True:
    s = re.sub('^W+','',s)
    s = re.sub('B+$','',s)
    s2 = s.replace('BW', 'WB', 1)
    if s2 == s:
        break
    cnt += 1
    s = s2


print(cnt)

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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
e = 0
n = 0

for chr in s:
    if chr == 'W':
        e += n

    if chr == 'B':
        n += 1

print(e)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys


s = sys.stdin.readline().rstrip()
s2 = ''
cnt = 0

while True:
    s2 = s.replace('BW', 'WB', 1)
    if s2 == s:
        break
    cnt += 1
    s = s2


print(cnt)

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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
e = 0
n = 0

for chr in s:
    if chr == 'W':
        e += n

    if chr == 'B':
        n += 1

print(e)

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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys

def my_rep(old, new, st):
    st2 = st.replace(old, new, 1)

    if st2 == st:
        return 0

    return my_rep(old, new, st2) + 1



s = sys.stdin.readline().rstrip()
print(my_rep('BW','WB',s))


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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
e = 0
n = 0

for chr in s:
    if chr == 'W':
        e += n

    if chr == 'B':
        n += 1

print(e)

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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re



def my_sub(_re,_rep,st):
    st2 = _re.sub(_rep, st, 1)

    if st2 == st:
        return 0

    return my_sub(_re, _rep, st2) + 1



s = sys.stdin.readline().rstrip()
print(my_sub(re.compile('BW'),'WB',s))


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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
e = 0
n = 0

for chr in s:
    if chr == 'W':
        e += n

    if chr == 'B':
        n += 1

print(e)
Buggy python submission (verdict: Runtime Error):
N = input()
p = []
max = 0
for i in range(N):
  p.append(int(input()))
  if(p[i]>max):
    maxi = i
sum = 0
for i in range(N):
  if(i == maxi):
    sum += p[i]/2
  else:
    sum += p[i]
print(sum)

Fixed submission:
N = int(input())
p = []
max = 0
for i in range(N):
  p.append(int(input()))
p.sort()
sum = 0
for i in range(N-1):
  sum += p[i]
sum += p[N-1]/2
print(int(sum))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini){
    mini = sub
print(mini)


Fixed submission:
N, K = map(int, input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini):
    mini = sub
print(mini)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini){
    mini = sub
print(mini)

Fixed submission:
N, K = map(int, input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini):
    mini = sub
print(mini)
Buggy python submission (verdict: Runtime Error):
n = list(input())
for i range(len(n)):
  n[i] = "1" if n[i]==9 else "9"
ans = ','.join(n)
print(ans)

Fixed submission:
n = list(input())
for i in range(len(n)):
  n[i] = "1" if n[i]=="9" else "9"
ans = ''.join(n)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(N:1000):
  if(str(i)[1] == str(i)[2] and str(i)[1] == str(i)[3]):
    num = i
    break
print(num)

Fixed submission:
N = int(input())
for i in range(N,1000):
  if(str(i)[0] == str(i)[1] and str(i)[1] == str(i)[2]):
    num = i
    break
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
string = str(input())
n = 0

for _ in range(len(string)):

    try:
        i = string.index("W")
        n = n + i
        string = string[:i] + string[i+1:]
    
    except ValueError:
        break

print(n)


Fixed submission:
string = str(input())

Wi = [i for i, x in enumerate(string) if x == 'W']
Wi = [x - i for i, x in enumerate(Wi)]

print(sum(Wi))
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  while b>0:
    a,b=b,a%b
  return a

x,y=map(int,input().split())
S=input()
T=input()
GCD=gcd(x,y)
LCM=(x * y) // GCD

x_new=x//GCD
y_new=y//GCD
for i in range(0,GCD-1):
  if S[(x_new)*i]==T[(y_new)*i]:
    result=LCM
  else:
    result=-1
    break
print(result)

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

x,y=map(int,input().split())
S=input()
T=input()
GCD=gcd(x,y)
LCM=(x * y) // GCD

x_new=x//GCD
y_new=y//GCD
for i in range(0,GCD):
  if S[(x_new)*i]==T[(y_new)*i]:
    result=LCM
  else:
    result=-1
    break
print(result)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
bet=abs(b-a)
if bet%2==0:
  winner='ALice'
  else:
    winner='Borys'
    
print(winner)

Fixed submission:
n,a,b=map(int,input().split())
bet=abs(b-a)
if bet%2==0:
  winner='Alice'
else:
    winner='Borys'
    
print(winner)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*(N-1)

for i in range(N-1):
  number_sum[i]=abs(sum(number[:i+1])*2-SUM)

print(min(number_sum))

Fixed submission:
N=int(input())
number=list(map(int,input().split()))
Sum=sum(number)
number_sum=[0]*N
number_sum[0]=number[0]
result=[0]*(N-1)
for i in range(1,N):
  number_sum[i]=number_sum[i-1]+number[i]
result[0]=abs(number_sum[0]*2-Sum)
for i in range(1,N-1):
  result[i]=abs(((number_sum[i])*2-Sum))

print(min(result))
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if x=y:
  result=0
elif y>x:
  if x<=0 and y>=0 and (x+y)/2>=0:
    result=y-abs(x)+1
  else:
    result=y-x
elif x>=y:
  if y>=0:
    result=y+x+1 
  elif x<=0:
    result=x-y+2
  else:
    result=abs(abs(x)-abs(y))+1
  
print(result)

Fixed submission:
x,y=map(int,input().split())
if x==y:
  result=0
elif y>x:
  if x<0 and y>0:
    result=abs(abs(y)-abs(x))+1
  else:
    result=y-x
elif x>y:
  if x<0:
    result=x-y+2
  else:
    if y>0:
      result=x-y+2
    else:
      result=abs(abs(x)-abs(y))+1
  
print(result)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

S = stdin.readline().rstrip()
#S = input()
white = 0
total = 0
for i in range len(S):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)


Fixed submission:
from sys import stdin

S = stdin.readline().rstrip()
#S = input()
white = 0
total = 0
for i in range(len(S)):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)

Buggy python submission (verdict: Runtime Error):
S = input()
white = 0
total = 0
for i in range len(S):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)


Fixed submission:
from sys import stdin

S = stdin.readline().rstrip()
#S = input()
white = 0
total = 0
for i in range(len(S)):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)

Buggy python submission (verdict: Runtime Error):
S = input()
white = 0
total = 0
for i in range len(S):
    if S[i] == "W":
        total += (i - white)
        white ++
        
print(total)

Fixed submission:
from sys import stdin

S = stdin.readline().rstrip()
#S = input()
white = 0
total = 0
for i in range(len(S)):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)
Buggy python submission (verdict: Runtime Error):
K = int(input())
A = list(map(int,input().split()))
a = K-1
p = 2
while 0 <= a:
    if A[a-1] > A[a]*2:
        print('-1')
        exit()
    num = 1
    if A[a] < p:
        while A[a]*num < p:
            num += 1
    p = num*A[a]
    a -= 1
pmax = p
while pmax < A[1]*2:
    pmax += A[0]
pmax -= A[0]
print(p,pmax)


Fixed submission:
import math
K = int(input())
A = list(map(int,input().split()))
a = 1
L,S = 2,2 

while a <= K:
    if math.ceil(S/A[-a])*A[-a] < S or L < math.ceil(S/A[-a])*A[-a]:
        print('-1')
        exit()
    S = math.ceil(S/A[-a])*A[-a]
    L = math.floor(L/A[-a])*A[-a] + A[-a] -1
    a += 1
print(S,L)
Buggy python submission (verdict: Runtime Error):
prinm(48-int(input()))

Fixed submission:
print(48-int(input()))
Buggy python submission (verdict: Runtime Error):
import math 
print(math.ceil(int((int(input())+int(input()))/2))

Fixed submission:
import math 
a,b = map(int,input().split())
print(math.ceil((a+b)/2))
Buggy python submission (verdict: Runtime Error):
Sd_ = input()
T_ = input()
Sd = []
T = []
S = []
check = False
for i in range(len(Sd_)):
    Sd.append(Sd_[i])
for i in range(len(T_)):
    T.append(T_[i])
num = 0
for a in range(len(Sd)-1,0,-1):
    if Sd[a] is '?':
        num += 1
    else:
        num = 0
    if num >= len(T):
        for m in range(len(T)):
            Sd[a+m] = T[m]
        for s in range(len(Sd)):
            if Sd[s] is '?':
                S.append('a')
            else:
                S.append(Sd[s])
        print(''.join(S))
        exit()


for i in range(len(Sd)-1,0,-1):
    if Sd[i] is not '?':
        if Sd[i] in T_:
            check = True
            num = T_.find(Sd[i])
            for n in range(len(T_)):
                if n < num:
                    if Sd[i-num+n] is not '?':
                        check = False
                        break
                else:
                    if Sd[i-num+n] is not T_[n] and Sd[i-num+n] is not '?':
                        check = False
                        break
            if check:
                for m in range(len(T)):
                    Sd[i-num+m] = T[m]
                break

if check:
    for s in range(len(Sd)):
        if Sd[s] is '?':
            S.append('a')
        else:
            S.append(Sd[s])
    print(''.join(S))
else:
    print('UNRESTORABLE')

Fixed submission:
Sd_ = input()
T_ = input()
Sd = []
T = []
S = []
for i in range(len(Sd_)):
    Sd.append(Sd_[i])
for i in range(len(T_)):
    T.append(T_[i])


def check(s, t, n):
    for i in range(len(t)):
        if s[n + i] is not t[i] and s[n + i] is not '?':
            return False
    return True


m = len(Sd) - len(T)
while m >= 0:
    if check(Sd[:], T[:], m):
        for j in range(len(T)):
            Sd[m + j] = T[j]
        for a in range(len(Sd)):
            if Sd[a] is '?':
                S.append('a')
            else:
                S.append(Sd[a])
        print(''.join(S))
        exit()
    m -= 1
print('UNRESTORABLE')
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = 0
s = []
patern = 0
for i in range(len(S)):
    s.append(S[i])
while n < len(s)//2+1:
    if s[n] is 'x':
        if s[-n-1] is not 'x':
            s.append('x')
            patern += 1
    else:
        if s[-n-1] is 'x':
            s.insert(n,'x')
            patern += 1
        elif s[-n-1] is not s[n]:
            patern = -1
            break
    n += 1
if patern != -1:
    print(patern)
else:
    print(patern)

Fixed submission:
S = input()
n, m = 0, 1
s = []
patern = 0
for i in range(len(S)):
    s.append(S[i])
while n + m < len(s):
    if s[n] is 'x':
        if s[-m] is not 'x':
            s.append('x')
            patern += 1
    else:
        if s[-m] is 'x':
            n -= 1
            patern += 1
        elif s[-m] is not s[n]:
            patern = -1
            break
    n += 1
    m += 1
if patern != -1:
    print(patern)
else:
    print(patern)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = 0
s = []
patern = 0
for i in range(len(S)):
    s.append(S[i])
while n < len(s):
    if s[n] is 'x':
        if s[-n-1] is not 'x':
            s.append('x')
            patern += 1
    else:
        if s[-n-1] is 'x':
            s.insert(n,'x')
            patern += 1
        elif s[-n-1] is not s[n]:
            patern = -1
            break
    n += 1
if patern != -1:
    print(patern)
else:
    print(patern)

Fixed submission:
S = input()
n, m = 0, 1
s = []
patern = 0
for i in range(len(S)):
    s.append(S[i])
while n + m < len(s):
    if s[n] is 'x':
        if s[-m] is not 'x':
            s.append('x')
            patern += 1
    else:
        if s[-m] is 'x':
            n -= 1
            patern += 1
        elif s[-m] is not s[n]:
            patern = -1
            break
    n += 1
    m += 1
if patern != -1:
    print(patern)
else:
    print(patern)
Buggy python submission (verdict: Runtime Error):
s = input()
a = 'YAKI'
ans = 0
for i in range(4):
    if s[i] == a[i]:
        ans = 1
    else:
        break
if ans == 1:
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()
a = 'YAKI'
ans = 0
if len(s) >= 4:
    for i in range(4):
        if s[i] == a[i]:
            ans = 1
        else:
            ans = 0
            break
if ans == 1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = []
for i in range(N):
    num = int(input())
    check = ans.count(num)
    if check == 0:
        ans.append(num)
    else:
        ans.pop(check)
print(len(ans))

Fixed submission:
N = int(input())
ans = set()
for i in range(N):
    num = int(input())
    if num in ans:
        ans.remove(num)
    else:
        ans.add(num)
print(len(ans))

Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = []
check = 0
for i in range(N):
    num = int(input())
    for n in range(len(ans)):
        if ans[n] == num:
            check = -1
            break
        else:
            check = n
    if check == -1:
        ans.remove(num)
    else:
        ans.append(num)
print(len(ans))

Fixed submission:
N = int(input())
ans = set()
for i in range(N):
    num = int(input())
    if num in ans:
        ans.remove(num)
    else:
        ans.add(num)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = []
for i in range(N):
    num = int(input())
    check = ans.count(num)
    if check == 0:
        ans.append(num)
    else:
        ans.remove(num)
print(len(ans))

Fixed submission:
N = int(input())
ans = set()
for i in range(N):
    num = int(input())
    if num in ans:
        ans.remove(num)
    else:
        ans.add(num)
print(len(ans))
Buggy python submission (verdict: Runtime Error):
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            p[i], p[i+1] = p[i+1], p[i]
            count += 1
    print(count)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            if i+1 == N:
                p[i], p[i - 1] = p[i - 1], p[i]
                count += 1
            else:
                p[i], p[i+1] = p[i+1], p[i]
                count += 1
    print(count)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            p[i], p[i+1] = p[i+1], p[i]
            count += 1
    print(count)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            if i+1 == N:
                p[i], p[i - 1] = p[i - 1], p[i]
                count += 1
            else:
                p[i], p[i+1] = p[i+1], p[i]
                count += 1
    print(count)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
N = int(input())
p = list(map(int,input().split))
count = 0
for i in range(N):
    if p[i] == i:
        p[i],p[i+1] = p[i+1],p[i]
        count += 1
print(count)

Fixed submission:
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            if i+1 == N:
                p[i], p[i - 1] = p[i - 1], p[i]
                count += 1
            else:
                p[i], p[i+1] = p[i+1], p[i]
                count += 1
    print(count)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
def solve():
    N = int(input())
    p = list(map(int,input().split))
    count = 0
    for i in range(N):
        if p[i] == i:
            p[i],p[i+1] = p[i+1],p[i]
            count += 1
    print(count)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    count = int(0)
    for i in range(N):
        if p[i] == i+1:
            if i+1 == N:
                p[i], p[i - 1] = p[i - 1], p[i]
                count += 1
            else:
                p[i], p[i+1] = p[i+1], p[i]
                count += 1
    print(count)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(7):
    if 2**i < N:
        ans = 2**i
print(ans)

Fixed submission:
N = int(input())
n = 1
num = 2
while num <= N:
    num = 2**n
    n += 1
print(int(num/2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])
if N % 2 == 1:
    [print(b[i], end=' ') for i in reversed(range(len(b)))]
else:
    [print(b[i], end=' ') for i in range(len(b))]


Fixed submission:
from collections import deque
N = int(input())
a = [int(i) for i in input().split()]
b = deque()
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if N % 2 == 1:
    [print(b[i], end=' ') for i in reversed(range(len(b)))]
else:
    [print(b[i], end=' ') for i in range(len(b))]

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])
if N % 2 == 1:
    b.reverse()
[print(b[i], end=' ') for i in range(len(b))]


Fixed submission:
from collections import deque
N = int(input())
a = [int(i) for i in input().split()]
b = deque()
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if N % 2 == 1:
    [print(b[i], end=' ') for i in reversed(range(len(b)))]
else:
    [print(b[i], end=' ') for i in range(len(b))]

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(N):
    b.append(a[i])
    b.reverse()
[print(b[i], end=' ') for i in range(len(b))]


Fixed submission:
from collections import deque
N = int(input())
a = [int(i) for i in input().split()]
b = deque()
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if N % 2 == 1:
    [print(b[i], end=' ') for i in reversed(range(len(b)))]
else:
    [print(b[i], end=' ') for i in range(len(b))]
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]
num = a[0]
ans = 0
check = 0
for n in range(1, N):
    num = a[num-1]
    if num-1 == 1:
        ans = n + 1
        check = 1
        break
if check != 1:
    print('-1')
else:
    print(ans)


Fixed submission:
x, a, b = [int(i) for i in input().split()]
if b <= a:
    print('delicious')
elif (b-a) <= x:
    print('safe')
else:
    print('dangerous')
Buggy python submission (verdict: Time Limit Exceeded):
a, b = [int(i) for i in input().split()]
num = 1
numb = 1
if abs(a-b) == 1:
    for i in range(a):
        num = (a-i)*num
    for i in range(b):
        numb = (b-i)*numb
    num = num*numb
elif abs(a-b) == 0:
    for i in range(a):
        num = (a-i)*num
    num = (num**2)*2
else:
    num = 0

print(num%(10**9+7))

Fixed submission:
from math import factorial

a, b = [int(i) for i in input().split()]
num = 1
if abs(a-b) == 1:
    num = factorial(a)*factorial(b)
elif abs(a-b) == 0:
    num = factorial(a) * factorial(b) * 2
else:
    num = 0

print(num%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
rank = [0]*9
ans = [0]*2
for i in range(len(a)):
    if a[i] < 400:
        rank[0] = 1
    elif a[i] < 800:
        rank[1] = 1
    elif a[i] < 1200:
        rank[2] = 1
    elif a[i] < 1600:
        rank[3] = 1
    elif a[i] < 2000:
        rank[4] = 1
    elif a[i] < 2400:
        rank[5] = 1
    elif a[i] < 2800:
        rank[6] = 1
    elif a[i] < 3200:
        rank[7] = 1
    else:
        rank[8] += 1
ans[0] = sum(rank)
if 8 < ans[0]:
    ans[0] = 8
if rank[9] != 0 and (sum(rank[0:8])) == 0:
    ans[1] = 1
else:
    ans[1] = sum(rank[0:8])

[print(ans[i], end=' ') for i in reversed(range(len(ans)))]


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
rank = [0]*9
ans = [0]*2
for i in range(len(a)):
    if a[i] < 400:
        rank[0] = 1
    elif a[i] < 800:
        rank[1] = 1
    elif a[i] < 1200:
        rank[2] = 1
    elif a[i] < 1600:
        rank[3] = 1
    elif a[i] < 2000:
        rank[4] = 1
    elif a[i] < 2400:
        rank[5] = 1
    elif a[i] < 2800:
        rank[6] = 1
    elif a[i] < 3200:
        rank[7] = 1
    else:
        rank[8] += 1
ans[0] = sum(rank)

if sum(rank[:8]) == 0:
    ans[1] = 1
else:
    ans[1] = sum(rank[:8])

[print(ans[i], end=' ') for i in reversed(range(len(ans)))]
Buggy python submission (verdict: Runtime Error):
n = int(input())
N = input()
L = 0
R = 0
num = 0
while N[num] == ')':
    L += 1
    num += 1
num = n-1
while N[num] == '(':
    R += 1
    num -= 1
a = N.count('(')
b = len(N) - a
c = a - b + L -R
if (c) < 0:
    for i in range(abs(c)):
        N = '(' + N
elif (c) > 0:
    for i in range(abs(c)):
        N = N + ')'
print('('*L+N+')'*R)

Fixed submission:
n = int(input())
N = input()
L = 0
R = 0
num = 0
for c in N:
    if c == '(':
        num += 1
    else:
        if num:
            num -= 1
        else:
            L += 1
R = num

print('('*L+N+')'*R)

Buggy python submission (verdict: Runtime Error):
n = int(input())
N = input()
num = 0
while N[num] == ')':
    N = '(' + N
    num += 2
a = N.count('(')
b = len(N)-a
if (a - b) < 0:
    for i in range(b-a):
        N = '(' + N
else:
    for i in range(a-b):
        N = N + ')'

print(N)

Fixed submission:
n = int(input())
N = input()
L = 0
R = 0
num = 0
for c in N:
    if c == '(':
        num += 1
    else:
        if num:
            num -= 1
        else:
            L += 1
R = num

print('('*L+N+')'*R)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
ans = []
for i in range(N):
    A,B = [int(i) for i in input().split()]
    for b in range(B):
        ans.append(A)
ans.sort()
print(ans[K-1])




Fixed submission:
N, K = [int(i) for i in input().split()]
ans = []
A = [[]*2]*N
num = 0
for i in range(N):
    A[i] = [int(i) for i in input().split()]
A.sort()
i = 0
while num < K:
    num += A[i][1]
    i += 1

print(A[i-1][0])