Problem p03201 (python)

Fixed submission:
#AGC030 B - Powers of two
import collections
import math
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for a in A:
    inv=2**(int(math.log2(a))+1)
    if cnter[a]==0:
        continue
    if inv==2*a and cnter[inv-a]<=1:
      	continue
    if cnter[inv-a]>0:
        cnter[inv-a]=cnter[inv-a]-1
        cnter[a]=cnter[a]-1
        ans=ans+1
print(ans)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
import collections
import math
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for a in A:
    inv=2**(int(math.log2(a))+1)
    if cnter[a]==0:
        continue
    if cnter[a]>=2 and a==inv//2:a
        cnter[a]=cnter[a]-2
        ans=ans+1
        continue
    if inv-a in cnter:
        cnter[inv-a]=cnter[inv-a]-1
        ans=ans+1
print(ans)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
import collections
import math
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for a in A:
    inv=2**(int(math.log2(a))+1)
    if cnter[a]==0:
        continue
    if cnter[a]>=2 and a==inv//2:a
        cnter[a]=cnter[a]-2
        ans=ans+1
        continue
    if inv-a in cnter:
        cnter[inv-a]=cnter[inv-a]-1
        ans=ans+1
print(ans)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
import collections
import math
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for a in A:
    inv=2**(int(math.log2(a))+1)
    if cnter[a]==0:
        continue
    if cnter[a]>=2 and a=inv//2:
        cnter[a]=cnter[a]-2
        ans=ans+1
        continue
    if inv-a in cnter:
        cnter[inv-a]=cnter[inv-a]-1
        ans=ans+1
print(ans)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
import collections
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for i in (reversed(beki)):
    for a in A:
        if (i//2<a<i and (i-a in cnter) )or(i//2==a and cnter[a]>=2):
            ans=ans+1
            A.remove(i-a)
print((N-len(A))//2)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
import collections
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=map(int,input().split())
A.sorted(reverse=True)
cnter=collections.Counter(A)
ans=0
for i in (reversed(beki)):
    for a in A:
        if (i//2<a<i and (i-a in cnter) )or(i//2==a and cnter[a]>=2):
            ans=ans+1
            A.remove(i-a)
print((N-len(A))//2)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
import copy
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=input().split()
for i in range(N):
    A[i]=int(A[i])
for i in (reversed(beki)):
    B=copy.deepcopy(A)
    for j in B:
        if i//2<j<i:
            if i-j in B:
                A.remove(i-j)
                A.remove(j)
        if j==i//2:
            if B.count(j)>=2:
                A.remove(j)
                A.remove(j)
print((N-len(A))//2)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=input().split()
for i in range(N):
    A[i]=int(A[i])
sorted(A)#Aを昇順にソート
for i in (reversed(beki)):
    B=A
    for j in B:
        if j==i/2 and B.count(j)=>2:
            A.remove(j)
            A.remove(j)
        if i-j in A:
            A.remove(j)
            A.remove(i-j)
print((N-len(A))//2)

Buggy submission (verdict: Runtime Error):
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
def tasitekesu(data,n):#dataの中で足したらnになるやつを消し、消した結果とペア数を報告する
    result=[]
    kosu=0
    for i in range(len(data)):
        if i in result:
            continue
        for j in range(i):
            if j in result:
                continue
            if data[i]+data[j]==n:
                result.append(i)
                result.append(j)
                kosu=kosu+1
                break
    result.sort(reverse=True)
    for i in result:
        del data[i]
    return [data,kosu]

N=int(input())
A=input().split()
ans=0
for i in range(N):
    A[i]=int(A[i])
sorted(A)#Aを昇順にソート
for i in (reversed(beki)):
    kesi=[]
    for j in range(len(A)):
        if j==len(A):
            break
        if i-A[j] in A:
            A.remove(i-A[j])
            kesi.append(j)
            ans=ans+1
    for j in (reversed(kesi)):
        A.pop(j)
print(ans)