In this problem, every string has a beauty value which is represented as a positive integer.
The elegance of a sequence of strings is defined as
where denotes the beauty of string , and represents the bitwise XOR operation. In particular, the elegance of a sequence of just one string is just the beauty value of that string. Also, the elegance of an empty sequence is .
Diane has strings , each consisting of the digits to , and has beauty value . She would like to form the most elegant sequence of strings among them. She can write any string with her digit cards; for every digit from to , she has exactly cards in which the digit is written, so she has cards in total. For example, 1 digit card each for every number to would be,
She may write the strings in any order, but she can only form each string at most once.
To write a string, she has to use the cards. But each card can only be used once, so it may not be possible to write all strings.
Given the above restrictions, what is the maximum elegance of any sequence that Diane can form?
Complete the function maximumElegance which takes in an integer , an array consisting of strings, and an array consisting of integers denoting their respective beauty values and returns the maximum elegance of any sequence that Diane can form.
The first line contains two space-separated integers and .
The second line contains space-separated integers denoting the beauty values of the strings.
The of the next lines contains the string, .
is a string of digits -.
For ~20% of the total score,
Print a single integer denoting the maximum elegance which can be obtained by Diane.
Sample Input 0
3 22 3 11032246748957
Sample Output 0
Note that , which means we have two cards for each digit, and so we can write all three strings.
If we write all three strings in the order , then we get an elegance of , which is the maximum possible.