SOLVE
LATER
Given a complete binary tree with $$N$$ nodes and each node have an distinct integer $$a_i$$ attached with it, find the minimum number of swaps you can make to convert the binary tree into binary search tree. In one swap, you can select any two nodes and swap their values.
You will be given the array representation of the binary tree. Root of the tree will be at $$a_1$$. Left child of root will be at $$a_2$$ and right child of root will be at $$a_3$$. Left child of node at array position $$k$$ will be at $$a_{2 * k}$$ and right child of node at array position $$k$$ will be at $$a_{2 * k + 1}$$.
Input format:
First line contains an integer, $$N$$ $$(1 \le N \le 10^5)$$, denoting the number of nodes. Second line contains $$N$$ space separated integers, $$a_i$$ $$(1 \le a_i \le 10^5)$$,, denoting the value attached to $$i^{th}$$ node.
Output format:
Print a single integer, denoting the minimum number of swaps needed to convert binary tree into a binary search tree.
We need to only one swap $$(1, 2)$$ to convert the given binary tree into binary search tree.