package Demoes;

import java.util.Scanner;

/**
 * Created by Yogurt on 16/6/30.
 */
public class BestCowLine_POJ_3617 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        StringBuilder res=new StringBuilder();
        int a=0,b=str.length()-1;
        while (a<=b){
            boolean left=false;
            for (int i=0;a+i<b;i++){
                if(str.charAt(a+i)<str.charAt(b-i)){
                    left=true;
                    break;
                }else if(str.charAt(a+i)>str.charAt(b-i)){
                    left=false;
                    break;
                }
            }
            if (left) res.append(str.charAt(a++));
            else res.append(str.charAt(b--));
        }
        System.out.println(res);
    }
}

@@ -213,19 +213,138 @@
     
-String str=
+int N=sc.nextInt();%0A        sc.nextLine();%0A        StringBuilder str=new StringBuilder();%0A        for(int i=0;i%3CN;i++) str.append(
 sc.n
@@ -344,32 +344,33 @@
 nd(sc.nextLine()
+)
 ;%0A        String
@@ -424,20 +424,9 @@
 0,b=
-str.length()
+N
 -1;%0A
@@ -892,16 +892,179 @@
         
+for(int i=0;i%3Cres.length();i++)%7B%0A            if(i%3E0&&i%2580==0)%0A                System.out.println();%0A            System.out.print(res.charAt(i));%0A        %7D%0A        
 System.o
@@ -1074,19 +1074,16 @@
 println(
-res
 );%0A    %7D

fixed the longest common sub sequence problem