Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
s = sum(A)
p = 10**20
t = 0
for i in range(n):
    t += A[i]
    p = min(p, abs(s-t*2))
    if 2*t > sum(A):
        break
print(p)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
s = sum(A)
p = 10**20
t = 0
for i in range(n):
    t += A[i]
    p = min(p, abs(s-t*2))
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

d = sum(A)
for i in range(n):
    d = min(abs(sum(A[:i]) - sum(A[i:])), d)
print(d)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
s = sum(A)
p = 10**20
t = 0
for i in range(n):
    t += A[i]
    p = min(p, abs(s-t*2))
print(p)
Buggy python submission (verdict: Runtime Error):
from math import atan, degrees
a, b, x = map(int, input().split())
if pow(a,b)*b == x:
    print(0)
elif b*pow(a,2)/2 <= x:
    print(90-degrees(atan((a/2)/(b-x/pow(a,2)))))
else:
    print(90-degrees(atan((2*x/(a*b))/b)))

Fixed submission:
from math import atan, degrees
a, b, x = map(int, input().split())
if pow(a,2)*b == x:
    print(0)
elif b*pow(a,2)/2 <= x:
    print(90-degrees(atan((a/2)/(b-x/pow(a,2)))))
else:
    print(90-degrees(atan((2*x/(a*b))/b)))

Buggy python submission (verdict: Runtime Error):
from math import atan, degrees
a, b, x = map(int, input().split())
if b*pow(a,2)/2 <= x:
    print(90-degrees(atan((a/2)/(b-x/pow(a,2)))))
else:
    print(90-degrees(atan((2*x/(a*b))/b)))

Fixed submission:
from math import atan, degrees
a, b, x = map(int, input().split())
if pow(a,2)*b == x:
    print(0)
elif b*pow(a,2)/2 <= x:
    print(90-degrees(atan((a/2)/(b-x/pow(a,2)))))
else:
    print(90-degrees(atan((2*x/(a*b))/b)))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, bisect_left(L,L[a]+L[b])):
            cnt += 1
print(cnt)

Fixed submission:
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        cnt += bisect_left(L,L[a]+L[b])-(b+1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, bisect_left(L,L[a]+L[b])):
            if L[c]>=L[a]+L[b]:
                break
            else:
                cnt += 1
print(cnt)

Fixed submission:
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        cnt += bisect_left(L,L[a]+L[b])-(b+1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, n):
            if L[c]>=L[a]+L[b]:
                break
            else:
                cnt += 1
print(cnt)

Fixed submission:
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        cnt += bisect_left(L,L[a]+L[b])-(b+1)
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

cnt = 0
t_cnt = 1
tmp = ''
for i in range(len(s)):
    if tmp==s[i]:
        t_cnt += 1
    else:
        cnt += t_cnt//2
        tmp = s[i]
        t_cnt = 1
cnt += t_cnt//2

top_cnt = 0
char = s[0]
for i in range(len(s)):
    if char == s[i]:
        top_cnt += 1
    else:
        break

bottom_cnt = 0
char = s[-1]
for i in range(1, len(s)+1):
    if char == s[-i]:
        bottom_cnt += 1
    else:
        break
        
if set(s)==1:
    print(len(s)*k//2)
else:
    if s[1]!=s[-1]:
        print(cnt*k)
    else:
        print(cnt*k-(top_cnt//2+bottom_cnt//2-(top_cnt+bottom_cnt)//2)*(k-1))

Fixed submission:
s = input()
k = int(input())

tmp = 1
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1
count += tmp//2

if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//2)*(k-1))
Buggy python submission (verdict: Runtime Error):
S = ['Sunny', 'Cloudy', 'Rainy']
today = input()
prnit(S[(S.index(today)+1)%3])

Fixed submission:
S = ['Sunny', 'Cloudy', 'Rainy']
today = input()
print(S[(S.index(today)+1)%3])
Buggy python submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
A = [k-q]*n
for i in range(q):
    ans = int(input())
    A[ans] += 1
for i in A:
    print('Yes' if i>0 else 'No')

Fixed submission:
N, K, Q = map(int, input().split())
points = [K-Q]*N
for i in range(Q):
    points[int(input())-1] += 1

for p in points:
    print('Yes' if p>0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
for i in range(m):
    A[A.index(max(A))] /= 2
print(sum([int(a) for a in A]))

Fixed submission:
import heapq
n, m = map(int, input().split())
A = list(map(lambda x:-x, map(int, input().split())))
heapq.heapify(A)
for i in range(m):
    mx = heapq.heappop(A)
    heapq.heappush(A,mx/2)
print(sum([int(-a) for a in A]))
Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in s]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

Fixed submission:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
S = []
r = -n
for i in range(n):
    s = Counter(input())
    S.append(s)
    r += S.count(s)
print(r)

Fixed submission:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
H = [int(i) for i in input().split()]

mi = -1
for i in range(n):
    if mi < H[i]:
        mi = H[i] - 1
    elif mi > H[i]:
        print('No')
        sys.exit()
print('Yes')

Fixed submission:
n = int(input())
H = [int(i) for i in input().split()]

mi = -1
rs = 'Yes'
for i in range(n):
    if mi < H[i]:
        mi = H[i] - 1
    elif mi > H[i]:
        rs = 'No'
        break
print(rs)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = []
for i in range(1, n+1):
    A.append(int(input()))
for i in range(n):
    print(max(list(list(A[:i])+list(A[i+1:]))))

Fixed submission:
n = int(input())
A = []
for i in range(1, n+1):
    A.append(int(input()))
A_srt = sorted(A)
A1, A2 = A_srt[-1], A_srt[-2]
for i in A:
    if i == A1:
        print(A2)
    else:
        print(A1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
XY.sort(key=lambda x: x[0], reverse=True)
dXY = Counter([])
for i in range(n-1):
    for j in range(i+1,n):
        dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
print(n-dXY.most_common()[0][1])

Fixed submission:
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
dXY = Counter([])
for i in range(n):
    for j in range(n):
        if i!=j:
            dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
if n==1:
    print(1)
else:
    print(n-dXY.most_common()[0][1])

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
XY.sort(key=lambda x: x[0], reverse=True)
dXY = Counter([])
for i in range(n-1):
    for j in range(1,n):
        dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
print(n-dXY.most_common()[0][1])

Fixed submission:
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
dXY = Counter([])
for i in range(n):
    for j in range(n):
        if i!=j:
            dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
if n==1:
    print(1)
else:
    print(n-dXY.most_common()[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
S = [[] for _ in range(h)]
for i in range(h):
    S[i] = list(input())

ans = 0
L = [[0]*w for _ in range(h)]
for hi in range(h):
    cnt = 1
    for wi in range(w):
        if S[hi][wi]=='#':
            L[hi][wi] = 0
            cnt = 1
        else:
            L[hi][wi] = cnt
            cnt += 1

R = [[0]*w for _ in range(h)]
for hi in range(h):
    cnt = 1
    for wi in range(w):
        if S[hi][w-wi-1]=='#':
            R[hi][w-wi-1] = 0
            cnt = 1
        else:
            R[hi][w-wi-1] = cnt
            cnt += 1

D = [[0]*w for _ in range(h)]
for wi in range(w):
    cnt = 1
    for hi in range(h):
        if S[hi][wi]=='#':
            D[hi][wi] = 0
            cnt = 1
        else:
            D[hi][wi] = cnt
            cnt += 1

U = [[0]*w for _ in range(h)]
for wi in range(w):
    cnt = 1
    for hi in range(h):
        if S[h-hi-1][wi] == '#':
            U[h-hi-1][wi] = 0
            cnt = 1
        else:
            U[h-hi-1][wi] = cnt
            cnt += 1

ans = 0
for hi in range(h):
    for wi in range(w):
        ans = max(ans, L[hi][wi]+R[hi][wi]+D[hi][wi]+U[hi][wi]-3)
print(ans)

Fixed submission:
h, w = map(int, input().split())
S = [[] for _ in range(h)]
for i in range(h):
    S[i] = list(input())

ans = 0
L = [[0]*w for _ in range(h)]
for hi in range(h):
    cnt = 1
    for wi in range(w):
        if S[hi][wi]=='#':
            L[hi][wi] = 0
            cnt = 1
        else:
            L[hi][wi] = cnt
            cnt += 1

R = [[0]*w for _ in range(h)]
for hi in range(h):
    cnt = 1
    for wi in range(w):
        if S[hi][w-wi-1]=='#':
            R[hi][w-wi-1] = 0
            cnt = 1
        else:
            R[hi][w-wi-1] = cnt
            cnt += 1

D = [[0]*w for _ in range(h)]
for wi in range(w):
    cnt = 1
    for hi in range(h):
        if S[hi][wi]=='#':
            D[hi][wi] = 0
            cnt = 1
        else:
            D[hi][wi] = cnt
            cnt += 1

U = [[0]*w for _ in range(h)]
for wi in range(w):
    cnt = 1
    for hi in range(h):
        if S[h-hi-1][wi] == '#':
            U[h-hi-1][wi] = 0
            cnt = 1
        else:
            U[h-hi-1][wi] = cnt
            cnt += 1

ans = 0
for hi in range(h):
    for wi in range(w):
        ans = max(ans, L[hi][wi]+R[hi][wi]+D[hi][wi]+U[hi][wi]-3)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
a1, a2, a3 = sorted([r, g, b])

r = 0
I = n//a3+1
J = n//a2+1
for i in range(I):
    for j in range(J):
        t = n-i*a3-j*a2
        if t>=0 and t%a1==0:
            r += 1
print(r)

Fixed submission:
r, g, b, n = map(int, input().split())
a1, a2, a3 = sorted([r, g, b])

r = 0
I = n//a3+1
for i in range(I):
    for j in range((n-i)//a2+1):
        t = n-i*a3-j*a2
        if t>=0 and t%a1==0:
            r += 1
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]
V = [[-1]*w for _ in range(h)]
que = deque([])
for i,a in enumerate(A):
    for j,_a in enumerate(a):
        if _a == '#':
            que.append([i,j])
            V[i][j] = 0
dhdw = [[-1,0],[1,0],[0,-1],[0,1]]
while que:
    nwh,nww = que.popleft()
    for dh, dw in dhdw:
        if not (0<=nwh+dh<h and 0<=nww+dw<w): continue
        if V[nwh+dh][nww+dw] != -1: continue
        V[nwh+dh][nww+dw] = V[nwh][nww]+1
        que.append([nwh+dh, nww+dw])
print(max(map(max, V)))

Fixed submission:
from collections import deque
h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]
V = [[-1]*w for _ in range(h)]
que = deque([])
for i,a in enumerate(A):
    for j,_a in enumerate(a):
        if _a == '#':
            que.append([i,j])
            V[i][j] = 0
dhdw = [[-1,0],[1,0],[0,-1],[0,1]]
while que:
    nwh,nww = que.popleft()
    for dh, dw in dhdw:
        if not (0<=nwh+dh<h and 0<=nww+dw<w): continue
        if V[nwh+dh][nww+dw] != -1: continue
        V[nwh+dh][nww+dw] = V[nwh][nww]+1
        que.append([nwh+dh, nww+dw])
print(max(map(max, V)))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
countS = [0]*n
for i in range(n-1):
    countS[i+1] = countS[i]
    if s[i]=='A' and s[i+1]=='C':
        countS[i+1] += 1

for i in range(q):
    l, r = map(int, input().split())
    print(countS[r-1]-countS[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
r = 0
while True:
    z = s.count('01')
    o = s.count('10')
    if z+o == 0:
        break
    elif z > o:
        s = s.replace('01', '')
        r += z
    else:
        s = s.replace('10', '')
        r += o
print(2*r)

Fixed submission:
s = input()
print(2*min(s.count('0'), s.count('1')))
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
A = [int(sys.stdin.readline()) for _ in range(n)]
print("second" if all(a[i]%2==0 for i in range(n)) else 'first')

Fixed submission:
import sys
n = int(input())
A = [int(sys.stdin.readline()) for _ in range(n)]
print("second" if all(A[i]%2==0 for i in range(n)) else 'first')
Buggy python submission (verdict: Runtime Error):
print(TODO)

Fixed submission:
s = input()
r = 0
c = 0
for i in range(len(s)):
    if s[i]=='B':
        c += 1
    else:
        r += c
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = n-1
for i in range(n):
    ans = min(ans, s[:i].count('W')+s[i:].count('E'))
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = n-1
r = s.count('E')
for i in range(n):
    if s[i] == 'E':
        r -= 1
    ans = min(ans, r)
    if s[i] == 'W':
        r += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline
n, m = map(int, readline().split())
P = list(map(lambda x:int(x)-1, readline().split()))
G = [set() for _ in range(n)]
for i in range(m):
    x, y = map(lambda x:int(x)-1, readline().split())
    G[x].add(y)
    G[y].add(x)

D = {}
cnt = 0
V = [-1]*n
while -1 in V:
    st = V.index(-1)
    que = deque([st])
    V[st] = cnt
    D[cnt] = set([P[st]])
    while que:
        nw = que.popleft()
        for nx in G[nw]:
            if V[nx] != -1: continue
            D[cnt].add(P[nx])
            V[nx] = cnt
            que.append(nx)
    cnt += 1
print(sum([int(i in D[V[i]]) for i in range(n)]))

Fixed submission:
S = input()
k = int(input())
ans = set()
for i in range(len(S)):
    for j in range(1,k+1):
        ans.add(S[i:i+j])
print(sorted(ans)[k-1])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
S = ['']*h
for i in range(h):
    S[i] = input()

r = 'Yes'
for i in range(1, w-1):
    for j in range(1, h-1):
        if S[i][j]=='#':
            if S[i-1][j]=='.' and S[i+1][j]=='.' or S[i][j-1]=='.' or S[i][j+1]=='.':
                r = 'No'
                break
print(r)

Fixed submission:
h, w =map(int,input().split())
S=["."+input()+"." for i in range(h)]
S=["."*(w+2)]+S+["."*(w+2)]
r = 'Yes'
for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                r = 'No'
                break
print(r)

Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
S = ['']*h
for i in range(h):
    S[i] = input()

r = 'Yes'
for i in range(1, w-1):
    for j in range(1, h-1):
        if S[i][j]=='#':
            if S[i-1][j]=='#' or S[i+1][j]=='#' or S[i][j-1]=='#' or S[i][j+1]=='#':
                continue
            else:
                r = 'No'
print(r)

Fixed submission:
h, w =map(int,input().split())
S=["."+input()+"." for i in range(h)]
S=["."*(w+2)]+S+["."*(w+2)]
r = 'Yes'
for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                r = 'No'
                break
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)
mi = (n-1)//2
for i in range(n):
    X_ = X_sort.copy()
    X_.remove(X[i])
    print(X_[mi])

Fixed submission:
n = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)
xm1 = X_sort[n//2-1]
xm2 = X_sort[n//2]
xm = (xm1+xm2)/2
for i in range(n):
    if X[i]<xm:
        print(xm2)
    else:
        print(xm1)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial as fac
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
t = 0
mxf = fac(mx)
for a in A:
    _t = mxf // (fac(mx-a)*fac(a))
    if t < _t:
        t = _t
        mn = a
    else:
        break
print(mx, mn)

Fixed submission:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A[1:]:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)
Buggy python submission (verdict: Time Limit Exceeded):
def valid():
    s = input()
    if s=='Vacant': exit()
    return 1 if s=='Male' else 0

n = int(input())
print(0, flush=True)
s_l = valid()
lidx = 0
ridx = n

while True:
    midx = (l+r)//2
    print(midx, flush=True)
    s_m = valid()
    if ((midx-lidx)%2==1) ^ (s_l==s_m):
        lidx = midx
        sl = sm
    else:
        ridx = midx

Fixed submission:
import sys
def valid():
    s = input()
    if s=='Vacant':
        sys.exit()
    return 1 if s=='Male' else 0

n = int(input())
print(0, flush=True)
s_l = valid()
lidx = 0
ridx = n

while True:
    midx = (lidx+ridx)//2
    print(midx, flush=True)
    s_m = valid()
    if ((midx-lidx)%2==1) ^ (s_l==s_m):
        lidx = midx
        s_l = s_m
    else:
        ridx = midx

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(0, flush=True)
s_st = input()
i_st = 0
if s=='Vacant': exit()
print(n-1, flush=True)
s_en = input()
i_en = n-1
if s=='Vacant': exit()
for _ in range(20)
    print((i_st+i_en)//2, flush=True)
    s_md = input()
    if s_md=='Vacant': exit()
    if (n-1)//2%2==0 and s_st!=s_md:
        i_en = (i_st+i_en)//2
    else:
        i_st = (i_st+i_en)//2
        s_st = s_md

Fixed submission:
import sys
def valid():
    s = input()
    if s=='Vacant':
        sys.exit()
    return 1 if s=='Male' else 0

n = int(input())
print(0, flush=True)
s_l = valid()
lidx = 0
ridx = n

while True:
    midx = (lidx+ridx)//2
    print(midx, flush=True)
    s_m = valid()
    if ((midx-lidx)%2==1) ^ (s_l==s_m):
        lidx = midx
        s_l = s_m
    else:
        ridx = midx

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(0)
s_st = input()
i_st = 0
if s=='Vacant': exit()
print(n-1)
s_en = input()
i_en = n-1
if s=='Vacant': exit()
for _ in range(20)
    print((i_st+i_en)//2)
    s_md = input()
    if s_md=='Vacant': exit()
    if (n-1)//2%2==0 and s_st!=s_md:
        i_en = (i_st+i_en)//2
    else:
        i_st = (i_st+i_en)//2
        s_st = s_md

Fixed submission:
import sys
def valid():
    s = input()
    if s=='Vacant':
        sys.exit()
    return 1 if s=='Male' else 0

n = int(input())
print(0, flush=True)
s_l = valid()
lidx = 0
ridx = n

while True:
    midx = (lidx+ridx)//2
    print(midx, flush=True)
    s_m = valid()
    if ((midx-lidx)%2==1) ^ (s_l==s_m):
        lidx = midx
        s_l = s_m
    else:
        ridx = midx
Buggy python submission (verdict: Time Limit Exceeded):
import math
def eraP(n):
    if n<=1: return [False]*(n+1)
    elif n<=2: return [False, False, True]
    L = [False if i%2==0 or i%3==0 else True for i in range(n)]
    L[0] = False; L[1] = False;
    L[2] = True; L[3] = True; L[5]=True
    limit = math.sqrt(n)
    for i in range(3,n,2):
        if i >= limit: return L
        for s in range(i**2,n,i):
            L[s] = False
    return L

q = int(input())
rmax = 0
L = [0]*q
R = [0]*q
for i in range(q):
    l, r = map(int, input().split())
    L[i], R[i] = l, r
    rmax = max(r,rmax)
P = eraP(rmax+1)

for i in range(q):
    tmp = 0
    for j in range(L[i],R[i]+1):
        if P[j] and P[(j+1)//2]:
            tmp += 1
    print(tmp)

Fixed submission:
import math
def eraP(n):
    if n<=1: return [False]*(n+1)
    elif n<=2: return [False, False, True]
    L = [False if i%2==0 or i%3==0 else True for i in range(n)]
    L[0] = False; L[1] = False;
    L[2] = True; L[3] = True; L[5]=True
    limit = math.sqrt(n)
    for i in range(3,n,2):
        if i >= limit: return L
        for s in range(i**2,n,i):
            L[s] = False
    return L

q = int(input())
LR = [[0,0] for _ in range(q)]
for i in range(q):
    LR[i] = list(map(int, input().split()))
P = eraP(pow(10,5)+1)[1:]

sumP = [0,0,0]
for i in range(2,pow(10,5)):
    sumP.append(sumP[-1]+int(P[i] and P[(i+1)//2]))

for lr in LR:
    print(sumP[lr[1]]-sumP[lr[0]-1])
Buggy python submission (verdict: Runtime Error):
s = sorted(input())
t = sorted(input(), reverse=True)
alf = 'abcdefghijklmnopqrstuvwxyz'
r = 'No'
if len(s)<len(t) and s==t[len(s):]:
    r = 'Yes'
for i in range(len(s)):
    si = alf.index(s[i])
    ti = alf.index(t[i])
    if si < ti:
        r = 'Yes'
        break
    elif si == ti:
        continue
    else:
        break
print(r)

Fixed submission:
s = input()
t = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
r = 'No'
if len(s)<len(t) and s==t[:len(s)]:
    r = 'Yes'

s = sorted(s)
t = sorted(t, reverse=True)
for i in range(min(len(s),len(t))):
    si = alf.index(s[i])
    ti = alf.index(t[i])
    if si < ti:
        r = 'Yes'
        break
    elif si == ti:
        continue
    else:
        break
print(r)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
F = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
P = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ans = 0
for i in range(1,pow(2,10)):
    b = bin(i)[2:].zfill(10)
    t = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if int(b[k]) and F[j][k]:
                c += 1
        a += P[j][c]
    ans = max(ans, a)
print(ans)

Fixed submission:
import sys
n = int(input())
F = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
P = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ans = -pow(10,9)-7
for i in range(1,pow(2,10)):
    b = bin(i)[2:].zfill(10)
    t = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if int(b[k]) and F[j][k]:
                c += 1
        t += P[j][c]
    ans = max(ans, t)
print(ans)