program main
implicit None
	integer(8)::n,p,i,k,s
	integer(8),allocatable::a(:)
	real(8)::x,y
	
	s = 0
	read *,n
	allocate(a(n))
	
	read *,a
	
	call hsort(a,n)
	
	y = 2
	do i = n,2,-1
		if(a(i) == 0) cycle
		p =2** (int(log(real(a(i)))/log(real(y))+1))-a(i)
		
		call schint(a,i-1,p,k)
		
		if(a(k) == p)then
			a(k) = 0
			s = s + 1
		endif
	enddo
	
	print 101,s
	
101 format(i0)
end program main

subroutine makeheap(a,n)
Implicit None
	integer(8)::n,i,c1,c2,p,t,m
	integer(8)::a(n)
	
	do i = n/2,1,-1
		p = i; c1 = i * 2
		do while (c1 <= n)
			c2 = c1 + 1
			if(c2 <= n .and. a(c2) > a(c1)) c1 = c2
			if(a(p) < a(c1))then
				t = a(p)
				a(p) = a(c1)
				a(c1) = t
				p = c1
				c1 = p*2
				else
					exit
			endif
		enddo
	enddo
end subroutine makeheap

subroutine hsort(a,n)
Implicit None
	integer(8)::n,t,i,p,c1,c2,j
	integer(8)::a(n)
	
	call makeheap(a,n)
	
	do i = n,2,-1
		t = a(i)
		a(i) = a(1)
		a(1) = t
		
		p = 1
		do
			c1 = p*2
			if (c1 >= i) exit
			
			c2 = c1 +1
			if(c2 < i .and. a(c2) > a(c1))then
					c1 = c2
			endif
			
			if(a(c1) >a(p))then
				t = a(p)
				a(p) = a(c1)
				a(c1) = t
				p = c1
				else
					exit
			endif
		enddo
	enddo
end subroutine hsort

subroutine schint(a,e1,x,p)
implicit None
	integer(8)::e1,s,e,x,p,t
	integer(8)::a(e1)
	
	s = 1;e = e1
	
	if(a(e) < x)then
		p = 0
		return
	endif
	
	do
		t = (s + e)/2
		if(a(t) < x)then
			if(a(t+1) >= x)then
				p = t + 1
				return
			endif
			
			s = t
			else if(t == 1 .or. a(t-1) < x)then
				p = t
				return
			else
			e = t
		endif
	enddo
	
end subroutine schint