This page is still under construction.

Parts of this page are still being built. What you see may change.

Xor Sum

Time limit2sMemory limit1024 MB

Summary
Find the minimum possible maximum of N nonnegative integers whose sum is S and whose XOR is X, or report -1 if no such sequence exists.
Level

Hard8 of 10

Topics
Bit manipulation, Binary search, Math
Solved
No attempts yet

문제

Determine whether there exists a sequence of NN nonnegative integers a1,a2,⋯ ,aNa_1, a_2, \cdots, a_N that satisfies both of the following conditions. If it exists, find the minimum possible value of the maximum element of the sequence.

  • a1+a2+⋯+aN=Sa_1+a_2+\cdots+a_N=S
  • a1⊕a2⊕⋯⊕aN=Xa_1 \oplus a_2 \oplus \cdots \oplus a_N=X (⊕\oplus is the bitwise xor operation)

The input file contains TT tests.

입력

Input is given from standard input in the following format:

TT

N1N_1 S1S_1 X1X_1

N2N_2 S2S_2 X2X_2

⋮\vdots

NTN_T STS_T XTX_T

Here, NiN_i, SiS_i, and XiX_i are the values of NN, SS, and XX for the ii-th test.

출력

Print TT lines. On the ii-th line, print −1-1 if no sequence satisfies the conditions in the ii-th test. Otherwise, print the minimum possible value of the maximum element.

제한

  • 1≤T≤5001 \leq T \leq 500
  • 1≤N≤260−11 \leq N \leq 2^{60}-1
  • 0≤S≤260−10 \leq S \leq 2^{60}-1
  • 0≤X≤260−10 \leq X \leq 2^{60}-1
  • All values in the input are integers.

힌트

The following is a solution for each test:

  • (3,3,3)
  • (2,2,2,2)
  • (2,3,3,3,4,4)
  • (15)
  • Impossible
  • Impossible

Examples1

  1. Example 1

    Input
    6
    3 9 3
    4 8 0
    6 19 1
    1 15 15
    2 6 5
    5 4 3
    
    Expected output
    3
    2
    4
    15
    -1
    -1