Skip to content

Instantly share code, notes, and snippets.

@irokez
Created April 11, 2012 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irokez/2363015 to your computer and use it in GitHub Desktop.
Save irokez/2363015 to your computer and use it in GitHub Desktop.
Problem C. Candy Splitting
import sys
T = int(sys.stdin.readline().strip())
for t in range(T):
C = int(sys.stdin.readline().strip())
num = sorted(int(n) for n in sys.stdin.readline().strip().split(' '))
left = 0
right = 0
realsum = 0
for n in num:
right ^= n
realsum += n
cur = num.pop(0)
realsum -= cur
left = cur
right ^= cur
while left != right and len(num):
cur = num.pop(0)
if not len(num):
break
# print(cur, left, right, realsum)
left ^= cur
right ^= cur
realsum -= cur
print('Case #{0}: {1}'.format(t + 1, realsum if left == right else 'NO'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment