Maximizing expressions

3.2

33 votes
Basic Programming, Bit Manipulation, Bit manipulation, Medium, Observation
Problem

You are given three arrays A,B, and C. All the three arrays consist of N integers.

You must perform the following operation on each index exactly one time:

Convert(i): Select a positive value D such that Ci & D=D, and update Bi=BiD.

Here,  and & denotes the bitwise XOR operation and bitwise AND operation.

You are required to maximize the following expression:

S=ni=1AiBi    

Input format

  • First line: A single integer N denoting the number of elements of the array
  • Next line: N integers of array A
  • Next line: N integers of array B
  • Next line: N integers of array C

Output format
Print a single integer that denotes the maximum value of S.

Constraints
1N105

1Ai,Bi,Ci<230

Sample Input
3
9 10 3
2 3 1
4 13 9
Sample Output
39
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For i=1, we can chose D=4
For i=2, we can chose D=4
For i=3, we can chose D=9

Editor Image

?