Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import math
  import bisect
  #import collections
  import sys
  input = sys.stdin.readline

  N = int(input())
  A = list(map(int,input().split()))
  #C = collections.Counter(A)
  C = {}
  for a in A:
    if a in C:
      C[a] += 1
    else:
      C[a] = 1
  A = sorted(list(C.keys()))
  #print(C)
  #print(A)

  ans = 0
  for i in range(len(A)-1,-1,-1):
    a = A[i]
    b = (1<<(int(math.log(a,2))+1))-a
    if a == b:
      ans += C[a]//2
      C[a] -= C[a]//2*2
    else:
      r = bisect.bisect_left(A[:i], b)
      if r < i and A[r] == b:
        mn = min(C[a],C[A[r]])
        ans += mn
        C[a] -=  mn
        C[A[r]] -= mn
  print(ans)

if __name__ == '__main__':
  main()

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
#C = collections.Counter(A)
C = {}
for a in A:
  if a in C:
    C[a] += 1
  else:
    C[a] = 1
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A[:i], b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
#C = collections.Counter(A)
C = {}
for a in A:
  if a in C:
    C[a] += 1
  else:
    C[a] = 1
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A[:i], b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
import collections

N = int(input())
A = sorted(list(map(int,input().split())))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A[:i], b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A[:i], b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  r = bisect.bisect_left(A[:i+1], b)
  #print(i,a,b,r)
  if r <= i and A[r] == b:
    if a == A[r]:
      ans += C[a]//2
      C[a] -= C[a]//2*2
    else:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  r = bisect.bisect_left(A[:i+1], b)
  #print(i,a,b,r)
  if r <= i and A[r] == b:
    if a == A[r]:
      ans += C[a]//2
      C[a] -= C[a]//2*2
    else:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import math
  import bisect
  import sys
  input = sys.stdin.readline

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

  ans = 0
  while(len(A)>1):
    a = A.pop()
    b = (1<<(int(math.log(a,2))+1))-a
    #print(a,b)
    r = bisect.bisect_left(A, b)
    if r < len(A) and A[r] == b:
      ans += 1
      del A[r]
  print(ans)

if __name__ == '__main__':
  main()

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect

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

ans = 0
while(len(A)>1):
  a = A.pop()
  b = (1<<(int(math.log(a,2))+1))-a
  #print(a,b)
  r = bisect.bisect_left(A, b)
  if r < len(A) and A[r] == b:
    ans += 1
    del A[r]
print(ans)

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect

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

ans = 0
while(len(A)>1):
  a = A.pop()
  b = (1<<(int(math.log(a,2))+1))-a
  #print(a,b)
  r = bisect.bisect_left(A, b)
  if r < len(A) and A[r] == b:
    ans += 1
    del A[r]
print(ans)

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect

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

ans = 0
while(len(A)>1):
  a = A[-1]
  del A[-1]
  b = (1<<(int(math.log(a,2))+1))-a
  #print(a,b)
  r = bisect.bisect_left(A, b)
  if r < len(A) and A[r] == b:
    ans += 1
    del A[r]
print(ans)

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect

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

ans = 0
while(len(A)>1):
  a = A[-1]
  del A[-1]
  b = (1<<(int(math.log(a,2))+1))-a
  #print(a,b)
  r = bisect.bisect_left(A, b)
  if r < len(A) and A[r] == b:
    ans += 1
    del A[r]
print(ans)

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect

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

ans = 0
while(len(A)>1):
  a = A[-1]
  A = A[:-1]
  b = (1<<(int(math.log(a,2))+1))-a
  #print(a,b)
  r = bisect.bisect_left(A, b)
  if r < len(A) and A[r] == b:
    ans += 1
    if r == 0:
      A = A[1:]
    elif r == len(A)-1:
      A = A[:r]
    else:
      A = A[:r]+A[r+1:]
print(ans)

Fixed submission:
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)