ZhenlongDai/ACPR huggingface dataset:
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        k=a.bit_length()
        d=(1<<k)-a
        if(a!=d):
            if(D[d]):
                ans+=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=1
    print(ans)
resolve()

Failing test case input:
5
3 11 14 5 1

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        if(D[a]==0): continue
        k=a.bit_length()
        d=(1<<k)-a
        if(a!=d):
            if(D[d]):
                ans+=1
                D[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    print(ans)
resolve()

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import Counter
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    t = 0
    while True:
        t += 1
        m = 1<<t
        if m > 10**9: break
        M = [a % m for a in A]
        C = Counter(M)
        tmp = 0
        for k,v in C.items():
            if k*k == m:
                tmp += v*(v-1)
                continue
            tmp += v * C[m-k]
        ans += tmp
    print(ans)


if __name__ == '__main__':
    main()

Failing test case input:
5
3 36 3 10 15

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import Counter
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    A.sort(reverse=True)
    C = Counter(A)
    for a in A:
        if C[a] == 0: continue
        C[a] -= 1
        p = (1 << a.bit_length()) - a
        if p in C and C[p] > 0:
            ans += 1
            C[p] -= 1
    print(ans)

if __name__ == '__main__':
    main()
Problem: p03201
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline









N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) 

import heapq as hq
balls_q = [] 

for a in A:
  balls_count[a] += 1
  hq.heappush(balls_q, -a)

def get_pair_num(x): 
  tar = 2
  while tar < x:
    tar *= 2
  return tar - x

ans = 0
while balls_q:
  ball = hq.heappop(balls_q)
  if balls_count[-ball] == 0: 
    continue
  
  
  balls_count[-ball] -= 1
  pair = get_pair_num(-ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1
  

print(ans)

Failing test case input:
5
2 3 2 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline









N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) 

import heapq as hq
balls_q = [] 

for a in A:
  balls_count[a] += 1
  hq.heappush(balls_q, -a)

def get_pair_num(x): 
  tar = 2
  while tar < x:
    tar *= 2
  if tar == x:
    return tar
  return tar - x

ans = 0
while balls_q:
  ball = -(hq.heappop(balls_q))
  if balls_count[ball] == 0: 
    continue
  
  
  balls_count[ball] -= 1
  pair = get_pair_num(ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1
  

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=7
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 0:
    continue
  c[target]-= 1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys() and c[pair] > 0:
    c[pair]-= 1
    pairCounter+=1

print(pairCounter)

Failing test case input:
5
2 6 25 3 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):

import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=29
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 1:
    continue
  c[target]-= 1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys() and c[pair] > 0:
    c[pair]-= 1
    pairCounter+=1

print(pairCounter)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  x=reversed_num(number[-1])+1
  if x in number and x!=number[-1]:
    number.remove(x)
    count+=1
  number.pop()
print(count)

Failing test case input:
5
3 24 16 16 13

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans =0
for a in A:
    b = 2**(a.bit_length())-a
    if b in d:
        if d[b] >=1 and d[a] >= 1:
            ans += 1 
            d[b]-= 1
            d[a]-= 1

print(ans)
            

Failing test case input:
5
1 34 26 10 25

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans =0
for a in A:
    b = 2**(a.bit_length())-a
    if b in d:
        if d[b] >=1 and d[a] >= 1:
          if a == b and d[b] ==1:
            continue
          ans += 1 
          d[b]-= 1
          d[a]-= 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans =0
for a in A:
    b = 2**(a.bit_length())-a
    if b in d:
        if d[b] >=1:
          if a == b and d[b] ==1:
            continue
          ans += 1 
          d[b]-= 1
          d[a]-= 1

print(ans)
            

Failing test case input:
5
3 4 1 14 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans =0
for a in A:
    b = 2**(a.bit_length())-a
    if b in d:
        if d[b] >=1 and d[a] >= 1:
          if a == b and d[b] ==1:
            continue
          ans += 1 
          d[b]-= 1
          d[a]-= 1

print(ans)
Problem: p03201
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
A.sort()
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  
  
from functools import lru_cache





import bisect as bi
Q=deque(A)
rui=[pow(2,i) for i in range(31)]
ans=0
C=Counter(A)
N={ i:0 for i in C.keys() }
while Q:
    k=Q.pop()
    for r2 in rui:
        if N.get(r2-k,None)==None:continue
        if N[r2-k] >= C[r2-k]: continue
        N[r2-k]+=1;N[k]+=1;ans+=1

print(ans)


Failing test case input:
5
1 3 45 6 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
A=list(map(int,input().split()))
A.sort()
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  
  
from functools import lru_cache





import bisect as bi
Q=deque(A)
rui=[pow(2,i) for i in range(31)]
ans=0
C=Counter(A)

while Q:
    k=Q.pop()
    if C[k]==0:continue
    for r2 in rui:
        if r2>2*k:break
        if C.get(r2-k,None)==None:continue
        if r2-k==k: 
            if C[k]<=1:continue
        if C[r2-k]==0: continue
        C[r2-k]-=1;C[k]-=1;ans+=1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int, input().split()))

A.sort(reverse=True)
dic={}
for a in A:
    dic[a]=dic.get(a,0)+1
print(dic)

ans=0

for a in A:
    small=(1<<(len(format(a,"b")))) -a
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a]-=1
        dic[small]-=1
        ans+=1
print(ans)

Failing test case input:
5
3 24 14 10 13

Expected output:
1


Actual output:
{24: 1, 14: 1, 13: 1, 10: 1, 3: 1}
1


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int, input().split()))

A.sort(reverse=True)
dic={}
for a in A:
    dic[a]=dic.get(a,0)+1

ans=0

for a in A:
    small=(1<<(len(format(a,"b")))) -a
    if small==a:
        if dic[a]>=2:
            dic[a]-=2
            ans+=1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a]-=1
        dic[small]-=1
        ans+=1
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import *
N = int(input())
A = list(map(int, input().split()))
A.sort()
s = set()
ans = 0
for i in range(N):
    if N-i-1 in s:
        continue
    a = A[N-i-1]
    for j in range(32):
        if a&(1<<(31-j)):
            b = 1<<(32-j)
            break
    k = bisect_left(A[:N-i-1], b-a)
    if k < N-i-1 and b-a == A[k]:
        s.add(k)
        ans += 1
print(ans)
    


Failing test case input:
5
2 3 24 6 14

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import *
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = 0
for i in range(N):
    a = A[N-i-1]
    if C[a] == 0:
        continue
    b = pow(2, a.bit_length())
    if C[b-a]-((a<<1) == b) > 0:
        C[a] -= 1
        C[b-a] -= 1
        ans += 1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=1
    else:
        D[A[i]]+=1
ans=0
for i in range(N):
    if D[A[i]]==0:
        continue
    if B[i]==2*A[i]:
        if D[A[i]]>=2:
            D[A[i]]-=2
            ans+=1
    else:
        if (B[i]-A[i]) in D:
            D[A[i]]-=1
            D[B[i]-A[i]]-=1
            ans+=1
print(ans)



Failing test case input:
5
2 6 24 6 16

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=1
    else:
        D[A[i]]+=1
ans=0
for i in range(N):
    if D[A[i]]<=0:
        continue
    if B[i]==2*A[i]:
        if D[A[i]]>=2:
            D[A[i]]-=2
            ans+=1
    else:
        if (B[i]-A[i]) in D:
            if D[B[i]-A[i]]!=0:
                D[A[i]]-=1
                D[B[i]-A[i]]-=1
                ans+=1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
d = dict()
u = dict()
ans = 0
a.sort(reverse=True)

for x in a:
  if x not in d:
    d[x] = 0
  d[x] += 1
  
for x in a:
  d[x] -= 1
  if u.get(x,0):
    u[x] -= 1
    continue
  p = (1<<x.bit_length()) - x
  if d.get(p,0):
    d[p] -= 1
    u[p] = u.get(p,0) + 1
    ans += 1

print(ans)

Failing test case input:
5
2 2 1 5 6

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
d = dict()
ans = 0
for x in a:
  if x not in d:
    d[x] = 0
  d[x] += 1
for x in a:
  t = (1<<x.bit_length()) - x
  f = (d.get(t,0) and d.get(x,0))
  if t == x:
    f = (d.get(t,0) >= 2)
  if f:
    d[x] -= 1
    d[t] -= 1
    ans += 1
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ca = Counter(a)

ans = 0
for item in a[::-1]:
    for i in range(19, 0, -1):
        inv = (1 << i) - item
        if inv < 0:
            continue
        if ca[inv] > 0 and item != inv:
            ans += 1 
            ca[inv] -=1
            ca[item] -=1
            break
        if ca[inv] > 1 and item == inv:
            ans += 1 
            ca[inv] -= 2
            break
print(ans)

Failing test case input:
5
1 3 82 6 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ca = Counter(a)
max_a = a[-1] 

ans = 0
for item in a[::-1]:
    if ca[item] == 0:
        continue
    for i in range(31, 0, -1):
        inv = (1 << i) - item
        if inv < 0 or inv > max_a:
            continue
        if item == inv:
            if ca[inv] > 1:
                ans += 1 
                ca[inv] -= 2
                break
        else:
            if ca[inv] > 0:
                ans += 1 
                ca[inv] -=1
                ca[item] -=1
                break
print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import Counter
size_a = int(input())
a = Counter(int(x) for x in input().split())
keys = list(a.keys())
keys.sort()
pair_cnt = 0
print(a)
while size_a >= 2:
    x = keys[-1]
    if a[x] == 0:
        keys.pop()
        continue
    print('search', x, a[x])
    a[x] -= 1
    size_a -= 1
    if a[x] == 0:
        keys.pop()
    b = 2 ** x.bit_length() - x
    if a[b] > 0:
        a[b] -= 1
        size_a -= 1
        if a[b] == 0:
            del a[b]
        pair_cnt += 1
        print('found')
print(pair_cnt)

Failing test case input:
5
3 36 18 14 13

Expected output:
2


Actual output:
Counter({3: 1, 36: 1, 18: 1, 14: 1, 13: 1})
search 36 1
search 18 1
found
search 13 1
found
2


Fixed submission (verdict: Accepted):
from collections import Counter
size_a = int(input())
a = Counter(int(x) for x in input().split())
keys = list(a.keys())
keys.sort()
pair_cnt = 0
while size_a >= 2:
    x = keys[-1]
    if a[x] == 0:
        keys.pop()
        continue
    a[x] -= 1
    size_a -= 1
    if a[x] == 0:
        keys.pop()
    b = 2 ** x.bit_length() - x
    if a[b] > 0:
        a[b] -= 1
        size_a -= 1
        if a[b] == 0:
            del a[b]
        pair_cnt += 1
print(pair_cnt)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):







from collections import Counter

n = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
print(c)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


while bool(c):
    m = list(c.elements())[0]
    n = pow2(m) - m
    print(m, n)
    c[m] -= 1
    c += Counter()
    if n in c:
        c[n] -= 1
        ans += 1
    c += Counter()

print(ans)








Failing test case input:
5
3 24 14 5 13

Expected output:
1


Actual output:
Counter({24: 1, 14: 1, 13: 1, 5: 1, 3: 1})
24 8
14 2
13 3
5 3
1


Fixed submission (verdict: Accepted):







from collections import Counter

nn = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    while c[ali[ii]] == 0:
        ii += 1
    m = ali[ii]
    n = pow2(m) - m
    c[m] -= 1
    if c[m] <= 0:
        del c[m]
    if n in c:
        c[n] -= 1
        if c[n] <= 0:
            del c[n]
        ans += 1

print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict

def twosum(n):
  now = 2
  while n > now:
    now *= 2
  return now - n
n = int(input())
a = sorted(list(map(int, input().split())))
d = defaultdict(int)
for i in a:
  d[i] += 1
ans = 0
for i in a[::-1]:
  find = twosum(i)
  if d[find] > 0 and d[i] > 0:
    ans += 1
    d[i] -= 1
    d[find] -= 1
print(ans)

Failing test case input:
5
3 4 1 14 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n = int(input())
a = sorted(list(map(int, input().split())))
d = defaultdict(int)
for i in a:
  d[i] += 1
ans = 0
for i in a[::-1]:
  d[i] -= 1
  find = twosum(i)
  if d[find] > 0 and d[i] >= 0:
    ans += 1
    d[find] -= 1
  else:
    d[i] += 1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a+1,"b")))) - a
    if dic.get(a,0)>0:
        dic[a] -= 1
    if dic.get(small,0)>0:
        dic[small] -= 1
        ans += 1
print(ans)


Failing test case input:
5
3 11 14 10 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a,"b")))) - a
    if small == a:
        if dic[a] >= 2:
            dic[a] -= 2
            ans += 1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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

print(ans)



Failing test case input:
5
3 24 22 5 16

Expected output:
1


Actual output:
0


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


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)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  if (number[-1]!=reversed_num(number[-1])+1) and (reversed_num(number[-1])+1 in number):
    number.remove(reversed_num(number[-1])+1)
    count+=1
  number.pop(-1)
print(count)


Failing test case input:
5
2 20 16 16 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  if reversed_num(number[-1])+1 in number and number[-1]!=reversed_num(number[-1])+1:
    number.remove(reversed_num(number[-1])+1)
    count+=1
  number.pop()
print(count)


Failing test case input:
5
4 3 4 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  x=reversed_num(number[-1])+1
  if x!=number[-1]:
    number.pop()
    if x in number:
      number.remove(x)
      count+=1
  else:
    number.pop()
print(count)


Failing test case input:
5
2 2 1 5 9

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, *A = map(int, open(0).read().split())

S = set(A)

A.sort(reverse=True)

ans = 0
for a in A:
    b = 2 ** a.bit_length() - a
    if a != b and b in S:
        S.remove(b)
        ans += 1

print(ans)


Failing test case input:
5
2 3 2 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter

N, *A = map(int, open(0).read().split())

C = Counter(A)
A.sort(reverse=True)

ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1

    b = 2 ** a.bit_length() - a
    if C[b] > 0:
        C[b] -= 1
        ans += 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

def get_smallest_power_of_2_over_N(N):
    i=2
    while i<N:
        i*=2
    return i

N = int(input())
A = list(map(int,input().split()))


A = sorted(A)

ans=0
D=defaultdict(int)

for a in A:
    D[a]+=1

for i in reversed(range(N)):
    if D[A[i]]<=0:
        continue
    else:
        pair_val = get_smallest_power_of_2_over_N(A[i]) - A[i]
        if pair_val==A[i] and D[pair_val]>1 or D[pair_val]>0:
            ans+=1
            D[pair_val]-=1
            D[A[i]]-=1

print(ans)


Failing test case input:
5
2 24 16 16 13

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter

def get_smallest_power_of_2_over_N(N):
    i=2
    while i<=N:
        i*=2
    return i

N = int(input())
A = list(map(int,input().split()))


A = sorted(A)

ans=0
D=Counter(A)

for i in reversed(range(N)):
    pair_val = get_smallest_power_of_2_over_N(A[i]) - A[i]
    if D[A[i]]<=0:
        continue
    elif pair_val==A[i] and D[pair_val]>=2 or pair_val!=A[i] and  D[pair_val]>=1:
        ans+=1
        D[pair_val]-=1
        D[A[i]]-=1

print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a.sort()
from collections import defaultdict
dic = defaultdict(int)
for x in a:
    dic[x] += 1
ans = 0
for num in a[::-1]:
    if dic[num] <= 0:
        continue
    nerai = 1
    while num>=nerai:
        nerai *= 2
    nerai -= num
    if dic[nerai] <= 0:
        continue
    ans += 1
    dic[num] -= 1
    dic[nerai] -= 1
print(ans)

Failing test case input:
5
2 6 24 5 16

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=sorted(list(map(int,input().split())))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    d[i] -= 1
    find = twosum(i)
    if d[find] > 0 and d[i] >= 0:
        ans += 1
        d[find] -= 1
    else:
        d[i] += 1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(len(t)):
        if t[j] < x[i]:
            break
        if t[j]-x[i] in c.keys():
            if t[j]-x[i] == x[i] and c[x[i]] >= 2:
                c[x[i]] -= 2
                count +=1
            elif c[t[j]-x[i]]>0 and c[x[i]]>0:
                c[t[j]-x[i]] -= 1
                c[x[i]] -= 1
                count+=1
print(count)

Failing test case input:
5
3 24 9 1 16

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(start,len(t)):
        if t[j] > 2*x[i]:
            start = j
        if t[j] < x[i]:
            break
        if t[j]-x[i] in c.keys():
            if t[j]-x[i] == x[i]:
                if c[x[i]] >= 2:
                    c[x[i]] -= 2
                    count +=1
            else:
                if c[t[j]-x[i]]>0 and c[x[i]]>0:
                    c[t[j]-x[i]] -= 1
                    c[x[i]] -= 1
                    count+=1
print(count)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split(" ")))
A.sort()
used = [0] * N
pow2_set = reversed([ 1<<i for i in range(36)])
ans = 0
for pow2 in pow2_set:
    print(pow2)
    l,r = 0,N-1
    while l < r:
        if A[l] + A[r] < pow2:
            l += 1
        elif A[l] + A[r] == pow2:
            if used[l] == 0 and used[r] == 0:
                ans += 1
                used[l],used[r] = 1,1
            else:
                if used[l] == 1:
                    l += 1
                if used[r] == 1:
                    r -= 1
        else:
            r -= 1

print(ans)

Failing test case input:
5
3 3 24 6 13

Expected output:
1


Actual output:
34359738368
17179869184
8589934592
4294967296
2147483648
1073741824
536870912
268435456
134217728
67108864
33554432
16777216
8388608
4194304
2097152
1048576
524288
262144
131072
65536
32768
16384
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split(" ")))
A.sort()
used = [0] * N
pow2_set = reversed([ 1<<i for i in range(36)])
ans = 0
for pow2 in pow2_set:
    l,r = 0,N-1
    while l < r:
        if A[l] + A[r] < pow2:
            l += 1
        elif A[l] + A[r] == pow2:
            if used[l] == 0 and used[r] == 0:
                ans += 1
                used[l],used[r] = 1,1
            else:
                if used[l] == 1:
                    l += 1
                if used[r] == 1:
                    r -= 1
        else:
            r -= 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  if number[-1]!=reversed_num(number[-1])+1 and reversed_num(number[-1])+1 in number:
    number.remove(reversed_num(number[-1])+1)
    count+=1
  number.pop(-1)
print(count)


Failing test case input:
5
2 2 1 5 9

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



import bisect
from collections import defaultdict

N = int(input())
X = sorted(list(map(int, input().rstrip().split(' '))), reverse=False)
included_X = defaultdict(int)
pow_2 = [2**i for i in range(40)]

for x in X:
    included_X[x] += 1

count = 0
for i, x in enumerate(X[::-1]): 
    if included_X[x] > 0:
        index = bisect.bisect_left(pow_2, x)
        if included_X[pow_2[index] - x] > 0:
            included_X[pow_2[index] - x] -= 1
            count += 1
         
print(count)


Failing test case input:
5
2 2 1 5 9

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):



import bisect
from collections import defaultdict

N = int(input())
X = sorted(list(map(int, input().rstrip().split(' '))), reverse=False)
included_X = defaultdict(int)
pow_2 = [2**i for i in range(1, 50)]

for x in X:
    included_X[x] += 1

count = 0
for i, x in enumerate(X[::-1]): 
    if included_X[x] > 0:
        index = bisect.bisect_left(pow_2, x + 1)
        if pow_2[index] - x == x:
            if included_X[pow_2[index] - x] > 1:
                included_X[pow_2[index] - x] -= 2
                count += 1
        else:
            if included_X[pow_2[index] - x] > 0:
                included_X[pow_2[index] - x] -= 1
                included_X[x] -= 1
                count += 1
         
print(count)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse = True)
    al = [False for _ in range(N)]
    
    def exp(x):
        ans = 1
        while x > ans:
            ans *= 2
        return ans
        
    def ind(x):
        return A.index(x)
        
    ans = 0
    for i in range(N):
        if al[i] == True:
            continue
        use = A[i]
        al[i] = True
        num = exp(A[i]) - A[i]
        if ((num in A) and (al[ind(num)] == False)):
            al[ind(num)] = True
            ans += 1
            
    print(ans)
    
if __name__ == "__main__":
    main()


Failing test case input:
5
2 2 1 5 9

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = defaultdict(int)
    for x in A:
        d[x] += 1
    A = list(set(A))
    A.sort(reverse = True)
    l = len(A)
    
    def exp(x):
        l = len(str(bin(x))[2:])
        return 2**l

    ans = 0
    for i in range(l):
        a = A[i]
        if exp(a)
            ans += int(d[a]
        else:
            m = min(d[a],d[exp(a)-a])
            ans += m
            d[a] -= m
            d[exp(a)-a] -= m
            
    print(ans)
    
if __name__ == "__main__":
    main()
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

N=int(input())
A=[int(x) for x in input().split()]
A.sort()

P2=[]
for i in range(1,32):
  P2.append(2**(32-i))
  
def solve():
  a=A.pop()
  l=len(A)
  for i in range(31):
    if a > P2[i]:
      return False
    else:
      cnt=P2[i]-a
      b=bisect.bisect_left(A,cnt)
      if b != l and A[b]== cnt:
        A.pop(b)
        return True

ans=0
for i in range(N):
  if len(A) < i:
    break
  else:
    if solve():
      ans+=1
print(ans)

Failing test case input:
5
3 11 19 10 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import defaultdict

N=int(input())
A=[int(x) for x in input().split()]
A.sort(reverse=True)

cnt=defaultdict(int)
for a in A:
  cnt[a]+=1

P2=[]
for i in range(1,32):
  P2.append(2**(32-i))

ans=0

for a in A:
  for b in P2:
    if a >= b or cnt[a] < 1:
      break
    else:
      if (cnt[b-a] > 0 and (b-a) != a) or (cnt[b-a] > 1 and (b-a) == a):
        ans+=1
        cnt[b-a]-=1
        cnt[a]-=1
        break

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = Counter(a)
ans = 0

def make(x):
    num = 1
    while num < x:
        num *= 2
    return num

for i in range(n):
    cnt[a[i]] -= 1
    x = make(a[i])
    if cnt[x - a[i]] > 0:
        ans += 1
        cnt[x - a[i]] -= 1

print(ans)

Failing test case input:
5
4 2 1 3 5

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = Counter(a)
ans = 0

def make(x):
    num = 1
    while num <= x:
        num *= 2
    return num

for i in range(n):
    x = make(a[i])
    if cnt[x - a[i]] > 0 and cnt[a[i]] > 0 and x != 2 * a[i]:
        ans += 1
        cnt[x - a[i]] -= 1
        cnt[a[i]] -= 1
    elif x == 2 * a[i] and cnt[a[i]] > 1:
        ans += 1
        cnt[a[i]] -= 2

print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect_left
N = int(input())
A = sorted(list(map(int,input().split())))
A = [[A[i],0] for i in range(N)]
cnt = 0
for i in range(N-1,0,-1):
    if A[i][1]==0:
        a = A[i][0]
        k = 0
        while 2**k<=a:
            k += 1
        b = 2**k-a
        ind = bisect_left(A,[b,1])
        ind -= 1
        if ind<i and A[ind]==[b,0]:
            A[i][1]=1
            A[ind][1]=1
            cnt += 1
print(cnt)

Failing test case input:
5
4 3 4 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from bisect import bisect_left
N = int(input())
A = sorted(list(map(int,input().split())))
A = [[A[i],0] for i in range(N)]
cnt = 0
for i in range(N-1,0,-1):
    if A[i][1]==0:
        a = A[i][0]
        A[i][1]=1
        k = 0
        while 2**k<=a:
            k += 1
        b = 2**k-a
        ind = bisect_left(A,[b,1])
        ind -= 1
        if ind<i and A[ind]==[b,0]:
            A[ind][1]=1
            cnt += 1
print(cnt)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)

c = 0
for i in range(N - 1 , -1, -1):
    b = 1
    while b <= A[i]:
        b <<= 1
    
    j = bisect.bisect_left(A, b - A[i])
    if b - A[i] == A[j]:
        c += 1
        A[j] = A[j] - 0.5

print(c)


Failing test case input:
5
4 3 16 6 20

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)

c = 0
for i in range(N - 1 , -1, -1):
    if A[i] == int(A[i]):
        b = 1
        while b <= A[i]:
            b <<= 1

        j = bisect.bisect_left(A, b - A[i])
        if i > j:
            if b - A[i] == A[j]:
                c += 1
                A[j] = A[j] - 0.5
                A[i] = A[i] + 0.5
print(c)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import heapq
import bisect

n = ni()
a = na()
ls = []
nibeki = [2**i for i in range(1,31)]

for i in a:
    heapq.heappush(ls,-i)

s = set()
ans = 0

for _ in range(n):
    m = -heapq.heappop(ls)
    if m in s:
        s.discard(m)
        ans += 1
        continue
    b = bisect.bisect_right(nibeki,m)
    dif = 0 if b > 0 and nibeki[b-1] == m else nibeki[b]-m
    s.add(dif)

print(ans)

Failing test case input:
5
2 41 16 16 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import heapq

n = ni()
a = na()
ls = []

for i in a:
    heapq.heappush(ls,-i)

s = {}
ans = 0

for _ in range(n):
    m = -heapq.heappop(ls)
    if m in s and s[m] > 0:
        s[m] -= 1
        ans += 1
        continue
    dif = 2**m.bit_length()-m
    if dif in s:
        s[dif] += 1
    else:
        s[dif] = 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
c = Counter(A)

ans = 0
while A:
    a = A.pop()
    c[a] -= 1
    Num = 1 << (a.bit_length())
    cand = Num - a  
    if c[cand] > 0:
        ans += 1
        c[cand] -= 1

print(ans)


Failing test case input:
5
2 6 25 5 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
c = Counter(A)

ans = 0
while A:
    a = A.pop()
    if c[a] <= 0:
        continue
    c[a] -= 1
    Num = 1 << (a.bit_length())
    cand = Num - a  
    if c[cand] > 0:
        ans += 1
        c[cand] -= 1

print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
A = sorted(A, reverse=True)
ans = 0
for a in A:
    if a & (a - 1) != 0:
        cand = (1 << ((a - 1).bit_length()))
        if cnt[a] == 0 or cnt[cand] == 0: continue
    else:
        cand = a
        if cnt[a] < 2: continue
    ans += 1
    cnt[a] -= 1; cnt[cand] -= 1
print(ans)

Failing test case input:
5
2 6 24 6 16

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
A = sorted(A, reverse=True)
ans = 0
for a in A:
    if a & (a - 1) != 0:
        cand = (1 << ((a - 1).bit_length())) - a
        if cnt[a] == 0 or cnt[cand] == 0: continue
    else:
        cand = a
        if cnt[a] < 2: continue
    ans += 1
    cnt[a] -= 1; cnt[cand] -= 1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ca = Counter(a)

ans = 0
for item in a[::-1]:
    for i in range(18):
        inv = (1 << i) - item
        if inv < 0:
            continue
        if ca[inv] > 0 and item != inv:
            ans += 1 
            ca[inv] -=1
            ca[item] -=1
            break
        if ca[inv] > 1 and item == inv:
            ans += 1 
            ca[inv] -= 2
            break
print(ans)

Failing test case input:
5
2 6 25 5 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ca = Counter(a)
max_a = a[-1] 

ans = 0
for item in a[::-1]:
    if ca[item] == 0:
        continue
    for i in range(31, 0, -1):
        inv = (1 << i) - item
        if inv < 0 or inv > max_a:
            continue
        if item == inv:
            if ca[inv] > 1:
                ans += 1 
                ca[inv] -= 2
                break
        else:
            if ca[inv] > 0:
                ans += 1 
                ca[inv] -=1
                ca[item] -=1
                break
print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



from collections import defaultdict

N = int(input())
As = sorted(list(map(int, input().split())),reverse=True)
d = defaultdict(int)
for a in As:
    d[a] += 1
cnt = 0

for a in As:
    n = 0
    while 2**n <= a:
        n += 1
    p = 2**n - a
    
    if d[p] > 0:
        cnt += 1
        d[p] -= 1
    d[a] -= 1

print(cnt)


Failing test case input:
5
2 2 1 5 6

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):



from collections import defaultdict

N = int(input())
As = sorted(list(map(int, input().split())),reverse=True)
d = defaultdict(int)
for a in As:
    d[a] += 1

cnt = 0
for a in As:
    if d[a] == 0:continue
    d[a] -= 1
    n = 0
    while 2**n <= a:
        n += 1
    p = 2**n - a
    if d[p] > 0:
        cnt += 1
        d[p] -= 1

print(cnt)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0

for x in a:
    if x not in d: d[x] = 0
    d[x] += 1
    
for i in range(len(a)):
    y = 2**a[i].bit_length() - a[i]
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)        

Failing test case input:
5
2 20 16 16 1

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0

for x in a:
    if x not in d: d[x] = 0
    d[x] += 1
    
for i in range(len(a)):
    if d[a[i]] == 0:continue
        
    d[a[i]] -= 1
    
    y = 2**a[i].bit_length() - a[i]
    
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from heapq import heappush, heappop, heapify
from bisect import bisect_left

pow2 = [2]
for i in range(29):
  pow2.append(pow2[-1]*2)

N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

A = [-a for a in A]
heapify(A)
ans = 0
while A:
  a = - heappop(A)
  if d[a] == 0:
    continue
  pair = pow2[bisect_left(pow2, a)] - a
  if pair in d and d[pair] > 0:
    ans += 1
    d[pair] -= 1
    d[a] -= 1

print(ans)

Failing test case input:
5
6 2 1 3 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from heapq import heappush, heappop, heapify
from bisect import bisect_right

pow2 = [2]
for i in range(29):
  pow2.append(pow2[-1]*2)

N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

A = [-a for a in A]
heapify(A)
ans = 0
while A:
  a = - heappop(A)
  if d[a] == 0:
    continue
  pair = pow2[bisect_right(pow2, a)] - a
  if a == pair:
    if d[a] >= 2:
      d[a] -= 2
      ans += 1
  elif pair in d and d[pair] > 0:
    ans += 1
    d[pair] -= 1
    d[a] -= 1

print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
import bisect

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ca = Counter(a)

ans = 0
for item in a[::-1]:
    for i in range(18):
        inv = (1 << i) - item
        if inv < 0:
            continue
        if ca[inv] > 0 and item != inv:
            ans += 1 
            ca[inv] -=1
            ca[item] -=1
        if ca[inv] > 1 and item == inv:
            ans += 1 
            ca[inv] -= 2
print(ans)

Failing test case input:
5
6 3 2 3 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ca = Counter(a)
max_a = a[-1] 

ans = 0
for item in a[::-1]:
    if ca[item] == 0:
        continue
    for i in range(31, 0, -1):
        inv = (1 << i) - item
        if inv < 0 or inv > max_a:
            continue
        if item == inv:
            if ca[inv] > 1:
                ans += 1 
                ca[inv] -= 2
                break
        else:
            if ca[inv] > 0:
                ans += 1 
                ca[inv] -=1
                ca[item] -=1
                break
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=7
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 0:
    continue
  c[target]= -1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys():
    c[pair]= -1
    pairCounter+=1

print(pairCounter)

Failing test case input:
5
2 3 76 6 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):

import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=29
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 1:
    continue
  c[target]-= 1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys() and c[pair] > 0:
    c[pair]-= 1
    pairCounter+=1

print(pairCounter)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for t in reversed(range(1, 31)):
    for i in reversed(range(n)):
        if memo[a[i]] == 0:
            continue
        if memo[(1 << t) - a[i]] == 0:
            continue
        memo[a[i]] -= 1
        memo[(1 << t) - a[i]] -= 1
        count += 1

print(count)

Failing test case input:
5
3 18 14 5 2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for i in reversed(range(n)):
    if memo[a[i]] == 0:
        continue
    if (memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 0 and (1 << (len(bin(a[i])) - 2)) - a[i] != a[i]) or memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 1:
        memo[a[i]] -= 1
        memo[(1 << (len(bin(a[i])) - 2)) - a[i]] -= 1
        count += 1

print(count)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
    else:
         d[A[i]] = 1

for i in range(N):
    if A[i] not in B:
        t = 2**len(bin(A[i])[2::]) - A[i]
        if t in d:
            if d[t] > 0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1

print(ans1+ans2)

Failing test case input:
5
6 2 1 3 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
    else:
         d[A[i]] = 1

for i in range(N):
    t = 2**len(bin(A[i])[2::]) - A[i]
    if t in d:
        if t != A[i]:
            if d[t]>0 and d[A[i]]>0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1
        else:
            if d[t] > 1:
                ans2 += 1
                d[t] -= 2


print(ans1+ans2)