#include<iostream> #include<vector> using namespace std; int main() { int n, result = 0; cin >> n; vector<int> arr(n, 0); for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) result ^= arr[i]; int rightOne = result & (~result + 1); int res1 = result, res2 = result; for (int i = 0; i < n; i++) if ((arr[i] & rightOne) == 0) res1 ^= arr[i]; res2 ^= res1; cout << (res1 < res2 ? res1 : res2) << " " << (res1 > res2 ? res1 : res2); return 0; }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] strArr = br.readLine().split(" "); int[] data = new int[n]; int[] result = new int[2]; int frist = 0; for (int i = 0; i < n; i++) { data[i] = Integer.parseInt(strArr[i]); frist ^= data[i]; } int second = frist & (-frist); int val = 0; for (int i = 0; i < n; i++) { if ((data[i] & second) != 0){ val ^= data[i]; } } result[0] = val; result[1] = frist ^ val; Arrays.sort(result); System.out.println(result[0]+" "+result[1]); } }