public static int [] rad(String str){
StringBuilder newStr= new StringBuilder();
newStr.append('#');
for(int i=0;i<str.length();i++){
newStr.append(str.charAt(i));
newStr.append('#');
}
int [] rad = new int[newStr.length()];
int rightPoint = -1;
int symmetry = -1;
for (int cur = 0; cur < newStr.length(); cur ++) {
int r = 1;
if (cur <= rightPoint)
r = Math.min(rad[symmetry]+(symmetry-cur),rad[2*symmetry-cur]);
while (cur - r >= 0 && cur + r < newStr.length() && newStr.charAt(cur - r) == newStr.charAt(cur + r))
r++;
if(cur + r - 1> rightPoint){
rightPoint = cur + r - 1;
symmetry = cur;
}
rad[cur] = r;
}
return rad;
}