ZhenlongDai/ACPR huggingface dataset:
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
import math
import collections

Even=set([A[i] for i in range(N) if A[i] %2 == 0])
Odd=set([A[i] for i in range(N) if A[i] %2==1])
powers =[2**i for i in range(1,int(math.log(max(A),2)+2))]
table=collections.defaultdict(int)
ans=0
for i in range(N):
  table[A[i]]+=1
for x in table:
  while(table[x]>0):
    table[x]-=1
    for y in reversed(powers):
      if y - x in table and table[y-x]>0:
        ans+=1
        table[y-x]-=1
        break
print(ans)  

Failing test case input:
5
3 11 14 5 1

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
import math
import collections
powers =[2**i for i in range(1,int(math.log(max(A),2)+2))]
table=collections.defaultdict(int)
table2=collections.defaultdict(set)
ans=0
for i in range(N):
  table[A[i]]+=1
for x in table:
  for y in reversed(powers):
    if y - x in table:
      table2[x].add(y-x)
        
        
        
table2 =list(table2.items())
table2.sort(key = lambda x:len(x[1]))

for x,y in table2:
  while(table[x]>0):
    table[x]-=1
    for z in y:
      if table[z]>0:
        ans+=1
        table[z]-=1
        break
print(ans)

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

N = int(input())
A = list(map(int, input().split()))
L2= [1]
for i in range(37):
    L2.append(L2[-1]*2)
D=defaultdict(int)
for a in A:
    D[a] += 1
A.sort(reverse=True)
res = 0
for a in A:
    if D[a]==0:continue
    beki2 = L2[bisect.bisect_left(L2,a)]
    j = beki2 - a
    if D[j] > 0:
        D[j] -= 1
        res += 1

print(res)


Failing test case input:
5
2 41 16 16 1

Expected output:
1


Actual output:
0


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

N = int(input())
A = list(map(int, input().split()))
L2 = [1]
for i in range(40):
    L2.append(L2[-1]*2)
D = defaultdict(int)
for a in A:
    D[a] += 1
A.sort(reverse=True)
res = 0
for a in A:
    if D[a] < 1:
        continue
    D[a] -= 1
    beki2 = L2[bisect.bisect_right(L2, a)]
    j = beki2 - a
    if D[j] > 0:
        D[j] -= 1
        res += 1

print(res)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
    if 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)


Failing test case input:
5
4 3 4 3 10

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 (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
import math

N=int(input())

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

answer=0
A.sort(reverse=True)

Amax=A[0]
limit=1
while(True):
  if limit>Amax:
    break;
  limit*=2

Acounter=Counter(A)
print(Acounter)

while(limit!=1):
  for number,count in Acounter.items():
    if limit-number in Acounter.keys():
      if number==limit-number:
        dec=math.floor(Acounter[number]/2)
        Acounter[number]-=dec
      else:
        dec=min(Acounter[number],Acounter[limit-number])
        Acounter[number]-=dec
        Acounter[limit-number]-=dec
      answer+=dec
  limit=int(limit/2)
print(answer)

Failing test case input:
5
2 41 16 16 1

Expected output:
1


Actual output:
Counter({16: 2, 41: 1, 2: 1, 1: 1})
1


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

N=int(input())

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

answer=0
A.sort(reverse=True)

Amax=A[0]
limit=1
while(True):
  if limit>Amax:
    break;
  limit*=2

Acounter=Counter(A)


while(limit!=1):
  eraserlist=[]
  for number,count in Acounter.items():
    if limit-number in Acounter.keys():
      if number==limit-number:
        dec=math.floor(Acounter[number]/2)
        Acounter[number]-=dec*2
      else:
        dec=min(Acounter[number],Acounter[limit-number])
        Acounter[number]-=dec
        Acounter[limit-number]-=dec
        if Acounter[limit-number]==0:
          eraserlist.append(limit-number)
      if Acounter[number]==0:
        eraserlist.append(number)
      answer+=dec
    if number>=limit/2:
      eraserlist.append(number)
  for i in range(len(eraserlist)):
    if eraserlist[i] in Acounter.keys():
      Acounter.pop(eraserlist[i])
  limit=int(limit/2)
print(answer)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
import itertools
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
d = defaultdict(int)

for key, value in itertools.groupby(a):
    d[key] = len(list(value))


ans = 0
for i in range(N):
    now = a[i]
    if d[now] > 0:
        pair = 2**((now-1).bit_length()) - now
        if d[pair] > 0:
            ans += 1
            d[now] -= 1
            d[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 bisect
import itertools
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
d = defaultdict(int)

for key, value in itertools.groupby(a):
    d[key] = len(list(value))

ans = 0
for i in range(N):
    now = a[i]
    if d[now] > 0:
        pair = 2**((now).bit_length()) - now
        if now == pair:
            if d[pair] >= 2:
                ans += 1
                d[pair] -= 2
        elif d[pair] > 0:
            ans += 1
            d[now] -= 1
            d[pair] -= 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
i=-1
while Q:
    k=Q.pop()
    for r2 in rui:
        tmp=bi.bisect_left(A[:i],r2-k)
        if tmp == n:i-=1;continue
        if A[tmp]==r2-k: ans+=1;break
        i-=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):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = Counter(a)

ans = 0
for i in a:
    if c[i] == 0:
        continue
    c[i] -= 1
    k = 1<<(i-1).bit_length()
    j = k-i
    if j in c and c[j] > 0:
        ans += 1
        c[j] -= 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
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = Counter(a)

ans = 0
for i in a:
    if c[i] == 0:
        continue
    c[i] -= 1
    k = 1<<i.bit_length()
    j = k-i
    if j in c and c[j] > 0:
        ans += 1
        c[j] -= 1
print(ans)

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

from collections import Counter



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

counter = Counter(A)
A.sort()

answer = 0
for x in A[::-1]:
    counter[x] -= 1
    target = (1 << x.bit_length()) - x
    if counter[target] > 0:
        counter[target] -= 1
        answer += 1

print(answer)

Failing test case input:
5
4 2 1 3 5

Expected output:
1


Actual output:
2


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

from collections import Counter



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

counter = Counter(A)
A.sort()

answer = 0
for x in A[::-1]:
    while counter[x] > 0:
        counter[x] -= 1
        target = (1 << x.bit_length()) - x
        if counter[target] > 0:
            counter[target] -= 1
            answer += 1

print(answer)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

for num in a:
    d[num]+=1

ans=0
for num in sorted(d,reverse=True):
    while d[num]>=1:
        d[num]-=1

        now=1
        while now<=num:
            now*=2

        cand = now - num
        print(num,cand)

        if d[cand]>=1:
            d[cand]-=1
            ans+=1
        else:
            break
print(ans)

Failing test case input:
5
7 3 8 3 19

Expected output:
0


Actual output:
19 13
8 8
7 1
3 1
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

for num in a:
    d[num]+=1

ans=0
for num in sorted(d,reverse=True):
    while d[num]>=1:
        d[num]-=1

        now=1
        while now<=num:
            now*=2

        cand = now - num
        if d[cand]>=1:
            d[cand]-=1
            ans+=1
        else:
            break
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 pair_val==A[i] and D[pair_val]>1 or pair_val!=A[i] and  D[pair_val]>0:
        ans+=1
        D[pair_val]-=1
        D[A[i]]-=1

print(ans)


Failing test case input:
5
2 6 25 3 10

Expected output:
1


Actual output:
2


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 (Python (3.4.3), verdict: Wrong Answer):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for _ in range(len(a)):
    if len(a)<2:
        break
    else:
        bi=format(a[0], 'b')
        x=2**len(bi)-a[0]
        if x in a:
            ans+=1
            a.remove(x)
        a.pop(0)
print(ans)


Failing test case input:
5
4 3 16 6 20

Expected output:
0


Actual output:
2


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):
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 = {}
ans = 0

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

print(ans)

Failing test case input:
5
2 24 16 16 13

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(reverse=True)
c = Counter(A)

ans = 0
flag = False
for i in range(n):
    if c[A[i]] == 0:
        continue

    pow_2 = 2 ** len(format(A[i], "b"))
    if pow_2 - A[i] != A[i]:
        c[pow_2 - A[i]] -= 1
        ans += 1
    elif c[pow_2 - A[i]] > 1 and pow_2 - A[i] == A[i]:
        if flag is True:
            c[A[i]] -= 2
            ans += 1
            flag = False
        else:
            flag = True

print(ans)

Failing test case input:
5
2 3 24 6 7

Expected output:
1


Actual output:
4


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

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

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

ans = 0
flag = False
for i in range(n):
    if c[A[i]] == 0:
        continue

    pow_2 = 2 ** len(format(A[i], "b"))
    if c[pow_2 - A[i]] > 0 and pow_2 - A[i] != A[i]:
        c[pow_2 - A[i]] -= 1
        c[A[i]] -= 1
        ans += 1
    elif c[pow_2 - A[i]] > 1 and pow_2 - A[i] == A[i]:
        if flag is True:
            c[A[i]] -= 2
            ans += 1
            flag = False
        else:
            flag = True

print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
C = Counter(A)
ans = 0
for a in A:
  for i in range(1, 33):
    r = (1<<i) - a
    if r != a:
      if r in C and C[r] > 0:
        ans += 1
        C[r] -= 1
        break
    else:
      if C[r] >= 2:
        ans += 1
        C[r] -= 1
        break
  C[a] -= 1
print(ans)

Failing test case input:
5
1 3 82 6 13

Expected output:
1


Actual output:
2


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

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
C = Counter(A)
ans = 0
for a in A:
  if not C[a]:
    continue
  r = (1<<a.bit_length()) - a
  if r != a:
    if r in C and C[r] > 0:
      ans += 1
      C[r] -= 1
  else:
    if C[r] >= 2:
      ans += 1
      C[r] -= 1
  C[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  =  {}
count = 0
overlap = -1 

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

Failing test case input:
5
2 24 16 16 13

Expected output:
1


Actual output:
3


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 (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):
    if A[i] == int(A[i]):
        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
            A[i] = A[i] + 0.5

print(c)


Failing test case input:
5
2 3 38 3 10

Expected output:
0


Actual output:
1


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):


n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0
overlap = -1 

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

Failing test case input:
5
4 3 4 3 10

Expected output:
1


Actual output:
2


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 (Python (3.4.3), verdict: Wrong Answer):
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:
    b = 2 ** a.bit_length() - a
    C[a] -= 1
    C[b] -= 1
    if C[a] >= 0 and C[b] >= 0:
        ans += 1

print(ans)


Failing test case input:
5
3 11 14 5 1

Expected output:
2


Actual output:
1


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):
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,100):
    if 2**i>2*(10**9):
        break
    else:
        B.append(2**i)
B.append(2**(i+1))
ans=0

for i in range(N):
    X=bisect.bisect_left(B,A[N-1-i])
    
    if A[bisect.bisect_left(A,B[X]-A[N-1-i])]==B[X]-A[N-1-i]:
        ans+=1
        A[bisect.bisect_left(A,B[X]-A[N-1-i])]-=0.1
print(ans)

Failing test case input:
5
1 3 24 6 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
A.append(999999999999999)
B=[]
for i in range(1,35):
    B.append(2**i)
ans=0
for i in range(N):
    if A[N-1-i]==int(A[N-1-i]):
        for j in range(len(B)):
            if A[N-1-i]<B[j]:
                break
        if A[bisect.bisect_left(A,B[j]-A[N-1-i])]==B[j]-A[N-1-i]:
            if bisect.bisect_left(A,B[j]-A[N-1-i])<N-1-i:
                A[bisect.bisect_left(A,B[j]-A[N-1-i])]-=0.1
                A[N-1-i]+=0.1
                ans+=1
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

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

ans = 0
for i in range(N):
    if dic[A[i]] != 0:
        b = 2**(A[i].bit_length()) - A[i]
        if dic[b]:
            ans += 1
            dic[A[i]], dic[b] = 0, 0

print(ans)

Failing test case input:
5
3 3 16 14 13

Expected output:
1


Actual output:
2


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

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

ans = 0
for a in A:
    if dic[a] != 0:
        b = 2**(a.bit_length()) - a
        if dic[b] != 0:
            if b == a and dic[b] == 1:
                continue
            ans += 1
            dic[a] -= 1
            dic[b] -= 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()
from collections import Counter
dic = Counter(a)
ans = 0
for k in range(len(a)-1,-1,-1):
    if dic[a[k]]:
        dic[a[k]] -= 1
    t = 2**a[k].bit_length()-a[k]
    if dic[t]:
        dic[t] -= 1
        ans += 1
print(ans)

Failing test case input:
5
2 6 25 5 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
a.sort()
from collections import Counter
dic = Counter(a)
ans = 0
for k in range(len(a)-1,-1,-1):
    if dic[a[k]]==0:
        continue
    dic[a[k]] -= 1
    t = 2**a[k].bit_length()-a[k]
    if dic[t]:
        dic[t] -= 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)
d  =  {}
count = 0
overlap = -1 

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

Failing test case input:
5
3 4 18 14 13

Expected output:
2


Actual output:
3


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 (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left
from collections import deque
 
N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        r = A.pop()
        idx = bisect_left(A, pow2 - r)
        for _ in range(idx):
            A_tmp.appendleft(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)

Failing test case input:
5
2 6 24 5 16

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from bisect import bisect_left, bisect_right
from collections import deque

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    while len(bin(A[-1])) - 2 > t:
        A.pop()
        if len(A) < 2: break
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        r = A.pop()
        idx = bisect_left(A, pow2 - r)
        for _ in range(idx):
            A_tmp.appendleft(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)

Problem: p03201
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    r = collections.Counter()
    a = LI()
    for x in a:
        z = 2**(x.bit_length())-x
        r[z] += 1 + (z != x)
    ans = 0
    for x in a:
        if r[x] > 1:
            ans += 1
            r[x] -= 2
    print(ans)


if __name__ == '__main__':
    main()

Failing test case input:
5
3 11 14 5 1

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    INF = 10**10
    N = NI()
    a = LI()
    a.sort()
    u = 2 ** 31
    ans = 0
    while u > 2:
        u /= 2
        j = N-1
        for i in range(N):
            if a[i] == INF: continue
            while j > i and a[i] + a[j] > u:
                j -= 1
            if j <= i: break
            if a[i] + a[j] == u:
                ans += 1
                a[i] = a[j] = INF

    print(ans)


if __name__ == '__main__':
    main()
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N = int(input())
A = sorted([int(x) for x in input().split()], reverse=True)
C = Counter(A)

ans = 0
for a in A:
    pt = 2 ** len(format(a, 'b'))
    C[a] -= 1
    if C[pt - a] >= 1:
        C[pt - a] -= 1
        ans += 1
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 = sorted([int(x) for x in input().split()], reverse=True)
C = Counter(A)

ans = 0
for a in A:
    if C[a] == 0:
        continue
    pt = 2 ** len(format(a, 'b'))
    C[a] -= 1
    if C[pt - a] >= 1:
        C[pt - a] -= 1
        ans += 1
print(ans)

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


from collections import Counter
n = int(input())
a = list(map(int, input().split( )))
a_c = Counter(a)

a.sort(reverse = True)
ans = 0
for i in range(n):
    j = 0
    while 2**j<a[i]:
        j+=1
    if 2**j-a[i] in a_c and a_c[a[i]]:
        if a_c[2**j-a[i]]:
            a_c[2**j-a[i]] -= 1
            ans += 1
    
print(ans)
            

Failing test case input:
5
3 24 16 16 13

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):


from collections import Counter
n = int(input())
a = list(map(int, input().split( )))
a_c = Counter(a)

a.sort(reverse = True)
ans = 0
for i in range(n):
    if not a_c[a[i]]:
        continue
    a_c[a[i]] -= 1
    t = (1<<a[i].bit_length()) - a[i]
    if t in a_c:
        if a_c[t]:
            a_c[t] -= 1
            
            ans += 1

print(ans)
Problem: p03201
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict
dic = defaultdict(int) 

N = int(input())
A = list(map(int,input().split()))
B = set(A)
for i in A:
  dic[i] +=1

beki = [1]
for i in range(30): 
  temp = beki[-1]
  beki.append(temp*2)

L = [[] for _ in range(N)]
for i in range(N):
  for t in beki:
    now = t-A[i]
    if now>0 and now != A[i] and now in B:
      L[i].append(now)
  L[i].append(A[i]) 

L.sort(key=len)

ans = 0
for i in range(N):
  now = L[i].pop()
  for num in L[i]:
    if num in dic and dic[now] > 0 and dic[num] > 0:
      dic[now] -= 1
      dic[num] -= 1
      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 defaultdict
dic = defaultdict(int) 

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

for i in A:
  dic[i] +=1

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

L = [[] for _ in range(N)]
for i in range(N):
  for t in beki:
    now = t-A[i]
    if A[i] == now and dic[now] >=2:
      L[i].append(now)
    elif A[i] != now and now>0 and now in dic:
      L[i].append(now)
  L[i].append(A[i]) 




ans = 0
for i in range(N):
  now = L[i].pop()
  
  for num in L[i]:
    if num in dic:
      if num == now and dic[now] > 1:
        dic[num] -=2
        ans += 1
        break
      elif num != now and dic[num] > 0 and dic[now] > 0:
        dic[num] -= 1
        dic[now] -= 1
        ans += 1
        break

print(ans)

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



import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)

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:
        d[p] -= 1
        cnt += 1
    d[a] -= 1
print(cnt)


Failing test case input:
5
1 3 82 6 13

Expected output:
1


Actual output:
2


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)
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 dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] = dic.get(a)-1
        dic[small] = dic.get(small)-1
        ans += 1
print(ans)

Failing test case input:
5
2 3 16 6 20

Expected output:
1


Actual output:
2


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict
import bisect

N = int(input())
A = list(map(int, input().split()))
L2 = [1]
for i in range(37):
    L2.append(L2[-1]*2)
D = defaultdict(int)
for a in A:
    D[a] += 1
A.sort(reverse=True)
res = 0
for a in A:
    if D[a] == 0:
        continue
    D[a] -= 1
    beki2 = L2[bisect.bisect_left(L2, a)]
    j = beki2 - a
    if D[j] > 0:
        D[j] -= 1
        res += 1

print(res)


Failing test case input:
5
2 24 16 16 1

Expected output:
1


Actual output:
0


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

N = int(input())
A = list(map(int, input().split()))
L2 = [1]
for i in range(40):
    L2.append(L2[-1]*2)
D = defaultdict(int)
for a in A:
    D[a] += 1
A.sort(reverse=True)
res = 0
for a in A:
    if D[a] < 1:
        continue
    D[a] -= 1
    beki2 = L2[bisect.bisect_right(L2, a)]
    j = beki2 - a
    if D[j] > 0:
        D[j] -= 1
        res += 1

print(res)

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

import copy

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

pairCounter=0

beki=7
nibeki=2**beki

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

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

  pair = nibeki * 2 - target
  if pair in A:
    
    pairCounter+=1

print(pairCounter)

Failing test case input:
5
2 2 1 6 9

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):
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 d[t] > 0:
            ans2 += 1
            d[t] -= 1
            d[A[i]] -= 1

print(ans1+ans2)

Failing test case input:
5
3 36 2 10 8

Expected output:
0


Actual output:
2


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)

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,"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
1 3 82 6 13

Expected output:
1


Actual output:
2


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 (PyPy3 (7.3.0), verdict: Wrong Answer):
from bisect import bisect_right
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
set_A = set(A)
ans = 0
use = [False for _ in range(N)]
beki_list = [pow(2, i) for i in range(1, 32)]
for a in A:
    index = bisect_right(beki_list, a)
    if (beki_list[index] - a) in set_A:
        if (use[A.index(beki_list[index] - a)] == False) & (a  != beki_list[index] - a):
            ans += 1
            use[A.index(beki_list[index] - a)] = True
print(ans)

Failing test case input:
5
2 3 16 6 10

Expected output:
1


Actual output:
2


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

balls_count = defaultdict(int)

N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
ans = 0
beki_list = [pow(2, i) for i in range(1, 32)]
for a in A:
    balls_count[a] += 1

for a in A:
    if balls_count[a] == 0:
        continue
    balls_count[a] -= 1
    index = bisect_right(beki_list, a)
    pair = beki_list[index] - a
    if balls_count[pair] > 0:
        balls_count[pair] -= 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:
  x=reversed_num(number[-1])+1
  if x in number:
    if x!=number[-1]:
      number.remove(x)
      count+=1
  number.pop()
print(count)


Failing test case input:
5
2 24 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 (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]:
  d[i] -= 1
  find = twosum(i)
  if d[find] > 0:
    ans += 1
    d[find] -= 1
print(ans)

Failing test case input:
5
1 3 24 6 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 (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
while size_a >= 2:
    x = keys[-1]
    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)

Failing test case input:
5
2 6 25 5 10

Expected output:
1


Actual output:
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 (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict
import bisect

N = int(input())
A = list(map(int, input().split()))
L2 = [1]
for i in range(40):
    L2.append(L2[-1]*2)
D = defaultdict(int)
for a in A:
    D[a] += 1
A.sort(reverse=True)
res = 0
for a in A:
    if D[a] < 1:
        continue
    D[a] -= 1
    beki2 = L2[bisect.bisect_left(L2, a)]
    j = beki2 - a
    if D[j] > 0:
        D[j] -= 1
        res += 1

print(res)


Failing test case input:
5
2 24 16 16 13

Expected output:
1


Actual output:
0


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

N = int(input())
A = list(map(int, input().split()))
L2 = [1]
for i in range(40):
    L2.append(L2[-1]*2)
D = defaultdict(int)
for a in A:
    D[a] += 1
A.sort(reverse=True)
res = 0
for a in A:
    if D[a] < 1:
        continue
    D[a] -= 1
    beki2 = L2[bisect.bisect_right(L2, a)]
    j = beki2 - a
    if D[j] > 0:
        D[j] -= 1
        res += 1

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

def get_smallest_power_of_2_over_N(N):
    return 2**N.bit_length()

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 D[pair_val]>0:
            ans+=1
            D[pair_val]-=1
            D[A[i]]-=1
        elif pair_val==A[i] and D[pair_val]>1:
            ans+=1
            D[pair_val]-=1
            D[A[i]]-=1

print(ans)


Failing test case input:
5
2 2 24 6 9

Expected output:
1


Actual output:
2


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 (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

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

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

ans = 0
for a in A:
    
    p = 2 ** a.bit_length()
    if cnt[p - a]:
        if a == p - a:
            if cnt[a] >= 2:
                ans += 1
                cnt[a] -= 2
        else:
            ans += 1
            cnt[p - a] -= 1
            cnt[a] -= 1

print(ans)

Failing test case input:
5
3 18 14 5 2

Expected output:
2


Actual output:
3


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

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

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

ans = 0
for a in A:
    if not cnt[a]: continue

    
    p = 2 ** a.bit_length()
    if cnt[p - a]:
        if a == p - a:
            if cnt[a] >= 2:
                ans += 1
                cnt[a] -= 2
        else:
            ans += 1
            cnt[p - a] -= 1
            cnt[a] -= 1

print(ans)
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[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    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 (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left
from collections import Counter

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

power = 1
powers = [1]
while power <= 10 ** 9:
    power *= 2
    powers.append(power)

a.sort()
c = Counter(a)

ans = 0
for e in a[::-1]:
    i = bisect_left(powers, e)
    target = powers[i]

    if target == 2 * e:
        if c[e] >= 2:
            c[e] -= 2
            ans += 1

    else:
        if c[e] and c[target-e]:
            c[e] -= 1
            c[target-e] -= 1
            ans += 1

print(ans)


Failing test case input:
5
2 41 16 16 1

Expected output:
1


Actual output:
0


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

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

power = 1
powers = [1]
while power <= 10 ** 9:
    power *= 2
    powers.append(power)

a.sort()
c = Counter(a)

ans = 0
for e in a[::-1]:
    i = bisect_right(powers, e)
    target = powers[i]

    if target == 2 * e:
        if c[e] >= 2:
            c[e] -= 2
            ans += 1

    else:
        if c[e] and c[target-e]:
            c[e] -= 1
            c[target-e] -= 1
            ans += 1

print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
C = Counter(A)
ans = 0
for a in A:
  for i in range(1, 32):
    r = (1<<i) - a
    if r != a:
      if r in C and C[r] > 0:
        ans += 1
        C[r] -= 1
        break
    else:
      if C[r] >= 2:
        ans += 1
        C[r] -= 1
        break
  C[a] -= 1
print(ans)

Failing test case input:
5
3 11 14 5 1

Expected output:
2


Actual output:
3


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

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
C = Counter(A)
ans = 0
for a in A:
  if not C[a]:
    continue
  r = (1<<a.bit_length()) - a
  if r != a:
    if r in C and C[r] > 0:
      ans += 1
      C[r] -= 1
  else:
    if C[r] >= 2:
      ans += 1
      C[r] -= 1
  C[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)
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 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 4 1 14 13

Expected output:
1


Actual output:
3


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)