Problem p03201 (python)

Fixed submission:
import collections
import bisect
n= int(input())
a=list(map(int, input().split()))
c=collections.Counter(a)
ans=0
des=sorted(a,reverse=True)
# asc=sorted(a)

for i in des:
    if c[i]>0:
        bi=format(i, 'b')
        x=2**len(bi)-i
        c[i]-=1
        if c[x]>0:
            c[x]-=1
            ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import copy
import bisect

def index(a, x):
    i = bisect.bisect_right(a, x)
    a.reverse()
    if i != len(a) and a[i] == x:
        return i
    return -1
    
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
ano_a=copy.copy(a)
ano_a.sort()
for i in range(n):
    if a[i]:
        bi=format(a[i], 'b')
        x=2**len(bi)-a[i]
        c=index(ano_a,x)
        if x==a[i] and a[i+1]==x:
            ans+=1
            a[i]=None
            a[c]=None
        elif c>=0:
            if x!=a[i]:
                ans+=1
                a[c]=None
                a[i]=None
print(ans)

Buggy submission (verdict: Runtime Error):
import copy
import bisect

def index(a, x):
    i = bisect.bisect_right(a, x)
    a.reverse()
    if i != len(a) and a[i] == x:
        return i
    return -1
    
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
ano_a=copy.copy(a)
ano_a.sort()
for i in range(n):
    if a[i]:
        bi=format(a[i], 'b')
        x=2**len(bi)-a[i]
        c=index(ano_a,x)
        if x==a[i] and a[i+1]==x:
            ans+=1
            a[i]=None
            a[c]=None
        elif c>=0:
            if x!=a[i]:
                ans+=1
                a[c]=None
                a[i]=None
print(ans)

Buggy submission (verdict: Runtime Error):
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return mid


n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for i in range(n-1):
    if a[i]:
        bi=format(a[i], 'b')
        x=2**len(bi)-a[i]
        if a[i]==x and a[i+1]==x:
            ans+=1
            a[i]=None
            c=binary_search(a,x)
            a[c]=None
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for i in range(n):
    if a[i]:
        bi=format(a[i], 'b')
        x=2**len(bi)-a[i]
        if a[i]==x and a[i+1]==x:
            ans+=1
            a[i]=None
            a[a.index(x)]=None
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for i in range(n):
    if a[i]:
        bi=format(a[i], 'b')
        x=2**len(bi)-a[i]
        if a[i]==x and a[i+1]==x:
            ans+=1
            a[i]=None
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for i in range(n):
    if a[i]:
        bi=format(a[i], 'b')
        x=2**len(bi)-a[i]
        if a[i]==x and a[i+1]==x:
            ans+=1
            a[i]=None
            a[a.index(x)]=None
        elif x in a and x!=a[i]:
            ans+=1
            a[a.index(x)]=None
            a[i]=None
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for b in a:
    if b:
        bi=format(b, 'b')
        x=2**len(bi)-b
        if x==b and a.count(x)>1:
            ans+=1
            b=None
            a[a.index(x)]=None
        else:
            ans+=1
            a[a.index(x)]=None
            b=None
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for b in a:
    if b:
        bi=format(b, 'b')
        x=2**len(bi)-b
        if x==b and a.count(x)>1:
            ans+=1
            b=None
            a[a.index(x)]=None
        elif x!=b:
            ans+=1
            a[a.index(x)]=None
            b=None
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for b in a:
    if b:
        bi=format(b, 'b')
        x=2**len(bi)-b
        if x==b and a.count(x)>1:
            ans+=1
            b=None
            a[a.index(x)]=None
        elif 1>0 and x!=b:
            ans+=1
            a[a.index(x)]=None
            b=None
print(ans)