You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

Examples

Input

ABA


Output

NO


Input

BACFAB


Output

YES


Input

AXBYBXA


Output

NO

Note

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".
import java.io.*;
import java.io.PrintWriter;
import java.util.*;
import java.io.InputStream;
import java.io.DataInputStream;
 
 
public class Main
{//static{ System.out.println(" hello ");}

   
  public static void main(String[] args) throws IOException
     { 
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader scn = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
       String s=scn.ns();
       int len=s.length();
       int flag=0; int p=0,q=0;
       for (int i=0;i<=len-2;i++)
       {
           String s1=s.substring(i,i+2);
            if (s1.equals("AB")) q=1;
            if (s1.equals("BA")) p=1;
           
        }   
       
        if (p==1 && q==1)
        {
      ArrayList<Integer> ar1=new ArrayList<Integer>();
      ArrayList<Integer> ar2=new ArrayList<Integer>();
      
       for (int i=0;i<=len-2;i++)
       {
           String s1=s.substring(i,i+2);
            if (s1.equals("AB")) ar1.add(i);
            if (s1.equals("BA")) ar2.add(i);
           
        }   
       Collections.sort(ar1);
       Collections.sort(ar2);
       int a1=ar1.get(0);
       int a2=ar1.get(ar1.size()-1);
       int a3=ar2.get(0);
       int a4=ar2.get(ar2.size()-1);
       
       
       
       
        if (Math.abs(a1-a4)>1 || Math.abs(a2-a3)>1)
        out.println("YES");
        else
        out.println("NO");
        
        
    }
    else
       out.println("NO");
        
          out.close();
     }
    
     
     
  
   }       
  class num //implements Comparator<num>
    {
        
        public int start;
        public int end;
        num()
        {
            
        }
        num(int x,int y)
        {
            this.start = x;
            this.end =y;
        }
        public int getstart()
        {
        return start;
        }
        public int getend()
        {
        return end;
        }
    /*    public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.start==n.start && this.end==n.end) return true;
        else return false;
            
            
        }
        
        
         public int hashCode() 
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + start;
        result = prime * result+end;
               
        return result;
       }
       
       
        
       public int compare(num o1, num o2) {
              if (o1.getstart() > o2.getstart())
            return (o1.getstart()-o2.getstart());
            else if (o1.getstart() == o2.getstart())
            return (o1.getend()-o2.getend());
            else 
            return (o1.getstart()-o2.getstart());
            
        }
      */  
        
        
    }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class FastReader
{
 
    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
 
    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }
 
    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }
    
 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }
    
    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {

                
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }
 
    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }
 
    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }
 
    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }
 
    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
 
    public String next()
    {
        return ns ();
    }
 
    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}   