For this Question: A number P is said to be binary palindromic if the binary representation of the number P is a palindrome.
Given an integer N your task is to find the minimum number that on either adding or subtracting converts the number N to a binary palindrome.The first line of input contains a single integer T denoting the number of test cases. Each of next T lines contains a single integer each containing the value of N.

Constraints:- 
1 <= T <= 10000
0 <= N <= 10^<sup>9</sup>For each test case in a new line print the minimum integer.Sample Input:-
3
6
9
20


Sample Output:-
1
0
1

Explanation:-
6 - 1 = 7(111)
9 + 0 = 0(1001)
20+1 = 21( 10101), I have written this Solution Code: #include <bits/stdc++.h>
#define lli long long

using namespace std;

vector <lli> palindromes;

lli cal(string p)
{
    string p1 = p;
    reverse(p1.begin(), p1.end());
    p += p1;
    lli ans = 0;
    for ( int i = p.size() - 1; i >= 0; i-- ) {
        if ( p[i] == '1' ) ans += (1LL << ((int)p.size() - 1 - i));
    }
    return ans;
}

lli cal1(string p)
{
    string p1 = p;
    reverse(p1.begin(), p1.end());
    p1.erase(p1.begin());
    p += p1;
    int ans = 0;
    for ( int i = p.size() - 1; i >= 0; i-- ) {
        if ( p[i] == '1' ) ans += (1LL << ((int)p.size() - 1 - i));
    }
    return ans;
}

void f(int idx, string p, int flag)
{
    if ( idx == 16 ) {
        palindromes.push_back(cal(p));
        if ( !p.empty() ) palindromes.push_back(cal1(p));
        return;
    }
    if ( flag == 0 ) {
        f(idx + 1, p, 0);
        f(idx + 1, p + "1", 1);
    }
    else {
        f(idx + 1, p + "0", 1);
        f(idx + 1, p + "1", 1);
    }
}

int main()
{


    int t;
    lli idx, ans, n;
    cin >> t;
    assert(t >= 1 && t <= 100000);

    f(0, "", 0);
    sort(palindromes.begin(), palindromes.end());

    while ( t-- ) {
        cin >> n;
        assert(n >= 0 && n <= 2000000000);
        idx = lower_bound(palindromes.begin(), palindromes.end(), n) - palindromes.begin();
        ans = palindromes[idx] - n;
        if ( idx > 0 ) ans = min(ans, n - palindromes[idx - 1]);
        cout << ans << endl;
    }

    return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?