https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXSVhGoqED8DFAQT
모든 사탕 봉지 속 사탕 개수를 XOR 연산했을 때 결과가 0이면, 그 중 어떤 값을 선택하든 "해당 값 제외 모든 숫자를 XOR 연산한 값 == 해당 값" 이 된다.
따라서 우선 사탕 개수를 정렬한 뒤 모든 숫자를 xor 연산 한 결과가 0이면 리스트의 첫 값을 출력하고, 결과가 0이 아니면 NO를 출력하는 방식으로 풀었다.
T = int(input())
for tc in range(1, T+1):
N = int(input())
candies = sorted(list(map(int, input().split())))
xor_sum = 0
for i in range(N):
xor_sum ^= candies[i]
if xor_sum == 0:
print('#{} {}'.format(tc, sum(candies[1:])))
else:
print('#{} NO'.format(tc))
^