Language: Java

import java.util.Scanner;

/**
 * Created by sonekenichiro on 2017/04/26.
 */

public class ExtraordinaryGirl {
    static final int UPPER=1;
    static final int MIDDLE=2;
    static final int NEXTBOOKS_UPPER_AND_LOWER=11;
    static final int NEXTBOOKS_UPPER=12;
    static final int NEXTBOOKS_LOWER=13;
    static final int NEXTBOOKS_NONE=14;
    static char[] upperBooks;
    static char[] lowerBooks;


    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int testCaseNum = scan.nextInt();

        for(int i = 0;i<testCaseNum;i++){

            scan = new Scanner(System.in);
            int n = scan.nextInt();

            scan = new Scanner(System.in);
            String books= scan.nextLine();

            upperBooks = new char[2*n];
            lowerBooks = new char[2*n];

            for(int j =0; j<upperBooks.length;j++){
                upperBooks[j]=books.charAt(j);
                System.out.print(upperBooks[j]+",");
            }
            System.out.println("--");

            for(int j =0; j<lowerBooks.length;j++){
                lowerBooks[j]=books.charAt(j+(2*n));
                System.out.print(lowerBooks[j]+",");
            }

            System.out.println("--");
            System.out.println(calculateCost(0,n,UPPER));
        }
    }

    static boolean areBooksInUpperShelf(int num){
        return upperBooks[num*2]=='Y'||upperBooks[num*2-1]=='Y';
    }
    static boolean areBooksInLowerShelf(int num){
        return lowerBooks[num*2]=='Y'||lowerBooks[num*2-1]=='Y';
    }
    
    static int whereNextBooks(int num,int maxNum){
        if(num==maxNum){
            if(lowerBooks[num*2-1]=='Y'&&upperBooks[num*2-1]=='Y'){
                return NEXTBOOKS_UPPER_AND_LOWER;
            }else if(upperBooks[num*2-1]=='Y'){
                return NEXTBOOKS_UPPER;
            }else if(lowerBooks[num*2-1]=='Y'){
                return NEXTBOOKS_LOWER;
            }else{
                return NEXTBOOKS_NONE;
            }
        }else{
            if(areBooksInLowerShelf(num)&&areBooksInUpperShelf(num)){
                return NEXTBOOKS_UPPER_AND_LOWER;
            }else if(areBooksInUpperShelf(num)){
                return NEXTBOOKS_UPPER;
            }else if(areBooksInLowerShelf(num)){
                return NEXTBOOKS_LOWER;
            }else{
                return whereNextBooks(num+1,maxNum);
            }
        }

    }

    static int calculateCost(int num,int maxNum,int position){
        if(num==0){
            //????????????????????????????????????????????????

            if(lowerBooks[num]=='Y'){
                position=MIDDLE;//???????£????????????´??????????????????????????????????????????????????????
                int cost = calculateCost(num+1,maxNum,position);
                return cost+3;
            }else if(upperBooks[num]=='Y'){

                //?¬??????¬????????¨???????£???????????£??????????????????????????????????
                int nextBooksState=whereNextBooks(num+1,maxNum);
                if(nextBooksState==NEXTBOOKS_LOWER){
                    position=MIDDLE;
                }else{
                    position=UPPER;
                }

                int cost = calculateCost(num+1,maxNum,position);
                return cost+2;
            }else{
                int cost = calculateCost(num+1,maxNum,position);
                return cost+1;
            }
        }else if(num==maxNum){
            if(position==UPPER){
                if(lowerBooks[num*2-1]=='Y'){
                    return 3;
                }else if(upperBooks[num*2-1]=='Y'){
                    return 1;
                }else{
                    return 0;
                }
            }else{
                if(lowerBooks[num*2-1]=='Y') {
                    return 2;
                }else{
                    return 1;
                }
            }
        }else{

            if(position == UPPER){
                if(areBooksInLowerShelf(num)){

                    position = MIDDLE;
                    int cost = calculateCost(num+1,maxNum,position);
                    return cost+3;

                }else if(areBooksInUpperShelf(num)){

                    int nextBooksState=whereNextBooks(num+1,maxNum);
                    if(nextBooksState==NEXTBOOKS_LOWER){
                        position=MIDDLE;
                    }else{
                        position=UPPER;
                    }


                    int cost = calculateCost(num+1,maxNum,position);
                    return cost+2;


                }else{
                    int cost =calculateCost(num+1,maxNum,position);
                    return cost+1;
                }
            }else{
                if(areBooksInUpperShelf(num)){


                    int nextBooksState=whereNextBooks(num+1,maxNum);
                    if(nextBooksState==NEXTBOOKS_LOWER){
                        position=MIDDLE;
                    }else{
                        position=UPPER;
                    }

                    if(areBooksInLowerShelf(num)){
                        int cost = calculateCost(num+1,maxNum,position);
                        return cost+3;
                    }else{
                        int cost = calculateCost(num+1,maxNum,position);
                        return cost+2;
                    }

                }else if(areBooksInLowerShelf(num)){

                    int cost = calculateCost(num+1,maxNum,position);
                    return cost+2;

                }else{
                    int cost = calculateCost(num+1,maxNum,position);
                    return cost+1;
                }
            }
        }



    }

}

Compiler output:
Main.java:7: error: class ExtraordinaryGirl is public, should be declared in a file named ExtraordinaryGirl.java
public class ExtraordinaryGirl {
       ^
1 error