program main
implicit None
integer(8)::n,i,j,p,q,s,e,f
integer(8),allocatable::a(:)
real(8)::k,x,y

	read *,n
	allocate(a(n))
	read *,a
	call h2(a,n)
	
	s = 0
	do i = n,1,-1
		if (a(i) >10e9) cycle
		x = a(i);y = 2
		k = log(x)/log(y)
		p = int(k)+1
		q = 2**p
		
		p = q-a(i)
		
		e = 1
		f = i-1
		do while (e-f >10)
		if(a((e+f)/2) < p)then
			f = (e+f)/2
			else
				e = (e+f)/2
		endif
		print *,e,f
		enddo
		
		
		do j = f,e,-1
			if(a(j) == p)then
				s = s + 1
				a(j) = 1000000001
				exit
			endif
		enddo
	enddo
	
	print * ,s
101 format(i0)
end program main

subroutine h2(a,n)
implicit None
	integer(8)::a(n),x
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie)
		a(ie) = a(1)
		a(1) = x
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2