Expert Computation
Complex physics experiments often have an underlying simple mathematical structure. In one such experiment that compares mathematical and empirical values, you are given three integer arrays, and asked to compute the experiment result mathematically.
From the given input arrays , , and , you are required to generate arrays , , and , each of equal length , based on the following function.
A function is defined for a given , where a value of is chosen such that is maximum where .
Let the modulo . Your task is to find .
Arrays , , and are generated from , , and , as follows:
where ( is a bitwise xor operation).
For example, given = , = , =
1 | 3 | 4 | 0 | 1 | 3*4 - 3*4 | 0 |
2 | 4 | 9 | 0 | 1 | 9*3 - 4*4 | 11 |
Complete the function expertComputation
that takes 3 integer arrays as input, and return a single integer denoting the appropriate value for .
Input Format
The first line contains a single integer denoting the length of the arrays.
Next lines contain arrays , , and , respectively.
Constraints
- where .
Output Format
Output the appropriate answer.
Sample Input 0
5
3 4 14 5 6
4 9 12 8 9
0 0 9 12 13
Sample Output 0
17
Explanation 0
Given that,
=
=
=
For every value of from to ,
1 | 3 | 4 | 0 | 1 | 3*4 - 3*4 | 0 |
2 | 4 | 9 | 0 | 1 | 3*9 - 4*4 | 11 |
3 | 5 | 7 | 2 | 1 | 3*7 - 4*5 | 12 |
4 | 9 | 4 | 0 | 4 | 4*9 - 4*9 | 12 |
5 | 10 | 5 | 1 | 4 | 5*9 - 4*10 | 17 |
From the table it is clear that,
=
=
=
Before computing in every step, choose in such a way that the maximum value of can be obtained.
For example, in the case of ,
Hence,
- which is the maximum value.
When is computed in a similar manner for all values of , would be for each respectively. So the answer is
Sample Input 1
3
2 6 4
1 9 11
0 0 14
Sample Output 1
18
xxxxxxxxxx
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada;
procedure Solution is
-- Enter your code here. Read input from STDIN. Print output to STDOUT
end Solution