#include <algorithm>
#include <iostream>
#include <vector>
std::size_t xor_sum(const std::vector<std::uint32_t>& v)
{
std::size_t res = 0;
for (std::size_t b = 0; b != 32; ++b) {
const std::size_t count_0 =
std::count_if(v.begin(), v.end(),
[b](std::uint32_t n) { return (n >> b) & 0x01; });
const std::size_t count_1 = v.size() - count_0;
res += count_0 * count_1 << b;
}
return res;
}
int main() {
std::cout << xor_sum({3, 5, 7}); // 12 = 3^5 + 3^7 + 5^7
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKc3RkOjpzaXplX3QgeG9yX3N1bShjb25zdCBzdGQ6OnZlY3RvcjxzdGQ6OnVpbnQzMl90PiYgdikKewoJc3RkOjpzaXplX3QgcmVzID0gMDsKCQoJZm9yIChzdGQ6OnNpemVfdCBiID0gMDsgYiAhPSAzMjsgKytiKSB7CgkJY29uc3Qgc3RkOjpzaXplX3QgY291bnRfMCA9CgkJICAgIHN0ZDo6Y291bnRfaWYodi5iZWdpbigpLCB2LmVuZCgpLAoJCSAgICAgICAgICAgICAgICAgIFtiXShzdGQ6OnVpbnQzMl90IG4pIHsgcmV0dXJuIChuID4+IGIpICYgMHgwMTsgfSk7CgkJY29uc3Qgc3RkOjpzaXplX3QgY291bnRfMSA9IHYuc2l6ZSgpIC0gY291bnRfMDsKICAgICAgICByZXMgKz0gY291bnRfMCAqIGNvdW50XzEgPDwgYjsKCX0KCXJldHVybiByZXM7Cn0KCmludCBtYWluKCkgewogICAgc3RkOjpjb3V0IDw8IHhvcl9zdW0oezMsIDUsIDd9KTsgLy8gMTIgPSAzXjUgKyAzXjcgKyA1XjcKfQ==