Why this code is giving wrong ans

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x=0;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
x=x^arr[i];
}
int temp=x;
int pos=0;
while((temp&1) != 1){
pos++;
temp=temp>>1;
}
int mask=(1<<pos);
int a=0;
int b=0;
for(int i=0;i<n;i++){
if((arr[i]&mask)>0){
a=a^arr[i];
}
}
b=temp^a;
cout<<min(a,b)<<" "<<max(a,b)<<endl;
}