@@ -0,0 +1,1148 @@
+import java.util.*;%0Aimport static java.lang.Math.*;%0Aimport java.util.stream.*;%0A%0A/*%0AProblem name: 11475 Extend to Palindromes%0AProblem url: https://uva.onlinejudge.org/external/114/11475.pdf%0AAuthor: Andrey Yemelyanov%0A*/%0Apublic class _11475 %7B%0A  public static void main(String%5B%5D args)%7B%0A    Scanner s = new Scanner(System.in);%0A    while(s.hasNext())%7B%0A      System.out.println(toPalindrome(s.next()));%0A    %7D%0A  %7D%0A%0A  static String toPalindrome(String str)%7B%0A    int%5B%5D b = kmpPreprocess(reverse(str) + str);%0A    if(b%5Bb.length - 1%5D %3E= str.length()) return str;%0A    return str + reverse(str).substring(b%5Bb.length - 1%5D);%0A  %7D%0A%0A  static int%5B%5D kmpPreprocess(String pattern)%7B%0A    int%5B%5D b = new int%5Bpattern.length() + 1%5D;%0A    int i = 0; int j = -1; b%5B0%5D = -1;%0A    while(i %3C pattern.length())%7B%0A      while(j %3E= 0 && pattern.charAt(i) != pattern.charAt(j)) j = b%5Bj%5D;%0A      i++; j++;%0A      b%5Bi%5D = j;%0A    %7D%0A    return b;%0A  %7D%0A%0A  static String reverse(String str)%7B%0A    char%5B%5D c = str.toCharArray();%0A    for(int i = 0; i %3C c.length / 2; i++)%7B%0A      char temp = c%5Bi%5D;%0A      c%5Bi%5D = c%5Bc.length - 1 - i%5D;%0A      c%5Bc.length - 1 - i%5D = temp;%0A    %7D%0A    return new String(c);%0A  %7D%0A%7D%0A

11475 Extend to palindrome