아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

XOR

면접 대비

시간 제한4초메모리 제한1024 MB

요약
서로 다른 수들의 집합과 여러 질의가 주어질 때, 각 질의에 대해 질의와 XOR한 값이 가장 큰 집합 원소를 출력한다.
난이도

보통10점 중 6점

유형
트라이, 비트 연산, 그리디, 배열
정답자
아직 제출이 없습니다

문제

Today Paul and Andrew discovered a new operation, XOR of two numbers.

Let us remind you that XOR, or exclusive OR, is a binary operation which is applied to two integer numbers bitwise. For each bit position, if the bits in the arguments are equal, the resulting bit is 0, otherwise 1. For example, 3 XOR 5 == 6, because 3_10=011_23\_{10} = 011\_2, 5_10=101_25\_{10} = 101\_2, so if we apply the operation, the second and the third bits are set to 1, bit the first bit is set to 0, so we get 110_2=6_10110\_{2} = 6\_{10}.

Paul and Andrew liked this operation so much that they invented a game. First, Paul writes nn integer numbers a_ia\_i. Second, Andrew writes mm integers b_jb\_j. After that, Paul finds for each b_jb\_j such kk that a_ka\_k XOR b_jb\_j is maximal.

The only problem is that Paul is not very fast in finding these numbers. Help him!

입력

The first line of the input contains one integer nn (1≤n≤100,0001 \le n \le 100,000) --- how many numbers Paul wrote. The second line contains Paul's numbers a_ia\_i (0≤a_i≤1090 \le a\_i \le 10^9). All a_ia\_i are different.

The third line contains an integer mm (1≤m≤100,0001 \le m \le 100,000) --- how many numbers Andrew wrote. The fourth line contains Andrew's numbers b_jb\_j (0≤b_j≤1090 \le b\_j \le 10^9).

출력

Output mm numbers: for each b_jb\_j, output such a_ka\_k that a_ka\_k XOR b_jb\_j is maximal.

예제2

  1. 예제 1

    입력
    2
    0 1
    2
    2 3
    
    예상 출력
    1 0
    
  2. 예제 2

    입력
    2
    3 0
    3
    2 3 9
    
    예상 출력
    0 0 3