## XOR Sum

View as PDF

Points: 10
Time limit: 0.6s
Memory limit: 256M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Given an array of length , partition it into one or more contiguous groups. Once partitioned, take the XOR of the elements in each group. Compute the sum of these values. Bessie wants this sum to be minimal, Farmer John wants the sum to be maximal. Compute the difference between their sums.

#### Input

The first line of the input contains a single positive integer, . You may assume .

The second line of the input will contain space-separated integers, the integers of the array in order. These integers will be less than .

#### Output

Print on a single line the difference between the sums Bessie and Farmer John compute.

#### Sample Input

5
1 2 4 8 16

#### Sample Output

0

• commented on Jan. 14, 2020, 11:20 p.m.

Fun relevant fact:

XOR got the symbol from its similarity to the addition function. XOR essentially adds () the two bits at the same position of each number, then takes the result (). Quite interesting!

• commented on Jan. 14, 2020, 11:48 p.m.

Damn, 4fecta here spitting out cool facts. What a chad.

• commented on Jan. 15, 2020, 12:01 a.m.

on god :pray:

• commented on Jan. 15, 2020, 12:04 a.m.

This sounds like an usaco problem lol