import java.util.*;
import java.io.*;
public class Programa {
	public static boolean is(String s)
	{
		for(int i = 0, j = s.length() - 1; i < s.length(); i++, j--)
			if(s.charAt(i) != s.charAt(j))
				return false;
		return true;
	}

	public static int consecutive(int [] v){
		int maxi = 0;
		for(int i = 0; i < v.length; i++){
			int cont = 0;

			if(v[i] == 1) cont++;
			while(i + 1 < v.length && v[i] == 1 && v[i] == v[i + 1]){
				cont++;
				i++;

			}

			if(maxi < cont)
				maxi = cont;
		}
		return maxi;
	}
	public static String girar(String s){
		char [] v = s.toCharArray();

		char c = v[0];
		for(int j = 1; j < v.length; j++){
			v[j-1] = v[j];
		}
		v[v.length-1] = c;

		String g = "";
    	for(int i =0 ; i < v.length; i++)
    		g += v[i];
    	return g;
	}

	public static String convert(char [] v){
		String s = "";
		for(int i = 0; i < v.length; i++)
			s += v[i];
		return s;
	}

	public static String bestmod(String s, int k)
	{
		String mini = "";
		char [] a= s.toCharArray();
		for(int j = 0; j < k; j++)
			a[j] = 'a';
		mini = convert(a);

		for(int i = 0; i < s.length(); i++){
			String temp = girar(s);

			char [] v= temp.toCharArray();
			int r = 0;
			for(int j = 0; j < k; j++){
				while(r < s.length() && v[r] == 'a'){
					r++;
					continue;
				}
				if(r < s.length())v[r] = 'a';
			}
			String b = convert(v);

			if(mini.compareTo(b) > 0)
				mini = b;
			s = temp;

		}

		return mini;
	}

    public static void main(String [] args){
    	Scanner scan = new Scanner (System.in);
    	char [] v = scan.next().toCharArray();
    	boolean [] f = {false, false,false};
    	int cont = 0, contb = 0;
    	for(int i = 0; i < v.length - 1; i++){
    		if(v[i] == 'A' && v[i+1] == 'B'){
    			f[0] = true;
    			v[i] = '?';v[i+1] = '?';
    			break;
    		}
    	}
    	for(int i = 0; i < v.length - 1; i++){
    		if(v[i] == 'B' && v[i+1] == 'A'){
    			f[1] = true;
    			v[i] = '?';v[i+1] = '?';
    			break;
    		}
    	}
    	if(f[0] && f[1])
    		System.out.println("YES");
    	else
    		System.out.println("NO");
    }

    /*

     */
}


import java.util.*;
import java.io.*;
public class Programa {
	public static boolean is(String s)
	{
		for(int i = 0, j = s.length() - 1; i < s.length(); i++, j--)
			if(s.charAt(i) != s.charAt(j))
				return false;
		return true;
	}

	public static int consecutive(int [] v){
		int maxi = 0;
		for(int i = 0; i < v.length; i++){
			int cont = 0;

			if(v[i] == 1) cont++;
			while(i + 1 < v.length && v[i] == 1 && v[i] == v[i + 1]){
				cont++;
				i++;

			}

			if(maxi < cont)
				maxi = cont;
		}
		return maxi;
	}
	public static String girar(String s){
		char [] v = s.toCharArray();

		char c = v[0];
		for(int j = 1; j < v.length; j++){
			v[j-1] = v[j];
		}
		v[v.length-1] = c;

		String g = "";
    	for(int i =0 ; i < v.length; i++)
    		g += v[i];
    	return g;
	}

	public static String convert(char [] v){
		String s = "";
		for(int i = 0; i < v.length; i++)
			s += v[i];
		return s;
	}

	public static String bestmod(String s, int k)
	{
		String mini = "";
		char [] a= s.toCharArray();
		for(int j = 0; j < k; j++)
			a[j] = 'a';
		mini = convert(a);

		for(int i = 0; i < s.length(); i++){
			String temp = girar(s);

			char [] v= temp.toCharArray();
			int r = 0;
			for(int j = 0; j < k; j++){
				while(r < s.length() && v[r] == 'a'){
					r++;
					continue;
				}
				if(r < s.length())v[r] = 'a';
			}
			String b = convert(v);

			if(mini.compareTo(b) > 0)
				mini = b;
			s = temp;

		}

		return mini;
	}

    public static void main(String [] args){
    	Scanner scan = new Scanner (System.in);
    	char [] v = scan.next().toCharArray();
    	int [] k = new int[10];
    	for(int i = 0; i < v.length; i++){
    		if((v[i] -'0') == 0){
    			System.out.println("YES");
    			System.out.println(0);
    			System.exit(0);
    		}
    		if((v[i] -'0') == 8){
    			System.out.println("YES");
				System.out.println(8);
				System.exit(0);
    		}
    		k[v[i] -'0']++;
    	}

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

    		int[] temp = new int[k.length];
        	for(int j = 0; j < k.length; j++)
        		temp[j] = k[j];

    		if(temp[i] > 0){
	        	temp[i]--;
	    		for(int j = 0; j < 10; j++){
	    			if(temp[j] > 0){
	    				temp[j]--;
	    				int m1 =  i*10+j;
    					if(m1 % 8 == 0){
    						System.out.println("YES");
    						System.out.println(m1);
    						System.exit(0);
    					}
		    			for(int z = 0; z < 10; z++){
		    				if(temp[z] > 0){
		    					temp[z]--;
		    					int m =  i*100+j*10+z;
		    					if(m % 8 == 0){
		    						System.out.println("YES");
		    						System.out.println(m);
		    						System.exit(0);
		    					}
		    				}
		    			}
	    			}
	    		}
    		}
    	}
    	System.out.println("NO");
    }

    /*

     */
}


import java.util.Scanner;
public class a  {
  public static void main(String[]args) {
    Scanner in=new Scanner(System.in);
    String s=in.next();
    s=s.replaceAll("ABA","");
    if(s.contains("AB")&&s.contains("BA")&&!s.contains("ABA"))
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}


import java.util.Scanner;
public class a  {
  public static void main(String[]args) {
    Scanner in=new Scanner(System.in);
    String s=in.next();
    boolean x=(s.contains("BA")&&s.contains("AB")&&(s.indexOf("AB")!=s.indexOf("BA")+1||s.indexOf("BA")!=s.indexOf("AB")+1)
    System.out.println(x?"YES":"NO");
  }
}


import java.util.Scanner;
public class a  {
  public static void main(String[]args) {
    Scanner in=new Scanner(System.in);
    String s=in.next();
    while(s.contains("ABA")||s.contains("BAB")) {
        s=s.replaceAll("ABA","");
        s=s.replaceAll("BAB","");
    }
    System.out.println(s.contains("AB")&&s.contains("BA")?YES":"NO");
  }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out  = new PrintWriter(System.out);
        String s = in.next();
        int leftab = s.indexOf("AB");
        int rightab = s.lastIndexOf("AB");
        int leftba = s.indexOf("BA");
        int rightba = s.lastIndexOf("BA");
        if ((leftab > -1 && rightba > -1 && rightba - leftab > 1) ||
                (leftba > -1 && rightab > -1 && rightab - leftba > 1))
            out.println("YES");
        else
            out.println("NO");
        out.close();
    }
}


import java.util.Scanner;
public class a  {
  public static void main(String[]args) {
    Scanner in=new Scanner(System.in);
    String s=in.next();
    while(s.contains("ABA")||s.contains("BAB")) {
        s=s.replaceAll("ABA","");
        s=s.replaceAll("BAB","");
    }
    System.out.println(s.contains("AB")&&s.contains("BA")?"YES":"NO");
  }
}


import java.util.Scanner;
public class a  {
  public static void main(String[]args) {
    Scanner in=new Scanner(System.in);
    String s=in.next();
    boolean x=(s.contains("BA")&&s.contains("AB")&&(s.indexOf("AB")!=s.indexOf("BA")+1||s.indexOf("BA")!=s.indexOf("AB")+1));
    System.out.println(x?"YES":"NO");
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		char[] input = bf.readLine().toCharArray();
		char[] temp = new char[input.length];
//		for (int i = 0; i < input.length; i++) {
//			temp[i] = input[i];
//		}
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		if (AB && BA){
			System.out.println("YES");
			return;
		}

		//สลับเงื่อนไขขึ้นก่อน
		AB = false;
		BA = false;
		input = temp;
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		char[] input = bf.readLine().toCharArray();
		char[] temp = input;
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		if (AB && BA){
			System.out.println("YES");
			return;
		}

		//สลับเงื่อนไขขึ้นก่อน
		AB = false;
		BA = false;
		input = temp;
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		char[] input = bf.readLine().toCharArray();
		char[] temp = input;
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		if (AB && BA){
			System.out.println("YES");
			return;
		}

		//สลับเงื่อนไขขึ้นก่อน
		AB = false;
		BA = false;
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class A550 {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		String input = bf.readLine();
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='A' && input.charAt(i+1)=='B') {
				try {
					if (input.charAt(i-1)=='B') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				try {
					if (input.charAt(i+2)=='A') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				System.out.println("YES");
				return;
			}
			else if (input.charAt(i)=='B' && input.charAt(i+1)=='A') {
				try {
					if (input.charAt(i-1)=='A') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				try {
					if (input.charAt(i+2)=='B') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				System.out.println("YES");
				return;
			}
		}//end for-loop
		System.out.println("NO");
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class A550 {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		String input = bf.readLine();
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='A' && input.charAt(i+1)=='B') {
				try {
					if (input.charAt(i-1)=='B') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				try {
					if (input.charAt(i+2)=='A') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				AB = true;
			}
			else if (input.charAt(i)=='B' && input.charAt(i+1)=='A') {
				try {
					if (input.charAt(i-1)=='A') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				try {
					if (input.charAt(i+2)=='B') {
						continue;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				BA = true;
			}
		}//end for-loop
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		char[] input = bf.readLine().toCharArray();
		char[] temp = new char[input.length];
		for (int i = 0; i < input.length; i++) {
			temp[i] = input[i];
		}
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		if (AB && BA){
			System.out.println("YES");
			return;
		}

		//สลับเงื่อนไขขึ้นก่อน
		AB = false;
		BA = false;
		input = temp;
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		for (int i = 0; i < input.length-1; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		String input = bf.readLine();
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='A' && input.charAt(i+1)=='B' && !AB) {
				AB = true;
				++i;
			}
			else if (input.charAt(i)=='B' && input.charAt(i+1)=='A' && !BA) {
				BA = true;
				++i;
			}
		}//end for-loop
		if (AB && BA){
			System.out.println("YES");
			return;
		}
		boolean AB = false;
		boolean BA = false;
		//สลับเงื่อนไขขึ้นก่อน
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='B' && input.charAt(i+1)=='A' && !BA) {
				BA = true;
				++i;
			}
			else if (input.charAt(i)=='A' && input.charAt(i+1)=='B' && !AB) {
				AB = true;
				++i;
			}

		}//end for-loop
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		char[] input = bf.readLine().toCharArray();
		char[] temp = new char[input.length];
		for (int i = 0; i < temp.length; i++) {
			temp[i] = input[i];
		}
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		if (AB && BA){
			System.out.println("YES");
			return;
		}

		//สลับเงื่อนไขขึ้นก่อน
		AB = false;
		BA = false;
		input = temp;
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='B' && input[i+1]=='A' && !BA) {
				BA = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop BA
		for (int i = 0; i < input.length; i++) {
			if (input[i]=='A' && input[i+1]=='B' && !AB) {
				AB = true;
				input[i] = 'X';
				input[i+1] = 'X';
				break;
			}
		}//end for-loop AB
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		String input = bf.readLine();
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='A' && input.charAt(i+1)=='B' && !AB) {
				AB = true;
				++i;
			}
			else if (input.charAt(i)=='B' && input.charAt(i+1)=='A' && !BA) {
				BA = true;
				++i;
			}
		}//end for-loop
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A550 {
/*
 * SPECIAL CASE: ABBA, BAAB, ABABA, BABAB
 */
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		String input = bf.readLine();
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='A' && input.charAt(i+1)=='B' && !AB) {
				AB = true;
				++i;
			}
			else if (input.charAt(i)=='B' && input.charAt(i+1)=='A' && !BA) {
				BA = true;
				++i;
			}
		}//end for-loop
		if (AB && BA){
			System.out.println("YES");
			return;
		}
		AB = false;
		BA = false;
		//สลับเงื่อนไขขึ้นก่อน
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='B' && input.charAt(i+1)=='A' && !BA) {
				BA = true;
				++i;
			}
			else if (input.charAt(i)=='A' && input.charAt(i+1)=='B' && !AB) {
				AB = true;
				++i;
			}

		}//end for-loop
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class A550 {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		String input = bf.readLine();
		boolean AB = false;
		boolean BA = false;
		for (int i = 0; i < input.length()-1; i++) {
			if (input.charAt(i)=='A' && input.charAt(i+1)=='B') {
				AB = true;
				++i;
			}
			else if (input.charAt(i)=='B' && input.charAt(i+1)=='A') {
				BA = true;
				++i;
			}
		}//end for-loop
		if (AB && BA)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


package hw07;

import java.util.*;

public class test {

    public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    boolean aB, bA, finl, aBIndSet, bAIndSet;
    aB=bA=finl=aBIndSet=bAIndSet = false;
    int lastIndexAB, lastIndexBA;
    lastIndexAB = lastIndexBA=-2;

    String sub;
    String s = console.nextLine();
    for (int i=0; i<s.length()-1; i++){

        sub = s.substring(i,i+2);

        if (sub.equals("AB")){
            aB=true;
            aBIndSet= true;
            if (!aBIndSet)
            lastIndexAB = i;
        } else if (sub.equals("BA") ){
            bA= true;
            bAIndSet= true;
            if (!bAIndSet)
            lastIndexBA=i;
        }
        if ((aB && sub.equals("BA") && lastIndexAB != i-1)
                || ((bA && sub.equals("AB") && lastIndexBA != i-1))) {
            finl = true;
            break;
        }

    }
    if (finl) {
        System.out.println("YES");
    } else
        System.out.println("NO");

    }
}


import java.util.*;

public class test {

    public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    boolean aB = false;
    boolean bA = false;
    boolean finl = false;
    String sub;
    String s = console.nextLine();
    for (int i=0; i<s.length()-1; i++){

        sub = s.substring(i,i+2);

        if (sub.equals("AB")&& !aB){
            aB=true;
            ++i;
        } else if (sub.equals("BA") && !bA){
            bA= true;
            ++i;
        }
        if ((aB && sub.equals("BA"))
                || ((bA && sub.equals("AB")))) {
            finl = true;
            break;
        }

    }
    if (finl) {
        System.out.println("YES");
    } else
        System.out.println("NO");

    }
}


import java.util.*;

public class test {

	public static void main(String[] args) {
	Scanner console = new Scanner(System.in);
	boolean aB, bA, finl, aBIndSet, bAIndSet;
	aB=bA=finl=aBIndSet=bAIndSet = false;
	int lastIndexAB, lastIndexBA;
	lastIndexAB = lastIndexBA=-2;

	String sub;
	String s = console.nextLine();
	for (int i=0; i<s.length()-1; i++){

		sub = s.substring(i,i+2);

		if (sub.equals("AB")){
			aB=true;

			if (!aBIndSet)
			lastIndexAB = i;

			aBIndSet= true;
		} else if (sub.equals("BA") ){
			bA= true;

			if (!bAIndSet)
			lastIndexBA=i;

			bAIndSet= true;
		}
		if ((aB && sub.equals("BA") && lastIndexAB != i-1)
				|| ((bA && sub.equals("AB") && lastIndexBA != i-1))) {
			finl = true;
			break;
		}

	}
	if (finl) {
		System.out.println("YES");
	} else
		System.out.println("NO");

	}
}


import java.util.*;

public class test {

    public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    boolean aB = false;
    boolean bA = false;
    boolean finl = false;
    int lastIndexAB, lastIndexBA;
    lastIndexAB = lastIndexBA=-2;

    String sub;
    String s = console.nextLine();
    for (int i=0; i<s.length()-1; i++){

        sub = s.substring(i,i+2);

        if (sub.equals("AB")){
            aB=true;
            lastIndexAB = i;
        } else if (sub.equals("BA") ){
            bA= true;
            lastIndexBA=i;
        }
        if ((aB && sub.equals("BA") && lastIndexAB != i-1)
                || ((bA && sub.equals("AB") && lastIndexBA != i-1))) {
            finl = true;
            break;
        }

    }
    if (finl) {
        System.out.println("YES");
    } else
        System.out.println("NO");

    }
}


import java.util.*;

public class test {

	public static void main(String[] args) {
	Scanner console = new Scanner(System.in);
	boolean aB = false;
	boolean bA = false;
	boolean finl = false;
	String sub;
	String s = console.nextLine();
	for (int i=0; i<s.length()-1; i++){

		sub = s.substring(i,i+2);

		if (sub.equals("AB")){
			aB=true;
			++i;
		} else if (sub.equals("BA")){
			bA= true;
			++i;
		}
		if ((aB && sub.equals("BA"))
				|| ((bA && sub.equals("AB")))) {
			finl = true;
			break;
		}

	}
	if (finl) {
		System.out.println("YES");
	} else
		System.out.println("NO");

	}
}


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

public class tmp {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        int indab = s.indexOf("AB");
        int indba = s.indexOf("BA");

        if(indba == -1 || indab == -1)
            System.out.println("NO");
        else if (Math.abs(indba-indab) > 1){
            System.out.println("YES");
        }else{
            if(indab < indba)
                System.out.println(s.indexOf("BA", indba+1) > 0 ? "YES" : s.indexOf("AB", indba+2)>0 ? "YES":"NO");
            else
                System.out.println(s.indexOf("AB", indab+1) > 0 ? "YES" : s.indexOf("BA", indab+2)>0 ? "YES":"NO");
        }

    }

}


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

public class tmp {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        int indab = s.indexOf("AB");
        int indba = s.indexOf("BA");

        if(indab == -1 || indba == -1)
            System.out.println("NO");
        else if (indab < indba){
            System.out.println(indba > indab+1 ? "YES" : s.indexOf(s, indba+1)>0 ? "YES":"NO");
        }else{
            System.out.println(indab > indba+1 ? "YES" : s.indexOf(s, indab+1)>0 ? "YES":"NO");
        }

    }

}


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

public class tmp {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        int indab = s.indexOf("AB");
        int indba = s.indexOf("BA");

        if (Math.abs(indba-indab) > 1){
            System.out.println("YES");
        }else{
            if(indab < indba)
                System.out.println(s.indexOf("AB", indba+2)>0 ? "YES":"NO");
            else
                System.out.println(s.indexOf("BA", indab+2)>0 ? "YES":"NO");
        }

    }

}


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

public class tmp {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        int indab = s.indexOf("AB");
        int indba = s.indexOf("BA");
        if(indba == -1 || indab == -1)
            System.out.println("NO");
        else if (Math.abs(indba-indab) > 1){
            System.out.println("YES");
        }else{
            if(indab < indba)
                System.out.println(s.indexOf("AB", indba+2)>0 ? "YES":"NO");
            else
                System.out.println(s.indexOf("BA", indab+2)>0 ? "YES":"NO");
        }

    }

}


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

public class tmp {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        int indab = s.indexOf("AB");
        int indba = s.indexOf("BA");

        if(indab == -1 || indba == -1)
            System.out.println("NO");
        else if (indab < indba){
            System.out.println(indba > indab+1 ? "YES" : s.indexOf("BA", indba+1)>0 ? "YES":"NO");
        }else{
            System.out.println(indab > indba+1 ? "YES" : s.indexOf("AB", indab+1)>0 ? "YES":"NO");
        }

    }

}


import java.util.Scanner;
import java.util.PriorityQueue;
import java.math.BigDecimal;

public class A306 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

		int abCount = 1;
		int baCount = 1;
		int aIndex = s.indexOf("AB");
		int bIndex = s.indexOf("BA");

		if (aIndex==-1 || bIndex==-1) {
			System.out.print("NO");
			return;
		}

		if (aIndex+1 != bIndex && bIndex+1!=aIndex) {
			System.out.print("YES");
			return;
		}

		if (s.indexOf("BA",aIndex+2) != -1) {
			System.out.print("YES");
			return;
		}
		if (s.indexOf("AB",bIndex+2) != -1) {
			System.out.print("YES");
			return;
		}

		System.out.print("NO");
		return;
    }
}


import java.util.Scanner;
import java.util.PriorityQueue;
import java.math.BigDecimal;

public class A306 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

		int abCount = 1;
		int baCount = 1;
		int aIndex = s.indexOf("AB");
		int bIndex = s.indexOf("BA");

		if (aIndex==-1 || bIndex==-1) {
			System.out.print("NO");
			return;
		}

		if (s.indexOf("AB",aIndex+3) != -1)
			abCount++;
		if (s.indexOf("BA",bIndex+3) != -1)
			baCount++;

		if (abCount > 1 || baCount > 1) {
			System.out.print("YES");
			return;
		}

		if (aIndex+1 == bIndex || bIndex+1==aIndex) {
			System.out.print("NO");
			return;
		}
		System.out.print("YES");
		return;
    }
}


import java.util.Scanner;
import java.util.PriorityQueue;
import java.math.BigDecimal;

public class A306 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

		int abCount = 1;
		int baCount = 1;
		int aIndex = s.indexOf("AB");
		int bIndex = s.indexOf("BA");

		if (aIndex==-1 || bIndex==-1) {
			System.out.print("NO");
			return;
		}

		if (aIndex+1 != bIndex && bIndex+1!=aIndex) {
			System.out.print("YES");
			return;
		}

		if (s.indexOf("BA",aIndex+2) != -1) {
			System.out.print("YES");
			return;
		}
		if (s.indexOf("AA",bIndex+2) != -1) {
			System.out.print("YES");
			return;
		}

		System.out.print("NO");
		return;
    }
}


import java.util.Scanner;
import java.util.PriorityQueue;
import java.math.BigDecimal;

public class A306 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

		int abCount = 1;
		int baCount = 1;
		int aIndex = s.indexOf("AB");
		int bIndex = s.indexOf("BA");

		if (aIndex==-1 || bIndex==-1) {
			System.out.print("NO");
			return;
		}

		if (s.indexOf("AB",aIndex+1) != -1)
			abCount++;
		if (s.indexOf("BA",bIndex+1) != -1)
			baCount++;

		if (abCount > 1 || baCount > 1) {
			System.out.print("YES");
			return;
		}

		if (aIndex+1 == bIndex || bIndex+1==aIndex) {
			System.out.print("NO");
			return;
		}
		System.out.print("YES");
		return;
    }
}


import java.util.Scanner;
import java.util.PriorityQueue;
import java.math.BigDecimal;

public class A306 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

		int abCount = 1;
		int baCount = 1;
		int aIndex = s.indexOf("AB");
		int bIndex = s.indexOf("BA");

		if (aIndex==-1 || bIndex==-1) {
			System.out.print("NO");
			return;
		}

		if (aIndex+1 != bIndex && bIndex+1!=aIndex) {
			System.out.print("YESa");
			return;
		}

		if (s.indexOf("BA",aIndex+2) != -1) {
			System.out.print("YES");
			return;
		}
		if (s.indexOf("AB",bIndex+2) != -1) {
			System.out.print("YES");
			return;
		}

		System.out.print("NO");
		return;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int c=0;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int count = 0;
        int minab=Integer.MAX_VALUE, minba=Integer.MAX_VALUE;
        boolean flag = false;
        try {
            while (c != -1) {
                if (c == 'A') {
                    c = reader.read();
                    count++;
                    if (c == 'B') {
                        abs = count;
                        if (!ab) {
                            minab = count;
                            ab = true;
                        }
                    }
                }
                else if (c == 'B') {
                    c = reader.read();
                    if (c == 'A') {
                        bas = count;
                        if (!ba) {
                            minba = count;
                            ba = true;
                        }
                    }
                }
                else {
                    c = reader.read();
                    count++;
                }

                if (abs - minba > 1 || bas - minab > 1) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int c;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int count = 0;
        int getab = 0, getba = 0;
        boolean flag = false;
        try {
            while ((c = reader.read()) != -1) {
                count++;
                if (c == 'A') {
                    c = reader.read();
                    count++;
                    if (c == 'B') {
                        abs = count;
                        getab++;
                        ab = true;
                    }
                }

                if ( c == 'B') {
                    c = reader.read();
                    count++;
                    if (c == 'A') {
                        bas = count;
                        getba++;
                        ba = true;
                    }
                }

                if (Math.abs(abs - bas) > 1 || (ab && ba && (getab > 1 || getba > 1))) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        Reader reader = new Reader(new InputStreamReader(System.in));
        int c=0;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int minab=Integer.MAX_VALUE, minba=Integer.MAX_VALUE;
        boolean flag = false;
        try {
            while (c != -1) {
                if (c == 'A') {
                    c = reader.read();
                    if (c == 'B') {
                        abs = reader.count;
                        if (!ab) {
                            minab = reader.count;
                            ab = true;
                        }
                    }
                }
                else if (c == 'B') {
                    c = reader.read();
                    if (c == 'A') {
                        bas = reader.count;
                        if (!ba) {
                            minba = reader.count;
                            ba = true;
                        }
                    }
                }
                else {
                    c = reader.read();
                }

                if (abs - minba > 1 || bas - minab > 1) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();
//        System.out.println(minab+" "+minba+" " + abs +" " + bas);
        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }

    private class Reader extends BufferedReader {
        public int count = 0;
        public Reader(java.io.Reader in) {
            super(in);
        }

        @Override
        public int read() throws IOException {
            count++;
            return super.read();
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int c=0;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int count = 0;
        int minab=Integer.MAX_VALUE, minba=Integer.MAX_VALUE;
        boolean flag = false;
        try {
            while (c != -1) {
                if (c == 'A') {
                    c = reader.read();
                    count++;
                    if (c == 'B') {
                        abs = count;
                        if (!ab) {
                            minab = count;
                            ab = true;
                        }
                    }
                }
                else if (c == 'B') {
                    c = reader.read();
                    if (c == 'A') {
                        bas = count;
                        getba++;
                        if (!ba) {
                            minba = count;
                            ba = true;
                        }
                    }
                }
                else {
                    c = reader.read();
                    count++;
                }

                if (abs - minba > 1 || bas - minab > 1) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int c=0;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int count = 0;
        int getab = 0, getba = 0;
        boolean flag = false;
        try {
            while (c != -1) {
                if (c == 'A') {
                    c = reader.read();
                    count++;
                    if (c == 'B') {
                        abs = count;
                        getab++;
                        ab = true;
                    }
                }
                else if (c == 'B') {
                    c = reader.read();
                    count++;
                    if (c == 'A') {
                        bas = count;
                        getba++;
                        ba = true;
                    }
                }
                else {
                    c = reader.read();
                    count++;
                }

                if (ab && ba && (Math.abs(abs - bas) > 1 || ((getab > 1 || getba > 1)))) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int c;
        boolean ab= false, ba=false;
        try{
            while ((c = reader.read())!=-1) {
                if (!ab && c == 'A') {
                    c = reader.read();
                    if (c == 'B') {
                        ab = true;
                        c = reader.read();
                    }
                 }

                if (!ba && c == 'B') {
                    c = reader.read();
                    if (c == 'A') {
                        ba = true;
                    }
                }

                if(ab && ba) break;
            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if(ab && ba) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        Reader reader = new Reader(new InputStreamReader(System.in));
        int c=0;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int minab=Integer.MAX_VALUE, minba=Integer.MAX_VALUE;
        boolean flag = false;
        try {
            while (c != -1) {
                if (c == 'A') {
                    c = reader.read();
                    if (c == 'B') {
                        abs = reader.count;
                        if (!ab) {
                            minab = reader.count;
                            ab = true;
                        }
                        c = reader.read();
                    }
                }
                else if (c == 'B') {
                    c = reader.read();
                    if (c == 'A') {
                        bas = reader.count;
                        if (!ba) {
                            minba = reader.count;
                            ba = true;
                        }
                        c = reader.read();
                    }
                }
                else {
                    c = reader.read();
                }

                if (abs - minba > 1 || bas - minab > 1) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }

    private class Reader extends BufferedReader {
        public int count = 0;
        public Reader(java.io.Reader in) {
            super(in);
        }

        @Override
        public int read() throws IOException {
            count++;
            return super.read();
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by wencan on 2015/6/5.
 */
public class TwoSubstrings {
    public static void main(String[] args) throws IOException {
        TwoSubstrings substrings = new TwoSubstrings();
        substrings.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int c;
        boolean ab = false, ba = false;
        int abs = 0, bas = 0;
        int count = 0;
        int getab = 0, getba = 0;
        boolean flag = false;
        try {
            while ((c = reader.read()) != -1) {
                count++;
                if (c == 'A') {
                    c = reader.read();
                    count++;
                    if (c == 'B') {
                        abs = count;
                        getab++;
                        ab = true;
                    }
                }

                if ( c == 'B') {
                    c = reader.read();
                    count++;
                    if (c == 'A') {
                        bas = count;
                        getba++;
                        ba = true;
                    }
                }

                if (ab && ba && (Math.abs(abs - bas) > 1 || ((getab > 1 || getba > 1)))) {
                    flag = true;
                    break;
                }

            }
        } catch (Exception ex) {
            //
        }

        reader.close();

        if (flag) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA",c="BAAB",d="ABBA",e="ABA",f="BAB";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
	   else if(s.contains(e)){
	       String s1=s.replaceFirst(e,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(f)){
	       String s1=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(a)){
		   String s1=s.replaceFirst(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replaceFirst(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(c)||s.contains(d))
	        System.out.println("YES");

	   else
	      System.out.println("NO");
   }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
	   else if(s.contains(a)){
		   String s1=s.replaceFirst(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replaceFirst(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
   }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA",c="BAAB",d="ABBA",e="ABA",f="BAB";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
	   else if(s.contains(e)||s.contains(f)){
	       String s1=s.replaceFirst(e,"");
		    String s2=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b)||s2.contains(a)||s2.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   /*else if(s.contains(f)){
	       String s1=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }*/
	   else if(s.contains(a)){
		   String s1=s.replaceFirst(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replaceFirst(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(c)||s.contains(d))
	        System.out.println("YES");

	   else
	      System.out.println("NO");
   }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA",c="BAAB",d="ABBA",e="ABA",f="BAB";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
       else if(s.startsWith(e)){
		   String s1=s.replaceFirst(e,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else

			   System.out.println("NO");
	   }
	   else if(s.startsWith(f)){
		   String s1=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else

			   System.out.println("NO");
	   }
	   /*else if(s.contains(f)){
	       String s1=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }*/
	   else if(s.contains(a)){
		   String s1=s.replaceFirst(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replaceFirst(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(c)||s.contains(d))
	        System.out.println("YES");

	   else
	      System.out.println("NO");
   }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
	   else if(s.contains(a)){
		   String s1=s.replaceFirst(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replaceFirst(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else
	      System.out.println("NO");
   }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
	   else if(s.contains(a)){
		   String s1=s.replace(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replace(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else
	      System.out.println("NO");
   }
}


import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class Checkstring {
   public static void main(String []arg){
	   String s;
	   String a="AB",b="BA",c="BAAB",d="ABBA",e="ABA",f="BAB";
	   Scanner in = new Scanner(System.in);
	   s = in.nextLine();
	   if(s.length()<=3)
		   System.out.println("NO");
       else if(s.startsWith(e)){
		   String s1=s.replaceFirst(e,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else

			   System.out.println("NO");
	   }
	   else if(s.startsWith(f)){
		   String s1=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else

			   System.out.println("NO");
	   }
	   else if(s.contains(e)){
	       String s1=s.replaceFirst(e,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(f)){
	       String s1=s.replaceFirst(f,"");
		   if(s1.contains(a)||s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(a)){
		   String s1=s.replaceFirst(a,"");
		   if(s1.contains(b))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(b)){
		   String s1=s.replaceFirst(b,"");
		   if(s1.contains(a))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
	   }
	   else if(s.contains(c)||s.contains(d))
	        System.out.println("YES");

	   else
	      System.out.println("NO");
   }
}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
	public static void main(String args[]){
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream,true);
		Task solver = new Task();

		solver.solve(in, out);
		out.close();

	}
}

class Task{
	Scanner in;
	PrintWriter out;

	//int a[]=new int[1001];
	public void solve(Scanner in,PrintWriter out){
		this.in=in;
		this.out=out;
		inputformat();
	}

	public void inputformat(){

		while(in.hasNext())
		//{
			//int t=in.nextInt();
			//while(t-->0)
				solve();
		//}

	}

	private void solve(){
	 String s=in.next();
	 char a[]=s.toCharArray();
	 int x=0,y=0;
	 for(int i=0;i<a.length-1;i++){
		 if(a[i]=='A' && a[i+1]=='B'){
			 x=i;
			 break;
		 }
	 }
	 for(int i=a.length-1;i>0;i--){
		 if(a[i]=='B' && a[i-1]=='A'){
			 y=i;
			 break;
		 }
	 }
	 if(x<y-1)out.println("YES");

	 else
	 out.println("NO");

		out.flush();
	}

}

// Input class
class Scanner{
	BufferedReader br;
	StringTokenizer st;

	public Scanner(InputStream in){
		br=new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String s){
		st=new StringTokenizer(s);
	}

	public String nextLine(){
		try{
			return br.readLine();
		}catch(IOException e){
			return null;
		}
	}

	public boolean hasNext(){
		while(!st.hasMoreTokens()){
			String s = nextLine();
			if(s == null) return false;
			eat(s);
		}
		return true;
	}

	public String next(){
		hasNext();
		return st.nextToken();
	}

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

	public long nextLong(){
		return Long.parseLong(next());
	}

	public BigInteger nextBigInteger(){
		return new BigInteger(next());
	}

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream,true);
        Task solver = new Task();

        solver.solve(in, out);
        out.close();

    }
}

class Task{
    Scanner in;
    PrintWriter out;

    //int a[]=new int[1001];
    public void solve(Scanner in,PrintWriter out){
        this.in=in;
        this.out=out;
        inputformat();
    }

    public void inputformat(){

        while(in.hasNext())
        //{
            //int t=in.nextInt();
            //while(t-->0)
                solve();
        //}

    }

    private void solve(){
     String s=in.next();
     Boolean ok=false;
     char a[]=s.toCharArray();
     int x=100000000,y=0;
     for(int i=0;i<a.length-1;i++){
         if(a[i]=='A' && a[i+1]=='B'){
             x=i;

             break;
         }
     }
     ok=false;
     for(int i=a.length-1;i>0;i--){
         if(a[i]=='A' && a[i-1]=='B'){
             y=i;
             ok=true;
             break;
         }
     }
     //out.println(x+" "+y);
     if(x<y-2 && ok){
         out.println("YES");
         return;
     }
     x=10000000;
     ok=false;
     for(int i=0;i<a.length-1;i++){
         if(a[i]=='B' && a[i+1]=='A'){
             x=i;
             break;
         }
     }
     for(int i=a.length-1;i>0;i--){
         if(a[i]=='B' && a[i-1]=='A'){
             y=i;
             ok=true;
             break;
         }
     }
     //out.println(x+" "+y);
     if(x<y-2 && ok)out.println("YES");
     else

     out.println("NO");

        out.flush();
    }

}

// Input class
class Scanner{
    BufferedReader br;
    StringTokenizer st;

    public Scanner(InputStream in){
        br=new BufferedReader(new InputStreamReader(in));
        eat("");
    }

    private void eat(String s){
        st=new StringTokenizer(s);
    }

    public String nextLine(){
        try{
            return br.readLine();
        }catch(IOException e){
            return null;
        }
    }

    public boolean hasNext(){
        while(!st.hasMoreTokens()){
            String s = nextLine();
            if(s == null) return false;
            eat(s);
        }
        return true;
    }

    public String next(){
        hasNext();
        return st.nextToken();
    }

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

    public long nextLong(){
        return Long.parseLong(next());
    }

    public BigInteger nextBigInteger(){
        return new BigInteger(next());
    }

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
	public static void main(String args[]){
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream,true);
		Task solver = new Task();

		solver.solve(in, out);
		out.close();

	}
}

class Task{
	Scanner in;
	PrintWriter out;

	//int a[]=new int[1001];
	public void solve(Scanner in,PrintWriter out){
		this.in=in;
		this.out=out;
		inputformat();
	}

	public void inputformat(){

		while(in.hasNext())
		//{
			//int t=in.nextInt();
			//while(t-->0)
				solve();
		//}

	}

	private void solve(){
	 String s=in.next();
	 char a[]=s.toCharArray();
	 int x=0,y=0;
	 for(int i=0;i<a.length-1;i++){
		 if(a[i]=='A' && a[i+1]=='B'){
			 x=i;
			 break;
		 }
	 }
	 for(int i=a.length-1;i>0;i--){
		 if(a[i]=='A' && a[i-1]=='B'){
			 y=i;
			 break;
		 }
	 }
	 //out.println(x+" "+y);
	 if(x<y-2){
		 out.println("YES");
		 return;
	 }
	 x=y=0;
	 for(int i=0;i<a.length-1;i++){
		 if(a[i]=='B' && a[i+1]=='A'){
			 x=i;
			 break;
		 }
	 }
	 for(int i=a.length-1;i>0;i--){
		 if(a[i]=='B' && a[i-1]=='A'){
			 y=i;
			 break;
		 }
	 }
	 //out.println(x+" "+y);
	 if(x<y-2)out.println("YES");
	 else

	 out.println("NO");

		out.flush();
	}

}

// Input class
class Scanner{
	BufferedReader br;
	StringTokenizer st;

	public Scanner(InputStream in){
		br=new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String s){
		st=new StringTokenizer(s);
	}

	public String nextLine(){
		try{
			return br.readLine();
		}catch(IOException e){
			return null;
		}
	}

	public boolean hasNext(){
		while(!st.hasMoreTokens()){
			String s = nextLine();
			if(s == null) return false;
			eat(s);
		}
		return true;
	}

	public String next(){
		hasNext();
		return st.nextToken();
	}

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

	public long nextLong(){
		return Long.parseLong(next());
	}

	public BigInteger nextBigInteger(){
		return new BigInteger(next());
	}

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream,true);
        Task solver = new Task();

        solver.solve(in, out);
        out.close();

    }
}

class Task{
    Scanner in;
    PrintWriter out;

    //int a[]=new int[1001];
    public void solve(Scanner in,PrintWriter out){
        this.in=in;
        this.out=out;
        inputformat();
    }

    public void inputformat(){

        while(in.hasNext())
        //{
            //int t=in.nextInt();
            //while(t-->0)
                solve();
        //}

    }

    private void solve(){
     String s=in.next();
     char a[]=s.toCharArray();
     int x=0,y=0;
     for(int i=0;i<a.length-1;i++){
         if(a[i]=='A' && a[i+1]=='B'){
             x=i;
             break;
         }
     }
     for(int i=a.length-1;i>0;i--){
         if(a[i]=='B' && a[i-1]=='A'){
             y=i;
             break;
         }
     }
     if(x<y-1){
         out.println("YES");
         return;
     }
     for(int i=0;i<a.length-1;i++){
         if(a[i]=='B' && a[i+1]=='A'){
             x=i;
             break;
         }
     }
     for(int i=a.length-1;i>0;i--){
         if(a[i]=='A' && a[i-1]=='B'){
             y=i;
             break;
         }
     }
     if(x>y-1)out.println("YES");
     else

     out.println("NO");

        out.flush();
    }

}

// Input class
class Scanner{
    BufferedReader br;
    StringTokenizer st;

    public Scanner(InputStream in){
        br=new BufferedReader(new InputStreamReader(in));
        eat("");
    }

    private void eat(String s){
        st=new StringTokenizer(s);
    }

    public String nextLine(){
        try{
            return br.readLine();
        }catch(IOException e){
            return null;
        }
    }

    public boolean hasNext(){
        while(!st.hasMoreTokens()){
            String s = nextLine();
            if(s == null) return false;
            eat(s);
        }
        return true;
    }

    public String next(){
        hasNext();
        return st.nextToken();
    }

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

    public long nextLong(){
        return Long.parseLong(next());
    }

    public BigInteger nextBigInteger(){
        return new BigInteger(next());
    }

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
	public static void main(String args[]){
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream,true);
		Task solver = new Task();

		solver.solve(in, out);
		out.close();

	}
}

class Task{
	Scanner in;
	PrintWriter out;

	//int a[]=new int[1001];
	public void solve(Scanner in,PrintWriter out){
		this.in=in;
		this.out=out;
		inputformat();
	}

	public void inputformat(){

		while(in.hasNext())
		//{
			//int t=in.nextInt();
			//while(t-->0)
				solve();
		//}

	}

	private void solve(){
	 String s=in.next();
	 char a[]=s.toCharArray();
	 int x=0,y=0;
	 for(int i=0;i<a.length-1;i++){
		 if(a[i]=='A' && a[i+1]=='B'){
			 x=i;
			 break;
		 }
	 }
	 for(int i=a.length-1;i>0;i--){
		 if(a[i]=='A' && a[i-1]=='B'){
			 y=i;
			 break;
		 }
	 }

	 if(x<y-1){
		 out.println("YES");
		 return;
	 }
	 x=y=0;
	 for(int i=0;i<a.length-1;i++){
		 if(a[i]=='B' && a[i+1]=='A'){
			 x=i;
			 break;
		 }
	 }
	 for(int i=a.length-1;i>0;i--){
		 if(a[i]=='B' && a[i-1]=='A'){
			 y=i;
			 break;
		 }
	 }
	 //out.println(x+" "+y);
	 if(x<y-1)out.println("YES");
	 else

	 out.println("NO");

		out.flush();
	}

}

// Input class
class Scanner{
	BufferedReader br;
	StringTokenizer st;

	public Scanner(InputStream in){
		br=new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String s){
		st=new StringTokenizer(s);
	}

	public String nextLine(){
		try{
			return br.readLine();
		}catch(IOException e){
			return null;
		}
	}

	public boolean hasNext(){
		while(!st.hasMoreTokens()){
			String s = nextLine();
			if(s == null) return false;
			eat(s);
		}
		return true;
	}

	public String next(){
		hasNext();
		return st.nextToken();
	}

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

	public long nextLong(){
		return Long.parseLong(next());
	}

	public BigInteger nextBigInteger(){
		return new BigInteger(next());
	}

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream,true);
        Task solver = new Task();

        solver.solve(in, out);
        out.close();

    }
}

class Task{
    Scanner in;
    PrintWriter out;

    //int a[]=new int[1001];
    public void solve(Scanner in,PrintWriter out){
        this.in=in;
        this.out=out;
        inputformat();
    }

    public void inputformat(){

        while(in.hasNext())
        //{
            //int t=in.nextInt();
            //while(t-->0)
                solve();
        //}

    }

    private void solve(){
     String s=in.next();
     char a[]=s.toCharArray();
     int x=0,y=0;
     for(int i=0;i<a.length-1;i++){
         if(a[i]=='A' && a[i+1]=='B'){
             x=i;
             break;
         }
     }
     for(int i=a.length-1;i>0;i--){
         if(a[i]=='B' && a[i-1]=='A'){
             y=i;
             break;
         }
     }
     if(x<y-1){
         out.println("YES");
         return;
     }
     for(int i=0;i<a.length-1;i++){
         if(a[i]=='B' && a[i+1]=='A'){
             x=i;
             break;
         }
     }
     for(int i=a.length-1;i>0;i--){
         if(a[i]=='A' && a[i-1]=='B'){
             y=i;
             break;
         }
     }
     if(x<y-1)out.println("YES");
     else

     out.println("NO");

        out.flush();
    }

}

// Input class
class Scanner{
    BufferedReader br;
    StringTokenizer st;

    public Scanner(InputStream in){
        br=new BufferedReader(new InputStreamReader(in));
        eat("");
    }

    private void eat(String s){
        st=new StringTokenizer(s);
    }

    public String nextLine(){
        try{
            return br.readLine();
        }catch(IOException e){
            return null;
        }
    }

    public boolean hasNext(){
        while(!st.hasMoreTokens()){
            String s = nextLine();
            if(s == null) return false;
            eat(s);
        }
        return true;
    }

    public String next(){
        hasNext();
        return st.nextToken();
    }

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

    public long nextLong(){
        return Long.parseLong(next());
    }

    public BigInteger nextBigInteger(){
        return new BigInteger(next());
    }

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Main{
	public static void main(String args[]){
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream,true);
		Task solver = new Task();

		solver.solve(in, out);
		out.close();

	}
}

class Task{
	Scanner in;
	PrintWriter out;

	//int a[]=new int[1001];
	public void solve(Scanner in,PrintWriter out){
		this.in=in;
		this.out=out;
		inputformat();
	}

	public void inputformat(){

		while(in.hasNext())
		//{
			//int t=in.nextInt();
			//while(t-->0)
				solve();
		//}

	}

	private void solve(){
	 String s=in.next();
	 char a[]=s.toCharArray();
	 int x=0,y=0;
	 for(int i=0;i<a.length-1;i++){
		 if(a[i]=='A' && a[i+1]=='B'){
			 x=i;
			 break;
		 }
	 }
	 for(int i=a.length-1;i>0;i--){
		 if(a[i]=='B' && a[i-1]=='A'){
			 y=i;
			 break;
		 }
	 }
	 if(x<y)out.println("YES");

	 else
	 out.println("NO");

		out.flush();
	}

}

// Input class
class Scanner{
	BufferedReader br;
	StringTokenizer st;

	public Scanner(InputStream in){
		br=new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String s){
		st=new StringTokenizer(s);
	}

	public String nextLine(){
		try{
			return br.readLine();
		}catch(IOException e){
			return null;
		}
	}

	public boolean hasNext(){
		while(!st.hasMoreTokens()){
			String s = nextLine();
			if(s == null) return false;
			eat(s);
		}
		return true;
	}

	public String next(){
		hasNext();
		return st.nextToken();
	}

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

	public long nextLong(){
		return Long.parseLong(next());
	}

	public BigInteger nextBigInteger(){
		return new BigInteger(next());
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")&& !BA){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")&&!AB){
				   BA=true;
				   i++;
			   }
		   }

		   if(AB==true &&BA==true)
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")&& !AB){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")&&!BA){
				   BA=true;
				   i++;
			   }
		   }
		   if(AB==true &&BA==true)
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")){
				   BA=true;
				   i++;
			   }
		   }
		   if(AB==true &&BA==true)
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")&& !AB){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")&&!BA){
				   BA=true;
				   i++;
			   }
		   }
		    for(int i=0;i<s.length()-1;i++)
			   {
				   String temp= s.substring(i,i+2);
				   if(temp.equals("BA")&&!BA){
					   BA=true;
					   i++;
				   }
				   if(temp.equals("AB")&& !AB){
					   AB=true;
					   i++;
				   }

			   }
		   if(AB==true &&BA==true)
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    boolean BA2=false;
		    boolean AB2=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")&& !AB){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")&&!BA){
				   BA=true;
				   i++;
			   }

		   }
		    for(int i=0;i<s.length()-1;i++)
			   {
				   String temp= s.substring(i,i+2);
				   if(temp.equals("BA")&&!BA2){
					   BA2=true;
					   i++;
				   }
				   if(temp.equals("AB")&& !AB2){
					   AB2=true;
					   i++;
				   }

			   }
		   if((AB==true &&BA==true)||(AB2&&BA2))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    boolean BA2=false;
		    boolean AB2=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")&& !AB){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")&&!BA){
				   BA=true;
				   i++;
			   }

		   }
		    for(int i=0;i<s.length()-1;i++)
			   {
				   String temp= s.substring(i,i+2);
				   if(temp.equals("BA")&&!BA2){
					   BA2=true;
					   i++;
				   }
				   if(temp.equals("AB")&& !AB2&&BA2){
					   AB2=true;
					   i++;
				   }

			   }
		   if((AB==true &&BA==true)||(AB2&&BA2))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) throws NumberFormatException, IOException {
		    BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		    String s= bf.readLine();
		    boolean AB=false;
		    boolean BA=false;
		    boolean BA2=false;
		    boolean AB2=false;
		    for(int i=0;i<s.length()-1;i++)
		   {
			   String temp= s.substring(i,i+2);

			   if(temp.equals("AB")&& !AB){
				   AB=true;
				   i++;
			   }
			   if(temp.equals("BA")&&!BA &&AB){
				   BA=true;
				   i++;
			   }

		   }
		    for(int i=0;i<s.length()-1;i++)
			   {
				   String temp= s.substring(i,i+2);
				   if(temp.equals("BA")&&!BA2){
					   BA2=true;
					   i++;
				   }
				   if(temp.equals("AB")&& !AB2&&BA2){
					   AB2=true;
					   i++;
				   }

			   }
		   if((AB==true &&BA==true)||(AB2&&BA2))
			   System.out.println("YES");
		   else
			   System.out.println("NO");
		  }
}


import java.util.Scanner;

/**
 * Created by popeye on 6/4/15.
 */
public class Abba {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        for (int i = 0; i < s.length(); i++) {
            String left = s.substring(0, i);
            String right = s.substring(i, s.length());
            if((left.contains("AB") && right.contains("BA")) || (left.contains("BA"))&& right.contains("AB")) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


package competitions.codeforces;

import java.util.Scanner;

/**
 * Created by popeye on 6/4/15.
 */
public class Abba {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        for (int i = 0; i < s.length(); i++) {
            String left = s.substring(0, i);
            String right = s.substring(i, s.length());
            if((left.contains("AB") && right.contains("BA")) || (left.contains("BA"))&& right.contains("AB")) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


import java.util.Scanner;

/**
 * Created by popeye on 6/4/15.
 */
public class Abba {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        sol3(s);
    }

    public static void sol3(String s) {
        int left = 0;
        int right = s.length()-1;
        boolean found = false;

        while(left < right) {
            while(left < s.length()-1 && !(s.charAt(left) == 'A' && s.charAt(left+1) == 'B') ) {
                left++;
            }
            while(right > 0 && !(s.charAt(right) == 'A' &&  s.charAt(right - 1) == 'B')) {
                right--;
            }
            if(left + 2 < right) {
                found = true;
                break;
            }
            left++;
            right--;
        }

        if(found) {
            System.out.println("YES");
            return;
        }

        left = 0;
        right = s.length()-1;
        while(left < right) {
            while(left < s.length()-1 && !(s.charAt(left) == 'B' && s.charAt(left+1) == 'A')) {
                left++;
            }
            while(right > 0 && !(s.charAt(right) == 'B' && s.charAt(right - 1) == 'A')) {
                right--;
            }
            if(left + 2 < right) {
                found = true;
                break;
            }
            left++;
            right--;
        }

        if(found) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}


import java.util.Scanner;

/**
 * Created by popeye on 6/4/15.
 */
public class Abba {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        sol2(s);
    }

    public static void sol2(String s) {
        if(s.matches(".*AB.*BA|.*BA.*AB.*"))
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.util.Scanner;

/**
 * Created by popeye on 6/4/15.
 */
public class Abba {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        sol3(s);
    }

    public static void sol3(String s) {
        int left = 0;
        int right = s.length()-1;
        boolean found = false;

        while(left < right) {
            while(left < s.length()-1 && !(s.charAt(left) == 'A' && s.charAt(left+1) == 'B') ) {
                left++;
            }
            while(right > 0 && !(s.charAt(right) == 'A' &&  s.charAt(right - 1) == 'B')) {
                right--;
            }
            if(left + 3 < right) {
                found = true;
                break;
            }
            left++;
            right--;
        }

        if(found) {
            System.out.println("YES");
            return;
        }

        left = 0;
        right = s.length()-1;
        while(left < right) {
            while(left < s.length()-1 && !(s.charAt(left) == 'B' && s.charAt(left+1) == 'A')) {
                left++;
            }
            while(right > 0 && !(s.charAt(right) == 'B' && s.charAt(right - 1) == 'A')) {
                right--;
            }
            if(left + 3 < right) {
                found = true;
                break;
            }
            left++;
            right--;
        }

        if(found) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}


package codeforces.srm306;

import java.util.Scanner;

/**
 * Created by mhoang on 6/4/2015.
 */
public class Substrings {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        while(s.length() > 1) {
            if (s.indexOf("AB") == -1) {
                System.out.println("NO");
                break;
            } else {
                int i = s.indexOf("AB");
                if (s.substring(0, i).indexOf("BA") == i + 1 || s.substring(0, i).indexOf("BA") == i-1) {
                    s = s.substring(i+2, s.length());
                } else {
                    System.out.println("YES");
                    break;
                }
            }
        }
        System.out.println("NO");
    }
}


package codeforces.srm306;

import java.util.Scanner;

/**
 * Created by mhoang on 6/4/2015.
 */
public class Substrings {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        if(s.indexOf("AB") == -1) {
            System.out.println("NO");
        } else {
            int i = s.indexOf("AB");
            if(s.substring(0,i).indexOf("BA") != -1 || s.substring(i+2,s.length()).indexOf("BA")!= -1) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
    }
}


import java.util.Scanner;

/**
 * Created by mhoang on 6/4/2015.
 */
public class Substrings {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        while(s.length() > 1) {
            if (s.indexOf("AB") == -1) {
                System.out.println("NO");
                break;
            } else {
                int i = s.indexOf("AB");
                if (s.substring(0, i).indexOf("BA") == i + 1 || s.substring(0, i).indexOf("BA") == i-1) {
                    s = s.substring(i+2, s.length());
                } else {
                    System.out.println("YES");
                    break;
                }
            }
        }
        System.out.println("NO");
    }
}


import java.io.*;
import java.util.*;

/**
 * Created by megido
 */
public class Solution {

    public static boolean check(String s) {
        int i = 0;
        int total = 0;
        while (i < s.length() - 1) {
            if (total == 3) break;
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'B' && total != 1) {
                total += 1;
                i += 2;
                continue;
            }
            if (s.charAt(i) == 'B' && s.charAt(i + 1) == 'A' && total != 2) {
                total += 2;
                i += 2;
                continue;
            }
            i++;
        }
        return total == 3;
    }

    public static void main(String args[]) {
        try {
            //Scanner in = new Scanner(new File("data.in"));
            Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            StringBuilder s1 = new StringBuilder(in.nextLine());
            String s2 = s1.reverse().toString();
            out.println(check(s1.toString()) || check(s2) ? "YES" : "NO");
            out.close();
        } catch(Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}


import java.io.*;
import java.util.*;

/**
 * Created by megido
 */
public class Solution {

    public static boolean check(String s) {
        int i = 0;
        int total = 0;
        while (i < s.length() - 1) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'B') {
                total += 1;
                i += 2;
                continue;
            }
            if (s.charAt(i) == 'B' && s.charAt(i + 1) == 'A') {
                total += 2;
                i += 2;
                continue;
            }
            i++;
        }
        return total == 3;
    }

    public static void main(String args[]) {
        try {
            Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            StringBuilder s1 = new StringBuilder(in.nextLine());
            String s2 = s1.reverse().toString();

            out.println(check(s1.toString()) || check(s2) ? "YES" : "NO");

            out.close();
        } catch(Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}


import java.io.*;
import java.util.*;

/**
 * Created by megido
 */
public class Solution {

    public static boolean check(String s) {
        int i = 0;
        int total = 0;
        while (i < s.length() - 1) {
            if (total == 3) break;
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'B') {
                total += 1;
                i += 2;
                continue;
            }
            if (s.charAt(i) == 'B' && s.charAt(i + 1) == 'A') {
                total += 2;
                i += 2;
                continue;
            }
            i++;
        }
        return total == 3;
    }

    public static void main(String args[]) {
        try {
            Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            StringBuilder s1 = new StringBuilder(in.nextLine());
            String s2 = s1.reverse().toString();

            out.println(check(s1.toString()) || check(s2) ? "YES" : "NO");

            out.close();
        } catch(Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Twos{

    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));

        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }

        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }      //Fastscanner class end

   static FastScanner in=new FastScanner();
   static PrintWriter ww=new PrintWriter(new OutputStreamWriter(System.out));
   public static void main(String args[])throws IOException
   {
   //Main ob=new Main();
   Twos ob=new Twos();
   ob.solve();
   ww.close();
   }
   public void solve()throws IOException
   {
     boolean X=false;
     boolean Y=false;
     boolean z=false;
     String st1=in.nextString();
     String st2=st1.replaceFirst("AB","X").replaceAll("BA","Y");
     String st3=st1.replaceFirst("BA","X").replaceAll("AB","Y");
     //System.out.println(st2);
     for(int i=0;i<st1.length()-1;i++)
     {
       if(st2.charAt(i)=='X')
            X=true;
       if(st2.charAt(i)=='Y')
          Y=true;
     }
     if(X&&Y)
     z=true;

     X=false;
     Y=false;
     for(int i=0;i<st1.length()-1;i++)
     {
       if(st3.charAt(i)=='X')
            X=true;
       if(st3.charAt(i)=='Y')
          Y=true;
     }
     if(X&&Y)z=true;
     if(z)
        System.out.println("YES");
     else
        System.out.println("NO");

  }
  }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Twos{

    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));

        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }

        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }      //Fastscanner class end

   static FastScanner in=new FastScanner();
   static PrintWriter ww=new PrintWriter(new OutputStreamWriter(System.out));
   public static void main(String args[])throws IOException
   {
   //Main ob=new Main();
   Twos ob=new Twos();
   ob.solve();
   ww.close();
   }
   public void solve()throws IOException
   {
     String y = in.nextString();
        String x = y.replaceFirst("AB", "x").replaceAll("BA", "y");
        String z = y.replaceFirst("BA", "x").replaceAll("AB", "y");

        boolean xx = false;
        boolean yy = false;
        boolean zz = false;

        for(int i=0;i<x.length();i++){
            if(x.charAt(i) == 'x') xx = true;
            if(x.charAt(i) == 'y') yy = true;
        }

        if(xx && yy) zz = true;
        xx = yy = false;

        for(int i=0;i<z.length();i++){
            if(z.charAt(i) == 'x') xx = true;
            if(z.charAt(i) == 'y') yy = true;
        }

        if(xx && yy) zz = true;

        if(zz)System. out.println("YES");
        else System.out.println("NO");

  }
  }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Twos{

    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));

        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }

        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }      //Fastscanner class end

   static FastScanner in=new FastScanner();
   static PrintWriter ww=new PrintWriter(new OutputStreamWriter(System.out));
   public static void main(String args[])throws IOException
   {
   //Main ob=new Main();
   Twos ob=new Twos();
   ob.solve();
   ww.close();
   }
   public void solve()throws IOException
   {
    boolean xx=false;
    boolean yy=false;
    boolean zz=false;
    String st=in.nextString();
    String st1=st.replaceFirst("AB","x").replaceAll("BA","y");
    String st2=st.replaceFirst("BA","x").replaceAll("AB","y");
    for(int i=0;i<st1.length();i++)
    {
     if(st1.charAt(i)=='x')xx=true;
     if(st1.charAt(i)=='y')yy=true;
    }
    if(xx && yy)
    zz=true;
    xx=yy=false;
    for(int i=0;i<st2.length();i++)
   {
     if(st2.charAt(i)=='x')xx=true;
     if(st2.charAt(i)=='y')yy=true;
   }
    if(xx && yy)zz=true;
   if(zz)
       System.out.println("YES");
   else
       System.out.println("NO");

  }
  }