Doubt on greedy bitmasking

https://codeforces.com/contest/1299/problem/A

Please can u give me some hint for solving thisproblem

@Somasree the key observation in this question is
f(a,b)=(a&(~b))
using this you can module the function on the whole array as
f(a1,an)=(a1&(~a2)&(~a3)…(~an))
now only the first position matters and so we place every element at first and then calculate the ans in o(1)
by pre calculating the prefix and suffix array for( ~a[i]) of values
like pref[i]=(~a[0]&~a[1]&…~a[i])
and reverse for suffix
then we check for each pos and the pos from thich the ans is max then we swap that position and a[0]
the answer at each position is pref[i] & a[i]& suf[i+1]
Coding Blocks IDE
this is the implemented code if not clear let me know

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.