Company: Infosys SP
Difficulty: medium
Optimal Permutation with XOR Condition You are given a positive integer n . A permutation p of length n is considered optimal if the following conditions are satisfied: For each i from 1 to n , p[i] ^ i is a power of two , where ^ is the bitwise XOR . Among all such permutations, p is lexicographically minimal . Find the sum of p[i] ^ i for each i in the optimal permutation. If such a permutation doesn\'t exist, print the sum of i ^ (n - i + 1) . Input Format The first line contains an integer n , denoting the size of the permutation. Output Format Output the sum of p[i] ^ i in the optimal permutation or the alternative value as described. Constraints 1 ≤ n ≤ 10^2 Examples Input: 1 Output: 0 Here, n = 1 . The only permutation is [1], and 1 ^ 1 = 0 , which is not a power of two. Thus, the answer is the sum of i ^ (n - i + 1) = 0 . Input: 6 Output: 14 The optimal permutation is: [3, 6, 1, 5, 4, 2] . Input: 10 Output: 26 Starter Code import sys def find_minimal_permutation(n): # Write you