A foundry's production log records the quality code of every batch produced during a shift, as a sequence of non-negative integers in production order. Before the shift's batches can be cleared for shipping, the yard supervisor must compute a single composite code for the manifest: it is formed by taking the bitwise OR of the quality codes of every batch whose code is an even number. Batches whose code is odd play no part in the composite code at all. If the shift produced no batch with an even code, the composite code is defined to be 0.
Given the sequence of quality codes, compute the composite code for the manifest.
The first line contains a single integer n, the number of batches produced during the shift. The second line contains n space-separated non-negative integers code[0], code[1], ..., code[n-1], the quality code of each batch in production order.
Print a single integer: the bitwise OR of every code[i] that is even, or 0 if no code[i] is even.
Example 1
Input
5 1 3 8 4 6
Expected
14
Explanation
The even-valued batch codes are 8, 4 and 6 (1 and 3 are odd and are discarded). Their bitwise OR is 8 | 4 | 6 = 1000b | 0100b | 0110b = 1110b = 14.
Example 2
Input
3 1 3 5
Expected
0
Explanation
Every code (1, 3, 5) is odd, so no batch contributes to the composite code. The result defaults to 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →