For this Question: A string is called AB string if it's of length at least 2 and all it's characters are A except the last character which is B.

You have an empty string s, you can do the following operation any number of times.
 
Choose any position of s and insert any AB string in that position.

You are given a string t of some length containing only A and B. Find out if it is possible to convert s to t after some operations.First line contains N denoting the length of t.
Next line contains t.

<b>Constraints</b>
1 <= N <= 10<sup>5</sup>
t contains only A and B.Output "YES" or "NO".Input:
5
AAABB

Output:
YES

Explanation :
"" => "AAB" => "AA "AB" B" => "AAABB"


Input:
3
ABB

Output:
NO
, I have written this Solution Code: import java.io.*;
import java.util.*;


public class Main {
     
    public static void main(String[] args) {
        
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        
        int n=Integer.parseInt(in.next());
        String s=in.next();
        
        int cnt=0;
        int f=0;
        for(int i=n-1;i>=0;i--){
            if(s.charAt(i) == 'A'){
                if(cnt == 0){
                    if(f == 0){
                        f=-1;
                        break;
                    }
                }
                else cnt--;
            }
            else{
                cnt++;
                f=1;
            }
        }
        if(f == -1 || cnt != 0){
            out.print("NO");
        }
        else out.print("YES");
        out.close();
    }

    
    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not?