import java.util.*;class Main{public static void main(String[]g)throws Exception{byte[]u=new byte[32767];String x,y,c="";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=new StringBuffer(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,"");}x="";for(Object z:new TreeSet(h.values()))x+=z;System.out.print((x+c)+(new StringBuffer(x).reverse().toString()));}}

@@ -216,15 +216,8 @@
 +n)%7B
-x=g%5Bn%5D;
 y=ne
@@ -224,32 +224,37 @@
 w StringBuffer(x
+=g%5Bn%5D
 ).reverse().toSt
@@ -416,15 +416,12 @@
 int(
-(
 x+c
-)+(
++
 new 
@@ -457,13 +457,12 @@
 tring())
-)
 ;%7D%7D%0A

Update test5.java