import java.io.*;import java.util.*;class Main{static BufferedReader i=new BufferedReader(new InputStreamReader(System.in));static String x,y;static int d;static Object[]w;static StringBuilder b=new StringBuilder(),c=new StringBuilder();static HashMap<String,String>h=new HashMap<>();public static void main(String[]a)throws Exception{i.readLine();while((x=i.readLine())!=null){y=b.replace(0,x.length(),x).reverse().toString();d=x.compareTo(y);if(d==0)c.append(x);else if(h.containsKey(x))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);System.out.print(c);System.out.print(b.reverse());}}

@@ -40,23 +40,67 @@
 ss Main%7B
-static 
+public static void main(String%5B%5Da)throws Exception%7B
 Buffered
@@ -161,23 +161,16 @@
 em.in));
-static 
 String x
@@ -176,27 +176,15 @@
 x,y;
-static
  int d;
-static
  Obj
@@ -190,22 +190,16 @@
 ject%5B%5Dw;
-static
  StringB
@@ -253,37 +253,12 @@
 r();
-static HashMap%3CString,String%3E
+Map 
 h=ne
@@ -270,64 +270,11 @@
 hMap
-%3C%3E
 ();
-public static void main(String%5B%5Da)throws Exception%7B
 i.re

Update test5.java