N = gets.to_i
as = gets.strip.split(/ /).collect{|n| n.to_i}

max = as.max

table = {}

as.each{|a|
	if table[a]
		table[a] += 1
	else
		table[a] = 1
	end
}

#p table

$counts = {}
$counts_rev = {}
$pairs = {}
as.each{|a|
	sum = 2
	count = 0
	pair_table = {}
	while sum <= a
		sum *= 2
	end
	while true
		if sum > a
			diff = sum - a
			if diff > max
				break
			end
			if c = table[diff]
				if diff == a
					c -= 1
				end
				if c > 0
					count += c
					pair_table[diff] = true
				end
			end
		end
		sum *= 2
	end
	if c = $counts[count]
		c[a] = true
	else
		$counts[count] = {a => true}
	end
	$pairs[a] = pair_table
	$counts_rev[a] = count
}

#p counts
#p pairs

max = $counts.keys.max

def remove_item(a)
#p [$counts, $counts_rev, a]
	count = $counts_rev[a]
	count_table = $counts[count]
	count_table.delete(a)
	if count_table.length == 0
		$counts.delete(count)
	end
	$counts_rev.delete(a)
	min = N
	$pairs[a].keys.each{|a2|
		count = $counts_rev[a2]
		table = $counts[count]
#p [$counts_rev, $counts, count, table, a2]
		table.delete(a2)
		if table.length == 0
			$counts.delete(count)
		end
		count -= 1
		$counts_rev[a2] = count
		if table = $counts[count]
			table[a2] = true
		else
			$counts[count] = { a2 => true }
		end
		if count < min
			min = count
		end
		$pairs[a2].delete(a)
	}
	min
end

count_pairs = 0
count = 1
while true
	if (table = $counts[count]) && table.length > 0
#		p ["x", $counts, count, table]
		a1 = table.keys[0]
		a2 = $pairs[a1].keys[0]
		count_pairs += 1
		
		min1 = remove_item(a1)
		min2 = remove_item(a2)
		
		count = [count, min1, min2].min
		if count < 1
			count = 1
		end
		
		if table.keys.length == 0
			table.delete(count)
		end
		next
	end
	count += 1
	if count >= max
		break
	end
end

puts count_pairs
