import java.util.*;class Main{public static void main(String[]g)throws Exception{byte[]u=new byte[32767];String x,y,c="";Object[]w;StringBuilder b=new StringBuilder();Map h=new HashMap();int d,n=0;g=new String(u,0,System.in.read(u)).split("\n");while(g.length>++n){x=g[n];y=b.replace(0,x.length(),x).reverse().toString();d=x.compareTo(y);if(d==0)c+=x;else if(h.get(x)!=null)h.put(x,d<0?x:y);else h.put(y,"");}w=h.values().toArray();Arrays.sort(w);b.delete(0,b.length());for(Object z:w)b.append(z);System.out.print(b+c);System.out.print(b.reverse());}}

@@ -511,39 +511,34 @@
 int(
+(
 b+c)
-;System.out.print(b.reverse
++b.reverse().toString
 ());

Update test5.java