public class TrySail {
static int n;
static int all;
static int arr[];
static int DP[][][][] = new int[51][260][260][12];
// {178, 111, 60, 202, 194, 170, 118, 170, 99, 119, 142, 242, 229, 70, 243, 238, 74, 7}
static boolean getBit(int num, int idx) {
return ( ((num >> idx) & 1) == 1);
}
static int setBit(int num,int idx){
return num|((1<<idx));
}
static int solve(int idx,int s1,int s2,int msk)
{
if(idx == n)
{
if(getBit(msk,0) && getBit(msk,1) && getBit(msk,2)) return (all^s1^s2) + s1 + s2;
else return -50;
}
if(DP[idx][s1][s2][msk] != -1) return DP[idx][s1][s2][msk];
int ret = 0;
ret
= Math.
max(ret,solve
(idx
+1,s1,s2,setBit
(msk,
2))); ret
= Math.
max(ret,solve
(idx
+1,s1
^arr
[idx
],s2,setBit
(msk,
0))); ret
= Math.
max(ret,solve
(idx
+1,s1,s2
^arr
[idx
],setBit
(msk,
1)));
return DP[idx][s1][s2][msk] = ret;
}
public static int get(int[] strength)
{
arr = strength;
n = arr.length;
all = 0;
for(int i = 0 ;i < arr.length ; i++) all ^= arr[i];
for(int i = 0 ; i < 51 ; i++)
{
for(int j = 0 ; j < 260 ; j++)
{
for(int k = 0 ; k < 260 ; k++)
{
for(int f = 0 ; f < 12; f++)
DP[i][j][k][f] = -1;
}
}
}
return solve(0,0,0,0);
}
{
}
}
cHVibGljIGNsYXNzIFRyeVNhaWwgewoKCXN0YXRpYyBpbnQgbjsKCXN0YXRpYyBpbnQgYWxsOwoJc3RhdGljIGludCBhcnJbXTsKCXN0YXRpYyBpbnQgRFBbXVtdW11bXSA9IG5ldyBpbnRbNTFdWzI2MF1bMjYwXVsxMl07Ci8vIHsxNzgsIDExMSwgNjAsIDIwMiwgMTk0LCAxNzAsIDExOCwgMTcwLCA5OSwgMTE5LCAxNDIsIDI0MiwgMjI5LCA3MCwgMjQzLCAyMzgsIDc0LCA3fQoJc3RhdGljIGJvb2xlYW4gZ2V0Qml0KGludCBudW0sIGludCBpZHgpIHsKCQlyZXR1cm4gKCAoKG51bSA+P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