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


-----Input-----

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


-----Output-----

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


-----Examples-----
Input
ABA

Output
NO

Input
BACFAB

Output
YES

Input
AXBYBXA

Output
NO



-----Note-----

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

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

In the third sample test there is no substring "AB" nor substring "BA".

Difficulty: MEDIUM
Tags: String algorithms

Implementation

Greedy algorithms

Complete search

Dynamic programming
Skill types: Dynamic programming

Complete search

Greedy algorithms

Starter code:

Solutions:
s = input()
a = s.find('AB')
b = s.rfind('BA')
c = s.find('BA')
d = s.rfind('AB')
if a == -1 or b == -1:
	print('NO')
elif abs(a - b) <= 1 and abs(c - d) <= 1:
	print('NO')
else:
	print('YES')


def substrings(s):
	if 'AB' not in s or 'BA' not in s:
		return 'NO'
	x = s.replace('AB', 'X', 1)
	if 'BA' in x:
		return 'YES'
	y = s.replace('BA', 'X', 1)
	if 'AB' in y:
		return 'YES'
	return 'NO'
s = input()
print(substrings(s))


s = input()

def d(s, a, b):
	if a in s:
		index = s.index(a)
		(s1, s2) = (s[:index], s[index + 2:])
		if b in s1 or b in s2:
			return True
		else:
			return False
	return False
if d(s, 'AB', 'BA') or d(s, 'BA', 'AB'):
	print('YES')
else:
	print('NO')


l = input()
i = 0
f1 = False
f2 = False
f3 = False
f4 = False
while i < len(l) - 1:
	if (l[i] == 'A' and l[i + 1] == 'B') and (not f1):
		f1 = True
		i += 2
	elif (l[i] == 'B' and l[i + 1] == 'A') and (not f2):
		f2 = True
		i += 2
	else:
		i += 1
i = len(l) - 1
if not (f1 and f2):
	while i > 1:
		if (l[i] == 'B' and l[i - 1] == 'A') and (not f3):
			f3 = True
			i -= 2
		elif (l[i] == 'A' and l[i - 1] == 'B') and (not f4):
			f4 = True
			i -= 2
		else:
			i -= 1
if f1 and f2 or (f3 and f4):
	print('YES')
else:
	print('NO')


s = input()
fi = s.find('AB')
se = s.find('BA')
ab = s.count('AB')
ba = s.count('BA')
if fi == -1 or se == -1:
	print('NO')
elif (s.count('ABAB') == 1 or s.count('BABA') == 1) and s.count('A') == 2 and (s.count('B') == 2):
	print('NO')
elif ab == 1 and ba == 1:
	if max(fi, se) - min(fi, se) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


from sys import stdin, stdout, stderr, setrecursionlimit
setrecursionlimit(100000)

def debug(*e):
	if not __debug__:
		print(*e, file=stderr)

def dd(*vals):
	import inspect, re
	frame = inspect.getframeinfo(inspect.stack()[1][0])
	vs = re.search('dd\\((.+)\\)', frame.code_context[0]).group(1).split(',')
	if vs:
		debug(','.join(('{0} = {1}'.format(vs[i], v) for (i, v) in enumerate(vals))))

def trace(f):

	def traced(*args, **kw):
		debug('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def read():
	return stdin.readline().rstrip()

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readia(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writea(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
import re

def findallBA(s):
	return [m.start(0) for m in re.finditer('BA', s)]

def f(s):
	i = 0
	bs = findallBA(s)
	while True:
		a = s.find('AB', i)
		if a == -1:
			return False
		for b in bs:
			if abs(a - b) > 1:
				return True
		i = a + 1
S = read()
r = f(S)
if r:
	write('YES')
else:
	r = f(S[::-1])
	write('YES' if r else 'NO')


s = input()
AB = []
BA = []
for i in range(len(s) - 1):
	if s[i] == 'B':
		if s[i + 1] == 'A':
			BA.append(i)
	if s[i] == 'A':
		if s[i + 1] == 'B':
			AB.append(i)
ANS = False
for i in range(len(AB)):
	for j in range(len(BA)):
		if abs(AB[i] - BA[j]) > 1:
			print('YES')
			exit(0)
print('NO')


s = input()
a = s.find('AB')
b = s.find('BA')
c = s.find('BA', a + 2)
d = s.find('AB', b + 2)
if a != -1 and c != -1 or (b != -1 and d != -1):
	print('YES')
else:
	print('NO')


s = input()
ab = s.count('AB')
ba = s.count('BA')
aba = s.count('ABA')
bab = s.count('BAB')
if ab + ba - aba - bab >= 2 and ab > 0 and (ba > 0):
	print('YES')
else:
	print('NO')


s = input()
ab_count = s.count('AB')
ba_count = s.count('BA')
if ab_count == 0 or ba_count == 0:
	print('NO')
elif ab_count == 1:
	s = s.replace('AB', '--')
	print('YES' if 'BA' in s else 'NO')
elif ba_count == 1:
	s = s.replace('BA', '--')
	print('YES' if 'AB' in s else 'NO')
else:
	print('YES')


def findAB(A):
	a = A.find('AB')
	if a == -1:
		return False
	else:
		b = A[a + 2:].find('BA')
		return b != -1

def findBA(B):
	a = B.find('BA')
	if a == -1:
		return False
	else:
		b = B[a + 2:].find('AB')
		return b != -1
s = input()
if findAB(s) or findBA(s):
	print('YES')
else:
	print('NO')


def main():
	s = input()
	if 'AB' not in s or 'BA' not in s:
		print('NO')
	elif s.index('AB') + 1 < s.rindex('BA'):
		print('YES')
	elif s.index('BA') + 1 < s.rindex('AB'):
		print('YES')
	else:
		print('NO')
main()


def main():
	s = input()
	f = False
	if 'AB' in s:
		i = s.index('AB')
		if 'BA' in s[i + 2:]:
			f = True
	if 'BA' in s:
		i = s.index('BA')
		if 'AB' in s[i + 2:]:
			f = True
	print('YES' if f else 'NO')
main()


s = input()

def helper(s, seq):
	for x in range(len(s) - 1):
		if s[x] == seq[0] and s[x + 1] == seq[1]:
			return True
	return False

def f(s):
	if len(s) < 4:
		return False
	else:
		count = 0
		for x in range(len(s) - 1):
			if s[x] == 'B' and s[x + 1] == 'A':
				count += 1
				if helper(s[x + 2:], 'AB'):
					return True
				elif count == 2:
					return False
			if s[x] == 'A' and s[x + 1] == 'B':
				count += 1
				if helper(s[x + 2:], 'BA'):
					return True
				elif count == 2:
					return False
		return False
if not f(s):
	print('NO')
else:
	print('YES')


s = list(input())
n = len(s)
index = n + 1
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		index = i + 2
		break
for i in range(index, n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		print('YES')
		exit()
index = n + 1
for i in range(n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		index = i + 2
		break
for i in range(index, n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		print('YES')
		exit()
print('NO')


s = input()
w = ''
if 'AB' in s:
	w = s.replace('AB', '.', 1)
else:
	print('NO')
	exit()
if 'BA' in w:
	print('YES')
else:
	if 'BA' in s:
		s = s.replace('BA', '.', 1)
	else:
		print('NO')
		exit()
	if 'AB' in s:
		print('YES')
	else:
		print('NO')


s = input()
abc = [0, 0, 0]
n = len(s)
i = 0
while i < n:
	ch = s[i]
	if ch == 'A':
		if i < n - 1 and s[i + 1] == 'B':
			if i < n - 2 and s[i + 2] == 'A':
				abc[2] += 1
				i += 3
			else:
				abc[0] = 1
				i += 2
		else:
			i += 1
	elif ch == 'B':
		if i < n - 1 and s[i + 1] == 'A':
			if i < n - 2 and s[i + 2] == 'B':
				abc[2] += 1
				i += 3
			else:
				abc[1] = 1
				i += 2
		else:
			i += 1
	else:
		i += 1
if abc[0] == 1 and abc[1] == 1:
	print('YES')
elif abc[2] != 0 and max(abc[0], abc[1]) != 0:
	print('YES')
elif abc[0] == 0 and abc[1] == 0 and (abc[2] >= 2):
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
s = stdin.readline().rstrip()

def find(s):

	def scan(a, b):
		(ix, i) = (-1, 0)
		while i < len(s) - 1:
			cand = s[i:i + 2]
			if cand == a:
				if ix == -1:
					ix = i
			elif cand == b:
				if ix != -1 and i - ix > 1:
					return True
			i += 1
		return False
	return scan('AB', 'BA') or scan('BA', 'AB')
if find(s):
	stdout.write('YES\n')
else:
	stdout.write('NO\n')


data = input()
abs = []
bas = []
for i in range(len(data) - 1):
	if data[i:i + 2] == 'AB':
		abs.append(i)
	elif data[i:i + 2] == 'BA':
		bas.append(i)

def is_valid(l1, l2):
	for i in l1:
		for j in l2:
			if j > i + 1:
				return True
	return False
print('YES' if is_valid(abs, bas) or is_valid(bas, abs) else 'NO')


ans = {True: 'YES', False: 'NO'}
s = input()
flag = False
p = s.find('AB')
if 'AB' in s and 'BA' in s:
	while p != -1:
		s = s[:p] + 'ab' + s[p + 2:]
		buf = s[:p].upper() + 'ab' + s[p + 2:]
		if 'BA' in buf:
			flag = True
			break
		p = s.find('AB')
print(ans[flag])


da_str = input()
ab = ba = concurrence = False
i = 0
while i < len(da_str) - 1:
	a = da_str[i]
	b = da_str[i + 1]
	if a == 'A' and b == 'B':
		if i + 2 < len(da_str) and da_str[i + 2] == 'A':
			if concurrence == True:
				ab = True
			concurrence = True
			i += 3
		else:
			ab = True
			i += 2
	elif a == 'B' and b == 'A':
		if i + 2 < len(da_str) and da_str[i + 2] == 'B':
			if concurrence == True:
				ab = True
			concurrence = True
			i += 3
		else:
			ba = True
			i += 2
	else:
		i += 1
if ab == True and ba == True or (concurrence == True and (ab == True or ba == True)):
	print('YES')
else:
	print('NO')


from math import *
s = input()
if 'AB' not in s or 'BA' not in s:
	print('NO')
elif abs(s.index('AB') - s.rfind('BA')) > 1 or abs(s.index('BA') - s.rfind('AB')) > 1:
	print('YES')
else:
	print('NO')


s = input()
f = 0
n = len(s)
ind = n
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ind = i + 2
		break
for i in range(ind, n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		f = 1
		break
ind = n
for i in range(n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		ind = i + 2
		break
for i in range(ind, n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		f = 1
		break
if f:
	print('YES')
else:
	print('NO')


from sys import stdin

def solve(s):
	n = len(s)
	gotba = False
	i = 1
	while i < n:
		if gotba and s[i - 1] == 'A' and (s[i] == 'B'):
			return 'YES'
		if not gotba and s[i - 1] == 'B' and (s[i] == 'A'):
			i += 1
			gotba = True
		i += 1
	gotab = False
	i = 1
	while i < n:
		if gotab and s[i - 1] == 'B' and (s[i] == 'A'):
			return 'YES'
		if not gotab and s[i - 1] == 'A' and (s[i] == 'B'):
			i += 1
			gotab = True
		i += 1
	return 'NO'
s = stdin.readline()
print(solve(s))


check = 0
s = input()
t = s
if 'AB' in s:
	s = s.replace('AB', '*', 1)
	if 'BA' in s:
		check += 1
if 'BA' in t:
	t = t.replace('BA', '*', 1)
	if 'AB' in t:
		check += 1
print('YES' if check > 0 else 'NO')


string = input()
found = 0
ab = string.find('AB')
if ab != -1:
	if string[ab + 2:].find('BA') != -1:
		found = 1
ba = string.find('BA')
if ba != -1:
	if string[ba + 2:].find('AB') != -1:
		found = 1
if found == 1:
	print('YES')
else:
	print('NO')


def main():
	s = input()
	if 'AB' in s and 'BA' in s:
		if s.rindex('BA') - s.index('AB') > 1 or s.rindex('AB') - s.index('BA') > 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
main()


s = input()
if 'BA' in s and 'AB' in s:
	x = s.index('BA')
	y = s.index('AB')
	if 'AB' in s[x + 2:] or 'BA' in s[y + 2:]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


from collections import Counter
import string
import math
import sys
sys.setrecursionlimit(10 ** 6)
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
mod = 10 ** 9 + 7

def ncr(n, r):
	if n < r:
		return 0
	if n == r:
		return 1
	numer = fact[n]
	denm = fact[n - r] * fact[r]
	return numer * pow(denm, mod - 2, mod)
fact = [1] * 1001
c = 1
mod = 10 ** 9 + 7
for i in range(1, 1001):
	fact[i] = fact[i - 1] * i % mod

def comp(x):
	return x[1]

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return -1
s = input()
if 0:
	pass
elif 0:
	pass
elif s.count('BA') == 0 or s.count('AB') == 0:
	print('NO')
elif s.count('AB') == 2 and s.count('BA') == 1:
	if s[s.find('AB') + 2:s.find('AB') + 4] == 'AB':
		print('NO')
	else:
		print('YES')
elif s.count('BA') == 2 and s.count('AB') == 1:
	if s[s.find('BA') + 2:s.find('BA') + 4] == 'BA':
		print('NO')
	else:
		print('YES')
elif s.count('AB') == 1 and s.count('BA') == 1 and (s.find('AB') < s.find('BA')):
	if s.find('AB') + 1 == s.find('BA'):
		print('NO')
	else:
		print('YES')
elif s.count('BA') == 1 and s.count('AB') == 1:
	if s.find('BA') + 1 == s.find('AB'):
		print('NO')
	else:
		print('YES')
else:
	print('YES')


def next(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans

def isFound(s):
	abIndexes = []
	baIndexes = []
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			abIndexes.append(i)
		elif s[i] == 'B' and s[i + 1] == 'A':
			baIndexes.append(i)
	for index in abIndexes:
		if next(baIndexes, index + 1) != -1:
			return True
	for index in baIndexes:
		if next(abIndexes, index + 1) != -1:
			return True
	return False
s = input()
memo = dict()
if isFound(s):
	print('Yes')
else:
	print('No')


s = input()
a = s.find('AB')
b = s.rfind('AB')
c = s.find('BA')
d = s.rfind('BA')
print('NYOE S'[min(a, b, c, d) > -1 and (abs(a - d) > 1 or abs(b - c) > 1)::2])


c = str(input())
n = len(c)
x = [i for i in range(n - 1) if c[i:i + 2] == 'AB']
y = [i for i in range(n - 1) if c[i:i + 2] == 'BA']
if x and y and (x[0] < y[-1] - 1 or y[0] < x[-1] - 1):
	print('YES')
else:
	print('NO')


s = input()
is_ab = s.find('AB') != -1
is_ba = s.find('BA', s.find('AB') + 2) != -1
if is_ab and is_ba:
	print('YES')
	exit()
is_ba = s.find('BA') != -1
is_ab = s.find('AB', s.find('BA') + 2) != -1
if is_ba and is_ab:
	print('YES')
else:
	print('NO')


s = input()
maxAB = -1
minAB = -1
maxBA = -1
minBA = -1
for i in range(len(s) - 1):
	if s[i] + s[i + 1] == 'AB':
		if minAB == -1:
			minAB = i
		maxAB = i
	if s[i] + s[i + 1] == 'BA':
		if minBA == -1:
			minBA = i
		maxBA = i
if (abs(maxAB - minBA) > 1 or abs(maxBA - minAB) > 1) and minAB > -1 and (minBA > -1):
	print('YES')
else:
	print('NO')


def solve(str, s1, s2):
	i = str.find(s1)
	return i > -1 and str.find(s2, i + 2) != -1
str = input()
res = solve(str, 'AB', 'BA') or solve(str, 'BA', 'AB')
print('YES' if res else 'NO')


s = input()
k = s
l = s
if len(s) <= 3:
	print('NO')
else:
	k = k.replace('AB', '.', 1)
	k = k.replace('BA', '.', 1)
	if k.count('.') == 2:
		print('YES')
	else:
		l = l.replace('BA', '.', 1)
		l = l.replace('AB', '.', 1)
		if l.count('.') == 2:
			print('YES')
		else:
			print('NO')


def main():
	s = input()
	a = s.find('AB')
	b = s.find('BA')
	if a == -1 or b == -1:
		print('NO')
		return
	if s[a + 2:].find('BA') != -1 or s[b + 2:].find('AB') != -1:
		print('YES')
		return
	print('NO')
	return
main()


s = input()
done = 0
ab_start_index_list = []
ba_start_index_list = []
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		ab_start_index_list.append(i)
	elif s[i:i + 2] == 'BA':
		ba_start_index_list.append(i)
for m in ab_start_index_list:
	for n in ba_start_index_list:
		if m != n - 1 and m != n + 1:
			done += 1
			break
if done == 0:
	print('NO')
else:
	print('YES')


sequence = str(input())
variant_first = sequence.replace('AB', '5', 1).replace('BA', '9', 1)
variant_two = sequence.replace('BA', '4', 1).replace('AB', '2', 1)
if '5' in variant_first and '9' in variant_first or ('2' in variant_two and '4' in variant_two):
	print('YES')
else:
	print('NO')


l = input()
a = 0
b = 0
for i in range(len(l) - 2):
	if l[i] == 'A' and l[i + 1] == 'B' and (l[i + 2] != 'A'):
		a = 1
	if l[i] == 'B' and l[i + 1] == 'A' and (l[i + 2] != 'B'):
		b = 1
if l[len(l) - 3:] != 'BAB' and l[len(l) - 2:] == 'AB':
	a = 1
if l[len(l) - 3:] != 'ABA' and l[len(l) - 2:] == 'BA':
	b = 1
c = 0
d = 0
k = 0
j = 0
for i in range(len(l) - 1):
	if l[i] == 'A' and l[i + 1] == 'B' and (c == 0):
		c = 1
		k = i + 1
	if l[i] == 'B' and l[i + 1] == 'A' and (c == 1) and (i != k):
		a = 1
		b = 1
	if l[i] == 'B' and l[i + 1] == 'A' and (d == 0):
		d = 1
		j = i + 1
	if l[i] == 'A' and l[i + 1] == 'B' and (d == 1) and (j != i):
		a = 1
		b = 1
if a + b == 2:
	print('YES')
else:
	print('NO')


s = input()
ab = s.find('AB')
ba = s.find('BA')
if ab != -1 and ba != -1:
	if abs(ab - ba) > 1:
		print('YES')
	elif abs(ab - ba) == 1:
		mx = max(ab, ba) + 2
		if s[mx:].find('AB') != -1 or s[mx:].find('BA') != -1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


x = input()
lab = 1000000000.0
rab = -1000000000.0
lba = 1000000000.0
rba = -1000000000.0
for i in range(len(x) - 1):
	if x[i:i + 2] == 'AB':
		lab = min(lab, i)
		rab = max(rab, i)
	if x[i:i + 2] == 'BA':
		lba = min(lba, i)
		rba = max(rba, i)
if lab < 1000000000.0 and lba < 1000000000.0:
	if lab + 1 < rba or lba + 1 < rab:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
if s.find('AB') >= 0 and s.replace('AB', '-', 1).find('BA') >= 0:
	print('YES')
elif s.find('BA') >= 0 and s.replace('BA', '-', 1).find('AB') >= 0:
	print('YES')
else:
	print('NO')


s = input()
if s.count('AB') == 0 or s.count('BA') == 0:
	print('NO')
else:
	t = s.replace('AB', 'xx', 1)
	tt = s.replace('BA', 'xx', 1)
	if t.count('BA') >= 1 or tt.count('AB') >= 1:
		print('YES')
	else:
		print('NO')


s = input()
id = s.find('AB')
if id != -1:
	p = s[id + 2:]
	if 'BA' in p:
		print('YES')
		exit()
id = s.find('BA')
if id == -1:
	print('NO')
	exit()
p = s[id + 2:]
if 'AB' in p:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
a = s.find('AB')
b = s.find('BA')
c = s.rfind('AB')
d = s.rfind('BA')
if a == -1 or b == -1:
	print('NO')
elif abs(a - b) >= 2 or abs(a - d) >= 2 or abs(b - c) >= 2 or (abs(c - d) >= 2):
	print('YES')
else:
	print('NO')


n = input()
n = list(n)
a = 0
b = 0
c = 0
for i in range(0, len(n) - 2):
	if n[i] == 'A' and n[i + 1] == 'B' and (n[i + 2] == 'A'):
		c += 1
		n[i] = ' '
		n[i + 1] = ' '
		n[i + 2] = ' '
	if n[i] == 'B' and n[i + 1] == 'A' and (n[i + 2] == 'B'):
		c += 1
		n[i] = ' '
		n[i + 1] = ' '
		n[i + 2] = ' '
if c >= 2:
	print('YES')
	exit()
for i in range(0, len(n) - 1):
	if n[i] == 'A' and n[i + 1] == 'B':
		a += 1
	if n[i] == 'B' and n[i + 1] == 'A':
		b += 1
if a & b or a & c or b & c:
	print('YES')
	exit()
else:
	print('NO')


def solve(s):
	(ab1, ab2) = (s.find('AB'), s.rfind('AB'))
	(ba1, ba2) = (s.find('BA'), s.rfind('BA'))
	if ab1 >= 0 and ba1 >= 0 and (abs(ab1 - ba2) > 1 or abs(ab2 - ba1) > 1):
		print('YES')
	else:
		print('NO')
solve(input())


s = input()
ab = []
ba = []
last = -9
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	if s[i:i + 2] == 'BA':
		ba.append(i)
F = False
for x in ab:
	for y in ba:
		if abs(x - y) != 1:
			F = True
			break
if F:
	print('YES')
else:
	print('NO')


s = input()
l = len(s)
a = -1
b = -1
for i in range(0, l - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a = i + 1
		break
for i in range(l - 1, 0, -1):
	if s[i] == 'A' and s[i - 1] == 'B':
		b = i - 1
		break
c = -1
d = -1
for i in range(0, l - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		c = i + 1
		break
for i in range(l - 1, 0, -1):
	if s[i] == 'B' and s[i - 1] == 'A':
		d = i - 1
		break
if a == -1 or b == -1:
	print('NO')
elif a != b and a - b != 2 or (c != d and c - d != 2):
	print('YES')
else:
	print('NO')


str2 = input()

def test(str1):
	if str1.count('AB') >= 1:
		str1 = str1.replace('AB', 'Z', 1)
		if str1.count('BA') >= 1:
			return True
		else:
			return False
	else:
		return False

def test1(str1):
	if str1.count('BA') >= 1:
		str1 = str1.replace('BA', 'Z', 1)
		if str1.count('AB') >= 1:
			return True
		else:
			return False
	else:
		return False
if test(str2) or test1(str2):
	print('YES')
else:
	print('NO')


s = input()
a = s.find('AB')
b = s.rfind('AB')
c = s.find('BA')
d = s.rfind('BA')
if 'AB' in s and 'BA' in s:
	if abs(a - d) >= 2 or abs(b - c) >= 2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


S = input()
Len = len(S)
a = []
b = []
i = 0
while i < Len:
	if i + 1 < Len and S[i] == 'A' and (S[i + 1] == 'B'):
		a.append(i)
	elif i + 1 < Len and S[i] == 'B' and (S[i + 1] == 'A'):
		b.append(i)
	i += 1
if len(a) == 0 or len(b) == 0:
	print('NO')
elif len(a) == 2 and len(b) == 1:
	if a[0] == b[0] - 1 and b[0] == a[1] - 1:
		print('NO')
	else:
		print('YES')
elif len(b) == 2 and len(a) == 1:
	if b[0] == a[0] - 1 and a[0] == b[1] - 1:
		print('NO')
	else:
		print('YES')
elif len(a) > 1 and len(b) >= 1:
	print('YES')
elif len(b) > 1 and len(a) >= 1:
	print('YES')
elif a[0] != b[0] + 1 and b[0] != a[0] + 1:
	print('YES')
else:
	print('NO')


s = input()
c = 0
if 'AB' in s:
	a = s.replace('AB', ',', 1)
	c += 1
	if 'BA' in a:
		c += 1
if c != 2:
	c = 0
	if 'BA' in s:
		a = s.replace('BA', ',', 1)
		c += 1
		if 'AB' in a:
			c += 1
print(['NO', 'YES'][c == 2])


s = input()
if s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB') - 1:
	if s.count('AB') and s.count('BA'):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = input()
ab1 = n.find('AB')
ba1 = n.find('BA', ab1 + 2)
ba2 = n.find('BA')
ab2 = n.find('AB', ba2 + 2)
if ab1 == -1 or ba1 == -1 or abs(ab1 - ba1) <= 1:
	if ab2 == -1 or ba2 == -1 or abs(ab2 - ba2) <= 1:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


a = input()
i = 0
j = len(a) - 1
t1 = t2 = 0
while i < len(a) and j > 0:
	try:
		if a[i] == 'A' and a[i + 1] == 'B':
			t1 = (i, i + 1)
		if a[j] == 'A' and a[j - 1] == 'B':
			t2 = (j - 1, j)
		if t1[0] not in t2 and t1[1] not in t2:
			print('YES')
			break
	except:
		pass
	i += 1
	j -= 1
else:
	print('NO')


a = input()
t = 'AB'
r = 'BA'
if t in a and r in a:
	w = str(a)
	w = w.replace(r, ' ', 1)
	a = a.replace(t, ' ', 1)
	if t in w:
		print('YES')
	elif r in a:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


a = input()
k = len(a)
ab = 0
ba = 0
aba = 0
bab = 0
m = 0
for i in range(0, k - 2):
	if a[i] == 'A' and a[i + 1] == 'B' and (a[i + 2] == 'A') and (i + 2 < k):
		aba = aba + 1
		break
	elif a[i] == 'A' and a[i + 1] == 'B' and (i + 1 < k):
		ab = ab + 1
		break
	elif a[i] == 'B' and a[i + 1] == 'A' and (a[i + 2] == 'B') and (i + 2 < k):
		bab = bab + 1
		break
	elif a[i] == 'B' and a[i + 1] == 'A' and (i + 1 < k):
		ba = ba + 1
		break
if aba > 0:
	for j in range(i + 3, k - 1):
		if a[j] == 'A' and a[j + 1] == 'B':
			ab = ab + 1
			break
		elif a[j] == 'B' and a[j + 1] == 'A':
			ba = ba + 1
			break
	if ab > 0 or ba > 0:
		m = 1
		print('YES')
elif ab > 0:
	for j in range(i + 2, k - 1):
		if a[j] == 'B' and a[j + 1] == 'A':
			ba = ba + 1
			break
	if ba > 0:
		m = 1
		print('YES')
elif bab > 0:
	for j in range(i + 3, k - 1):
		if a[j] == 'A' and a[j + 1] == 'B':
			ab = ab + 1
			break
		elif a[j] == 'B' and a[j + 1] == 'A':
			ba = ba + 1
			break
	if ab > 0 or ba > 0:
		m = 1
		print('YES')
elif ba > 0:
	for j in range(i + 2, k - 1):
		if a[j] == 'A' and a[j + 1] == 'B':
			ab = ab + 1
			break
	if ab > 0:
		m = 1
		print('YES')
if m == 0:
	print('NO')


def comprobar(cadena, tam):
	if tam <= 3:
		return 'NO'
	k = 0
	for i in range(tam - 2):
		if cadena[i] == 'A' and cadena[i + 1] == 'B':
			k = i + 2
			break
	if k != 0:
		for j in range(k, tam - 1):
			if cadena[j] == 'B' and cadena[j + 1] == 'A':
				return 'YES'
	k = 0
	for i in range(tam - 2):
		if cadena[i] == 'B' and cadena[i + 1] == 'A':
			k = i + 2
			break
	if k != 0:
		for j in range(k, tam - 1):
			if cadena[j] == 'A' and cadena[j + 1] == 'B':
				return 'YES'
	return 'NO'
A = input()
t = len(A)
if t > 100000:
	print('NO')
else:
	print(comprobar(A, t))


f = lambda l, r: abs(l - r) > 1 and l >= 0 and (r >= 0)
(lambda s: print('YES' if f(s.find('AB'), s.rfind('BA')) or f(s.find('BA'), s.rfind('AB')) else 'NO'))(input())


s = input()
if 'AB' in s and 'BA' in s:
	a = s.find('AB')
	b1 = s[a + 2:].find('BA')
	if b1 != -1:
		print('YES')
	else:
		b = s.find('BA')
		a1 = s[b + 2:].find('AB')
		if a1 != -1:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


def f(inp, ab, ba):
	i = inp.find(ab)
	return i != -1 and inp.find(ba, i + 2) != -1
inp = input()
if f(inp, 'AB', 'BA') or f(inp, 'BA', 'AB'):
	print('YES')
else:
	print('NO')


inp = input()
i = inp.find('AB')
j = inp.find('BA')
if i == -1 or j == -1:
	print('NO')
	exit()
x = inp.find('BA', i + 2)
if x != -1:
	print('YES')
	exit()
y = inp.find('AB', j + 2)
if y != -1:
	print('YES')
	exit()
print('NO')


s = input()
a = False
b = False
if 'AB' in s:
	ia = s.find('AB')
	a = True
	b = False
	if 'BA' in s[ia + 2:]:
		b = True
if (a == False or b == False) and 'BA' in s:
	ib = s.find('BA')
	b = True
	a = False
	if 'AB' in s[ib + 2:]:
		a = True
if b and a:
	print('YES')
else:
	print('NO')


a = input()
(q, w) = (a.count('ABA'), a.count('BAB'))
(r, t) = (a.count('AB'), a.count('BA'))
if min(r, t) == 0 or r + t - (w + q) < 2:
	print('NO')
else:
	print('YES')


inp = input()
lastab = None
lastba = None
if 'BA' not in inp or 'AB' not in inp:
	print('NO')
else:
	ab = inp.find('AB')
	ba = inp.find('BA')
	for i in range(min(ab, ba), len(inp)):
		if i < len(inp) - 2:
			second = inp[i + 1]
			third = inp[i + 2]
			subB = second + third
			if subB == 'BA':
				lastba = i
			elif subB == 'AB':
				lastab = i
	if ab != lastba and lastba is not None:
		print('YES')
	elif ba != lastab and lastab is not None:
		print('YES')
	else:
		print('NO')


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
s = read_str()
ab = s.find('AB')
ba = s.find('BA')
if ab != -1 and s.find('BA', ab + 2) > -1 or (ba != -1 and s.find('AB', ba + 2) > -1):
	print('YES')
else:
	print('NO')


def solve(s):
	ab = s.find('AB')
	ba = s.find('BA')
	if ab == -1 or ba == -1:
		return False
	ba1 = s.find('BA', ab + 2)
	ab1 = s.find('AB', ba + 2)
	return ba1 != -1 or ab1 != -1
s = input().rstrip()
print('YES' if solve(s) else 'NO')


s = input()
l = len(s)
count = 0
trig = []
for i in range(l - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		count = 1
		m = i
		trig.append(m)
if count > 0:
	for i in range(l - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			for m in trig:
				if i != m + 1 and i + 1 != m:
					count += 1
					break
if count >= 2:
	res = 'YES'
else:
	res = 'NO'
print(res)


string = input()
index1 = []
index2 = []
judge = False
if 'AB' not in string or 'BA' not in string:
	print('NO')
else:
	for i in range(len(string) - 1):
		if string[i] == 'A' and string[i + 1] == 'B':
			index1.append(i)
		elif string[i] == 'B' and string[i + 1] == 'A':
			index2.append(i)
	for i in index1:
		for j in index2:
			if abs(i - j) != 1:
				judge = True
				break
	if judge == True:
		print('YES')
	else:
		print('NO')


n = input()
res = 'NO'
mylist = ['BABAB', 'BAAAB', 'ABABA', 'ABBBA']
if 'ABA' not in n and 'BAB' not in n:
	if 'AB' in n and 'BA' in n:
		res = 'YES'
else:
	for i in mylist:
		if i in n:
			res = 'YES'
	if 'ABA' in n:
		n = n.replace('ABA', '', 1)
		if 'AB' in n or 'BA' in n:
			res = 'YES'
	elif 'BAB' in n:
		n = n.replace('BAB', '', 1)
		if 'AB' in n or 'BA' in n:
			res = 'YES'
print(res)


a = input()
b = a.count('AB')
c = a.replace('AB', '.', 1)
d = c.count('BA')
e = a.count('BA')
f = a.replace('BA', '.', 1)
g = f.count('AB')
if b > 0 and d > 0 or (g > 0 and e > 0):
	print('YES')
else:
	print('NO')


x = input()
m = False
for i in range(len(x)):
	if i + 1 < len(x) and x[i] == 'A' and (x[i + 1] == 'B'):
		n = min(i + 2, len(x) - 1)
		if 'BA' in x[:i] + ' ' + x[n:]:
			m = True
if m:
	print('YES')
else:
	print('NO')


st = input().strip()
cab = st.count('AB')
cba = st.count('BA')
if cab == 0 or cba == 0:
	print('NO')
else:
	found = False
	idx = None
	for i in range(cab):
		if idx == None:
			idx = st.find('AB')
		else:
			idx = idx + 1 + st[idx + 1:].find('AB')
		try:
			if max(st[0:idx].count('BA'), st[idx + 2:].count('BA')) > 0:
				found = True
				break
		except:
			pass
	if found:
		print('YES')
	else:
		print('NO')


s = input()
lab = None
lba = None
rab = None
rba = None
i = 0
while i < len(s) - 1:
	if s[i] == 'A' and s[i + 1] == 'B':
		if lab == None:
			lab = i
		rab = i
	elif s[i] == 'B' and s[i + 1] == 'A':
		if lba == None:
			lba = i
		rba = i
	i += 1
if lab == None or lba == None:
	print('NO')
elif rab != lab and rba != lba:
	print('YES')
elif rab == lab and rab + 1 == rba and (rab - 1 == lba):
	print('NO')
elif rba == lba and rba + 1 == rab and (rba - 1 == lab):
	print('NO')
elif rba == lba and rab == lab and (rab + 1 == rba or rab - 1 == rba):
	print('NO')
else:
	print('YES')


s = input()
a = 0
b = 0
AB = []
BA = []
flag = True
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		AB.append([i, i + 1])
	elif s[i] == 'B' and s[i + 1] == 'A':
		BA.append([i, i + 1])
for i in AB:
	for j in BA:
		flag = True
		if i[1] != j[0] and i[0] != j[1]:
			flag = False
			print('YES')
			break
	if not flag:
		break
if flag:
	print('NO')


s = str(input())
(aba, ab, ba, skip) = (0, 0, 0, 0)
n = len(s)
for i in range(n):
	if i < skip:
		continue
	if i + 2 < n and (s[i] == 'B' and s[i + 1] == 'A' and (s[i + 2] == 'B') or (s[i] == 'A' and s[i + 1] == 'B' and (s[i + 2] == 'A'))):
		aba += 1
		skip = i + 3
	elif i + 1 < n and s[i] == 'A' and (s[i + 1] == 'B'):
		ab += 1
		skip = i + 2
	elif i + 1 < n and s[i] == 'B' and (s[i + 1] == 'A'):
		ba += 1
		skip = i + 2
if min(ab, ba) > 0 or (aba > 0 and max(ab, ba) > 0) or aba > 1:
	print('YES')
else:
	print('NO')


s = input()
t = False
if s.find('AB') >= 0 and s.replace('AB', 'Z', 1).find('BA') >= 0 or (s.find('BA') >= 0 and s.replace('BA', 'Z', 1).find('AB') >= 0):
	t = True
print('YES' if t else 'NO')


import unittest
from random import randint
from sys import maxsize

class StressTest(unittest.TestCase):
	known_values = (('ABA', 'NO'), ('BACFAB', 'YES'), ('AXBYBXA', 'NO'), ('ABBA', 'YES'), ('ABABAB', 'YES'), ('A', 'NO'), ('ABAXXXAB', 'YES'))

	def test_known_cases(self):
		for (S, expected) in self.known_values:
			self.assertEqual(expected, NaiveSolution().twoSubs(S))

	def test_all_cases(self):
		while True:
			break

class NaiveSolution:

	def twoSubs(self, S):
		(ab_1, ba_1, i) = (0, 0, 0)
		(ab_2, ba_2, j) = (0, 0, len(S) - 1)
		while i < len(S) - 1:
			ss = S[i] + S[i + 1]
			if ab_1 == 0 and ss == 'AB':
				ab_1 += 1
				i += 2
			elif ba_1 == 0 and ab_1 == 1 and (ss == 'BA'):
				ba_1 += 1
				i += 2
			else:
				i += 1
		while j > 0:
			ss = S[j - 1] + S[j]
			if ab_2 == 0 and ss == 'AB':
				ab_2 += 1
				j -= 2
			elif ba_2 == 0 and ab_2 == 1 and (ss == 'BA'):
				ba_2 += 1
				j -= 2
			else:
				j -= 1
		scenario_1 = ab_1 == 1 and ba_1 == 1
		scenario_2 = ab_2 == 1 and ba_2 == 1
		return 'YES' if scenario_1 or scenario_2 else 'NO'

class BestSolution:
	pass
ans = NaiveSolution().twoSubs(input().strip())
print(ans)


def solve(s):
	(ab_s, ba_s) = ([], [])
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			ab_s.append(i)
		if s[i] == 'B' and s[i + 1] == 'A':
			ba_s.append(i)
	(lab, lba) = (len(ab_s), len(ba_s))
	if lab > 0 and lba > 0:
		(left, right) = (0, 0)
		while left < lab or right < lba:
			if left < lab and right < lba and (abs(ab_s[left] - ba_s[right]) > 1):
				return 'YES'
			if left > lab - 2 and right < lba or (right < lba - 1 and ab_s[left] <= ba_s[right]):
				right += 1
				continue
			if right > lba - 2 and left < lab or (left < lab - 1 and ab_s[left] >= ba_s[right]):
				left += 1
				continue
	return 'NO'

def main():
	s = input()
	print(solve(s))
main()


s = input()
(i, j) = (0, len(s) - 1)
(lab, lba, rab, rba) = (-999999, -999999, -999999, -999999)
while i <= len(s) - 2 and j >= 1:
	if (s[i] == 'A' and s[i + 1] == 'B') and lab == -999999:
		lab = i
	if (s[i] == 'B' and s[i + 1] == 'A') and lba == -999999:
		lba = i
	if (s[j - 1] == 'B' and s[j] == 'A') and rba == -999999:
		rba = j - 1
	if (s[j - 1] == 'A' and s[j] == 'B') and rab == -999999:
		rab = j - 1
	if lab != -999999 and lba != -999999 and (rab != -999999) and (rba != -999999):
		break
	i += 1
	j -= 1
m = max(lab, rba) - min(lab, rba)
n = max(lba, rab) - min(lba, rab)
if m >= 2 and m <= 100000 or (n >= 2 and n <= 100000):
	print('YES')
else:
	print('NO')


a = input()
b = a
f1 = 0
f2 = 0
if a.find('AB') != -1:
	a = a.replace('AB', 'C', 1)
	if a.find('BA') != -1:
		f1 = 1
if b.find('BA') != -1:
	b = b.replace('BA', 'C', 1)
	if b.find('AB') != -1:
		f2 = 1
if f1 == 0 and f2 == 0:
	print('NO')
else:
	print('YES')


(s, ix1, ix2) = (input(), [], [])
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		ix1.append(i)
	if s[i:i + 2] == 'BA':
		ix2.append(i)
if ix1 == [] or ix2 == []:
	print('NO')
elif abs(ix1[-1] - ix2[0]) > 1 or abs(ix1[0] - ix2[-1]) > 1:
	print('YES')
else:
	print('NO')


s = input()
a = s.count('AB')
b = s.count('BA')
c = s.count('ABA')
d = s.count('BAB')
e = c + d
if a > 0 and b > 0 and (a + b - e >= 2):
	print('YES')
else:
	print('NO')


prevc = ''
firstab = firstba = i = 0
for c in input():
	i += 1
	if prevc == 'A' and c == 'B':
		if firstab == 0:
			firstab = i
		if firstba and i - firstba > 1:
			print('YES')
			exit()
	elif prevc == 'B' and c == 'A':
		if firstba == 0:
			firstba = i
		if firstab and i - firstab > 1:
			print('YES')
			exit()
	prevc = c
print('NO')


string = input()
string2 = string
string = string.replace('AB', '1', 1)
string = string.replace('BA', '1', 1)
count = string.count('1')
if count == 2:
	print('YES')
else:
	string2 = string2.replace('BA', '1', 1)
	string2 = string2.replace('AB', '1', 1)
	count = string2.count('1')
	if count == 2:
		print('YES')
	else:
		print('NO')


strr = input()
cntab = strr.count('AB')
cntba = strr.count('BA')
if cntba > 1 and cntab > 1:
	print('YES')
elif cntba == 2 and cntab == 1 and (strr.find('BABA') == -1):
	print('YES')
elif cntab == 2 and cntba == 1 and (strr.find('ABAB') == -1):
	print('YES')
elif cntba == 1 and cntab == 1 and (strr.find('ABA') == -1 and strr.find('BAB') == -1):
	print('YES')
elif cntab > 2 and cntba == 1:
	print('YES')
elif cntba > 2 and cntab == 1:
	print('YES')
else:
	print('NO')


s = input()
if not 'AB' in s:
	print('NO')
elif not 'BA' in s.replace('AB', ' ', 1):
	if 'BA' in s:
		if not 'AB' in s.replace('BA', ' ', 1):
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
else:
	print('YES')


def solve():
	s = input()
	n = len(s)
	ab = []
	ba = []
	if n == 1 or n == 2 or n == 3:
		print('NO')
	else:
		i = 0
		while i < n - 1:
			if 'AB' in s[i:i + 2]:
				ab.append(i)
			elif 'BA' in s[i:i + 2]:
				ba.append(i)
			i += 1
		f = 0
		for i in ab:
			for j in ba:
				if abs(j - i) >= 2:
					f = 1
					break
				else:
					f = 0
			if f == 1:
				break
		if f == 1:
			print('YES')
		else:
			print('NO')
solve()


s = input()
a = []
b = []
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		a.append(i)
	elif s[i:i + 2] == 'BA':
		b.append(i)
for x in a:
	for y in b:
		if abs(x - y) > 1:
			print('YES')
			quit()
print('NO')


s = list(input())
ab = 0
ba = 0
aba = 0
bab = 0
flag = 0
n = len(s)
i = 1
while i < n:
	if ab == 0 and s[i] == 'A' and (s[i - 1] == 'B'):
		ab += 1
		i += 2
		continue
	if ab > 0 and s[i] == 'B' and (s[i - 1] == 'A'):
		ba += 1
		break
	i += 1
flag = 1 if ab > 0 and ba > 0 else 0
if flag == 0:
	i = 1
	ab = 0
	ba = 0
	while i < n:
		if ab == 0 and s[i] == 'B' and (s[i - 1] == 'A'):
			ab += 1
			i += 2
			continue
		if ab > 0 and s[i] == 'A' and (s[i - 1] == 'B'):
			ba += 1
			break
		i += 1
	flag = 1 if ab > 0 and ba > 0 else 0
if flag == 1:
	print('YES')
else:
	print('NO')


s = input()
q = s
v = 0
u = 0
if 'AB' in s:
	v = v + 1
	z = s.index('AB')
	s = s[:z] + 'ab' + s[z + 2:]
if 'BA' in s:
	v = v + 1
if 'BA' in q:
	u = u + 1
	z = q.index('BA')
	q = q[:z] + 'ba' + q[z + 2:]
if 'AB' in q:
	u = u + 1
if v == 2 or u == 2:
	print('YES')
else:
	print('NO')


def check(string):
	string = string.upper()
	if 'AB' in string and 'BA' in string.replace('AB', '-', 1) or ('BA' in string and 'AB' in string.replace('BA', '-', 1)):
		return 'YES'
	else:
		return 'NO'
print(check(input()))


s = input()
flag = 0
if 'AB' in s:
	x = s.index('AB')
	r = s[:x] + 'CC' + s[x + 2:]
	if 'BA' in r:
		flag = 1
if 'BA' in s:
	x = s.index('BA')
	r = s[:x] + 'CC' + s[x + 2:]
	if 'AB' in r:
		flag = 1
if flag:
	print('YES')
else:
	print('NO')


string = input()
s = -1
ans = 'NO'
if len(string) < 2:
	print('NO')
else:
	for i in range(len(string) - 1):
		if string[i:i + 2] == 'AB':
			break
	for j in range(i + 2, len(string) - 1):
		if string[j:j + 2] == 'BA':
			ans = 'YES'
	for i in range(len(string) - 1):
		if string[i:i + 2] == 'BA':
			break
	for j in range(i + 2, len(string) - 1):
		if string[j:j + 2] == 'AB':
			ans = 'YES'
	print(ans)


string = str(input())

def main(string):
	AB_faced = False
	BA_faced = False
	index = string.find('AB')
	if index == -1:
		return 'NO'
	else:
		AB_faced = True
		BA_faced = False if string.find('BA', 0, index) == -1 else True
		if BA_faced is False:
			BA_faced = False if string.find('BA', index + 2) == -1 else True
	if AB_faced and BA_faced:
		return 'YES'
	AB_faced = False
	BA_faced = False
	index = string.find('BA')
	if index == -1:
		return 'NO'
	else:
		BA_faced = True
		AB_faced = False if string.find('AB', 0, index) == -1 else True
		if AB_faced is False:
			AB_faced = False if string.find('AB', index + 2) == -1 else True
	return 'YES' if AB_faced and BA_faced else 'NO'
print(main(string))


s = input()
i = 0
ab = False
ba = False
o = 0
while i < len(s) - 1:
	if i < len(s) - 2 and (not o and (not ab) and (not ba)) and (s[i:i + 2] == 'AB' and s[i + 1:i + 3] == 'BA') or (s[i:i + 2] == 'BA' and s[i + 1:i + 3] == 'AB'):
		o += 1
		i += 2
	elif s[i:i + 2] == 'AB' and (not ab):
		ab = True
		i += 1
	elif s[i:i + 2] == 'BA' and (not ba):
		ba = True
		i += 1
	i += 1
if ab + ba + o >= 2:
	print('YES')
else:
	print('NO')


def reverse(a):
	return a[::-1]

def find_all(str, sub):
	start = 0
	a = []
	while start < len(str):
		d = str.find(sub, start)
		if not d == -1:
			a.append(d)
			start = d + len(sub)
		else:
			break
		if len(a) == 3:
			break
	return a

def find_rev(str, sub):
	start = 0
	a = []
	str = reverse(str)
	while start < len(str):
		d = str.find(sub, start)
		if not d == -1:
			p = len(m) - d - 2
			a.append(p)
			start = d + len(sub)
		else:
			break
		if len(a) == 0:
			break
	return a
m = input()
a = []
a = find_all(m, 'AB')
b = []
b = find_all(m, 'BA')
c = 0
b = reverse(b)
for x in a:
	for y in b:
		d = abs(x - y)
		if d > 1:
			c = 1
			break
if c == 1:
	print('YES')
else:
	print('NO')


s = input()
k = s.find('AB')
j = s.find('BA')
m = min(k, j)
if m == -1:
	print('NO')
else:
	flag = 1
	if m == k:
		b = s[m + 2:].find('BA')
		if b != -1:
			print('YES')
		else:
			flag = 0
	else:
		b = s[m + 2:].find('AB')
		if b != -1:
			print('YES')
		else:
			flag = 0
	if flag == 0:
		if s.count('AB') > 1 or s.count('BA') > 1:
			if s.count('AB') > 1:
				if s[j + 2:].find('AB') != -1:
					print('YES')
				else:
					print('NO')
			elif s.count('BA') > 1:
				if s[k + 2:].find('BA') != -1:
					print('YES')
				else:
					print('NO')
		else:
			print('NO')


import sys
s = input()
if 'AB' not in s or 'BA' not in s:
	print('NO')
	sys.exit()
pos = s.find('AB')
if pos + 2 < len(s) and 'BA' in s[pos + 2:]:
	print('YES')
	sys.exit()
pos = s.find('BA')
if pos + 2 < len(s) and 'AB' in s[pos + 2:]:
	print('YES')
	sys.exit()
else:
	print('NO')


s = input()
x = s.find('AB')
y = s.find('BA')
if x + 1 and s.find('BA', x + 2) + 1 or (y + 1 and s.find('AB', y + 2) + 1):
	print('YES')
else:
	print('NO')


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0
tcmax = 99999999

def compute(val, func):
	return func(val)

def seq(lo, hi, step=1):
	return range(lo, hi + 1, step)

def sround(val, nd):
	return f'{val:.{nd}f}'

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def num(str=None):
	str = str or line()
	return float(str) if '.' in str else int(str)

def nums(o=None):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(num, o or split()))

def mainloop(tcid=1):
	s = line()

	def aaa(aa, bb):
		ii = s.find(aa)
		if ii < 0:
			return false
		jj = s.find(bb, ii + 2)
		return jj > -1
	ab = 'AB'
	ba = 'BA'

	def bbb():
		return aaa(ab, ba) or aaa(ba, ab)
	yes = 'YES'
	no = 'NO'
	ans = [no, yes]
	ans = ans[bbb()]
	print(ans)
while tcid < tcmax:
	tcid += 1
	mainloop(tcid)


a = input()
b = a
flag1 = 0
flag2 = 0
if a.find('AB') != -1:
	a = a.replace('AB', '#', 1)
	if a.find('BA') != -1:
		flag1 = 1
if b.find('BA') != -1:
	b = b.replace('BA', '#', 1)
	if b.find('AB') != -1:
		flag2 = 1
if flag1 == 0 and flag2 == 0:
	print('NO')
else:
	print('YES')


s = input()
try:
	i1 = s.index('AB')
	i2 = s.index('BA')
	if abs(i1 - i2) == 1:
		try:
			s.index('AB', min(i1, i2) + 3)
		except ValueError:
			s.index('BA', min(i1, i2) + 3)
	elif i1 < i2:
		s.index('BA', i1 + 2)
	else:
		s.index('AB', i2 + 2)
	print('YES')
except ValueError:
	print('NO')


data = input()

def run():
	for index in range(len(data) - 1):
		if data[index:index + 2] == 'AB':
			if data[index + 2:].count('BA') > 0:
				return 'YES'
		if data[index:index + 2] == 'BA':
			if data[index + 2:].count('AB') > 0:
				return 'YES'
	return 'NO'
print(run())


n = input()
a = n.find('AB')
b = n[a + 2:].find('BA')
c = n.find('BA')
d = n[c + 2:].find('AB')
print('YES' if a >= 0 and b >= 0 or (c >= 0 and d >= 0) else 'NO  ')


s = input()
a = None
b = None
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		if a is None:
			a = i
		if b is not None and abs(i - b) > 1:
			print('YES')
			exit(0)
	if s[i] == 'B' and s[i + 1] == 'A':
		if b is None:
			b = i
		if a is not None and abs(a - i) > 1:
			print('YES')
			exit(0)
print('NO')


def fd70000000():
	s = input()
	rs = s
	AB = s.find('AB')
	sw = False
	if AB != -1:
		s = s[:AB] + ' ' + s[AB + 2:]
		AB = s.find('BA')
		if AB != -1:
			sw = True
	AB = rs.rfind('AB')
	if AB != -1:
		rs = rs[:AB] + ' ' + rs[AB + 2:]
		AB = rs.find('BA')
		if AB != -1:
			sw = True
	if sw:
		return print('YES')
	return print('NO')
fd70000000()


def main():
	(a, ab, ba) = ('*', [], [])
	for (i, b) in enumerate(input()):
		if a == 'A' and b == 'B':
			ab.append(i)
		elif a == 'B' and b == 'A':
			ba.append(i)
		a = b
	print(('NO', 'YES')[bool(ab and ba) and (ba[-1] - ab[0] > 1 or ab[-1] - ba[0] > 1)])
main()


s = input()
x = s.find('AB')
y = s.find('BA', x + 2)
i = s.find('BA')
j = s.find('AB', i + 2)
if x > -1 and y > -1:
	print('YES')
elif i > -1 and j > -1:
	print('YES')
else:
	print('NO')


s = input()
s_len = len(s)
result = 'NO'
ab = None
ba = None
ab2 = None
ba2 = None
for i in range(s_len - 1):
	if s[i] == 'A' and s[i + 1] == 'B' and (ab is None):
		ab = i + i + 1
	if s[i] == 'B' and s[i + 1] == 'A':
		ba = i + i + 1
		if ab and abs(ab - ba) >= 4:
			result = 'YES'
			break
	if s[i] == 'B' and s[i + 1] == 'A' and (ba2 is None):
		ba2 = i + i + 1
	if s[i] == 'A' and s[i + 1] == 'B':
		ab2 = i + i + 1
		if ba2 and abs(ab2 - ba2) >= 4:
			result = 'YES'
			break
print(result)


s = input()

def isPresent(s, t):
	k = s.find(t)
	if k == -1:
		return False
	if s[:k].find(t[::-1]) == -1 and s[k + 2:].find(t[::-1]) == -1:
		return False
	return True
if isPresent(s, 'AB') or isPresent(s, 'BA'):
	print('YES')
else:
	print('NO')


s = str(input())
a = 99999
b = 99999
i = 0
while i < len(s) - 1:
	if a == 99999 or b == 99999:
		if s[i:i + 2] == 'AB':
			a = i
		elif s[i:i + 2] == 'BA':
			b = i
	elif s[i:i + 2] == 'AB' and (not abs(i - b) < 2):
		a = i
	elif s[i:i + 2] == 'BA' and (not abs(a - i) < 2):
		b = i
	if abs(a - b) >= 2 and (not a == 99999) and (not b == 99999):
		break
	i += 1
if abs(a - b) >= 2 and (not a == 99999) and (not b == 99999):
	print('YES')
else:
	print('NO')


s = input()
if 'AB' in s and 'BA' in s:
	ct = s.index('AB')
	d = 0
	if 'BA' in s[ct + 2:]:
		d = 1
	else:
		d = 0
	if d == 0:
		ct = s.index('BA')
		if 'AB' in s[ct + 2:]:
			print('YES')
		else:
			print('NO')
	if d:
		print('YES')
else:
	print('NO')


s = input()
s1 = s.replace('AB', 'x', 1)
s2 = s.replace('BA', 'x', 1)
if len(s1) < len(s) and s1.find('BA') != -1:
	print('YES')
elif len(s2) < len(s) and s2.find('AB') != -1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
s = input().strip()
ab = []
ba = []
n = len(s)
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	if s[i:i + 2] == 'BA':
		ba.append(i)
try:
	if abs(min(ab) - max(ba)) > 1 or abs(max(ab) - min(ba)) > 1:
		print('YES')
	else:
		print('NO')
except:
	print('NO')


from itertools import accumulate

def bin_search(x, left, right, num_list):
	if right - left <= 1:
		if x <= num_list[left]:
			return left + 1
		else:
			return right + 1
	else:
		middle = (left + right) // 2
		if x < num_list[middle]:
			return bin_search(x, left, middle, num_list)
		elif x > num_list[middle]:
			return bin_search(x, middle + 1, right, num_list)
		else:
			return middle + 1
s = input()
if s.find('AB') >= 0 and s.find('BA') >= 0:
	if abs(s.find('AB') - s.rfind('BA')) >= 2 or abs(s.rfind('AB') - s.find('BA')) >= 2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def solve():
	a = s.find('AB')
	b = s.rfind('AB')
	c = s.find('BA')
	d = s.rfind('BA')
	found = (abs(a - d) > 1 or abs(b - c) > 1) and min(a, b, c, d) >= 0
	return 'NO YES'.split()[found]

def main():
	global s
	s = input()
	print(solve())
main()


s = input()
a = b = -1
for i in range(len(s) - 1):
	if s[i] == 'A':
		if s[i + 1] == 'B':
			if a == -1:
				a = i
			if 0 <= b < i - 1:
				print('YES')
				exit()
	elif s[i] == 'B':
		if s[i + 1] == 'A':
			if b == -1:
				b = i
			if 0 <= a < i - 1:
				print('YES')
				exit()
print('NO')


s = input()
ab = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ab += [i]
n = len(ab)
if n > 0:
	for i in range(len(s) - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			if n == 1 and abs(ab[0] - i) == 1:
				continue
			elif n == 2 and abs(ab[0] - ab[1]) == 2 and (i - ab[0] == 1):
				continue
			if i - 1 not in ab or (i - 1 in ab and n > 1):
				print('YES')
				exit()
print('NO')


string = input()
(nAB, nBA) = (string.count('AB'), string.count('BA'))
if nAB == 0 or nBA == 0:
	print('NO')
	exit()
(dBA, dAB) = (-2, -2)
for i in range(nAB):
	dAB = string.find('AB', dAB + 2)
	for j in range(nBA):
		dBA = string.find('BA', dBA + 2)
		if abs(dBA - dAB) > 1:
			print('YES')
			exit()
	dBA = -2
print('NO')


s = input()
ans1 = []
ans2 = []
if len(s) < 2:
	print('NO')
else:
	for i in range(1, len(s)):
		if s[i - 1] == 'A' and s[i] == 'B':
			ans1.append('AB')
			i += 2
			break
	for e in range(i, len(s)):
		if s[e - 1] == 'B' and s[e] == 'A':
			ans1.append('BA')
			i += 2
			break
	for i in range(1, len(s)):
		if s[i - 1] == 'B' and s[i] == 'A':
			ans2.append('BA')
			i += 2
			break
	for e in range(i, len(s)):
		if s[e - 1] == 'A' and s[e] == 'B':
			ans2.append('AB')
			i += 2
			break
	if ans1.count('AB') == 1 and ans1.count('BA') == 1 or (ans2.count('AB') == 1 and ans2.count('BA') == 1):
		print('YES')
	else:
		print('NO')


s = input()
af = s.find('AB')
ae = s.rfind('AB')
bf = s.find('BA')
be = s.rfind('BA')
if min(af, ae, bf, be) >= 0:
	if abs(af - be) > 1 or abs(ae - bf) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import re
s = input()
a1 = s.find('BA') + 1 < s.rfind('AB')
a2 = s.find('AB') + 1 < s.rfind('BA')
print('YES' if s.find('AB') >= 0 and s.find('BA') >= 0 and (a1 or a2) else 'NO')


s = input()
p = list(s)
q = list(s)
o = 0
e = 0
mark1 = 0
mark2 = 0
for i in range(len(p) - 1):
	if mark1 == 0:
		if p[i] == 'A' and p[i + 1] == 'B':
			o += 1
			p[i] = 0
			p[i + 1] = 0
			mark1 += 1
	if mark1 != 0 and mark2 == 0:
		if p[i] == 'B' and p[i + 1] == 'A':
			o += 1
			p[i] = 0
			p[i + 1] = 0
			mark2 += 1
mark1 = 0
mark2 = 0
for i in range(len(q) - 1):
	if mark1 == 0:
		if q[i] == 'B' and q[i + 1] == 'A':
			e += 1
			q[i] = 0
			q[i + 1] = 0
			mark1 += 1
	if mark1 != 0 and mark2 == 0:
		if q[i] == 'A' and q[i + 1] == 'B':
			e += 1
			q[i] = 0
			q[i + 1] = 0
			mark2 += 1
if e == 2 or o == 2:
	print('YES')
else:
	print('NO')


s = input()
i = 0
(AB, BA) = (0, 0)
ff = True
dd = True
over = 0
while i <= len(s) - 2:
	if s[i:i + 3] == 'ABA' or s[i:i + 3] == 'BAB':
		i += 3
		over += 1
	if s[i:i + 2] == 'AB' and ff == True:
		i += 2
		AB = 1
		ff = False
	elif s[i:i + 2] == 'BA' and dd == True:
		BA = 1
		i += 2
		dd = False
	else:
		i += 1
if AB == 1 and BA == 1 or (AB == 1 and over >= 1) or (BA == 1 and over >= 1):
	print('YES')
else:
	print('NO')


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(s):
	ff = 0
	if 'AB' in s and 'BA' in s:
		ab = s.find('AB') + 2
		if s[ab:].find('BA') != -1:
			ff = 1
		ba = s.find('BA') + 2
		if s[ba:].find('AB') != -1:
			ff = 1
		if ff:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
s = str(input())
solve(s)


word = input()
n = len(word)
ab = []
ba = []
for i in range(0, n - 1):
	if word[i:i + 2] == 'AB':
		ab.append(i)
	elif word[i:i + 2] == 'BA':
		ba.append(i)
if len(ab) >= 1 and len(ba) >= 1 and (len(ab) + len(ba) >= 4):
	print('YES')
elif len(ab) == 1 and len(ba) == 1 and (abs(ab[0] - ba[0]) != 1):
	print('YES')
elif len(ab) >= 2 and len(ba) == 1 and (abs(ab[0] - ba[0]) != 1 or abs(ab[1] - ba[0]) != 1):
	print('YES')
elif len(ab) == 1 and len(ba) >= 2 and (abs(ab[0] - ba[0]) != 1 or abs(ab[0] - ba[1]) != 1):
	print('YES')
else:
	print('NO')


def isValid(i):
	c1 = s[i]
	c2 = s[i - 1]
	c3 = s[i - 2]
	dp_AB[i] = dp_AB[i - 1]
	dp_BA[i] = dp_BA[i - 1]
	if c1 == 'A':
		if c2 == 'B':
			if c3 == 'A':
				if dp_AB[i - 3] or dp_BA[i - 3]:
					return True
				else:
					(dp_AB[i], dp_BA[i]) = (True, True)
			elif dp_AB[i - 2]:
				return True
			else:
				dp_BA[i] = True
	elif c1 == 'B':
		if c2 == 'A':
			if c3 == 'B':
				if dp_AB[i - 3] or dp_BA[i - 3]:
					return True
				else:
					(dp_AB[i], dp_BA[i]) = (True, True)
			elif dp_BA[i - 2]:
				return True
			else:
				dp_AB[i] = True
	return False
s = input()
if len(s) < 4:
	print('NO')
elif len(s) == 4:
	if s == 'ABBA' or s == 'BAAB':
		print('YES')
	else:
		print('NO')
else:
	dp_AB = [False] * len(s)
	dp_BA = [False] * len(s)
	for i in range(1, 4):
		dp_AB[i] = 'AB' in s[:i + 1]
		dp_BA[i] = 'BA' in s[:i + 1]
	for i in range(4, len(s)):
		if isValid(i):
			print('YES')
			break
	else:
		print('NO')


import math
s = input()
b = False
A = -5
B = -5
A1 = len(s)
B1 = len(s)
n = len(s)
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		A = i
	if s[n - i - 2] == 'B' and s[n - i - 1] == 'A':
		B = n - i - 2
	if s[i] == 'B' and s[i + 1] == 'A':
		B1 = i
	if s[n - i - 2] == 'A' and s[n - i - 1] == 'B':
		A1 = n - i - 2
if A == -5 or B == -5:
	print('NO')
elif math.fabs(A - B) != 1:
	print('YES')
elif math.fabs(A1 - B1) != 1:
	print('YES')
else:
	print('NO')


s = input()
cnt_a = 0
cnt_b = 0
cnt_c = 0
cnt_d = 0
a = 'AB'
b = 'BA'
c = 'ABA'
d = 'BAB'
cnt_a = s.count(a)
cnt_b = s.count(b)
cnt_c = s.count(c)
cnt_d = s.count(d)
if cnt_a != 0 and cnt_b != 0:
	if cnt_a + cnt_b - (cnt_c + cnt_d) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
(AB, BA, BOTH) = (False, False, False)
index = 0
for i in range(len(s)):
	if s[i:i + 3] == 'ABA' or s[i:i + 3] == 'BAB':
		index = i
		BOTH = True
		break
	elif s[i:i + 2] == 'AB':
		index = i
		AB = True
		break
	elif s[i:i + 2] == 'BA':
		index = i
		BA = True
		break
if AB or BA or BOTH:
	for j in range(len(s)):
		if BOTH and j > index + 2:
			if s[j:j + 2] == 'AB' or s[j:j + 2] == 'BA':
				(AB, BA) = (True, True)
				break
		elif AB and j > index + 1 and (s[j:j + 2] == 'BA'):
			BA = True
			break
		elif BA and j > index + 1 and (s[j:j + 2] == 'AB'):
			AB = True
			break
if AB and BA:
	print('YES')
else:
	print('NO')


s = input()
for pattern in [('AB', 'BA'), ('BA', 'AB')]:
	found1 = False
	i = 0
	while i < len(s) - 1:
		sub = s[i:i + 2]
		if sub == pattern[0] and (not found1):
			found1 = True
			i += 1
		elif sub == pattern[1] and found1:
			print('YES')
			exit()
		i += 1
print('NO')


arr = input()
n = len(arr)
ab = 0
ba = 0
ab2 = 0
ba2 = 0
check = 0
mark = [0 for _ in range(n)]
mark2 = [0 for _ in range(n)]
for i in range(n - 1):
	if arr[i] == 'A' and arr[i + 1] == 'B' and (ab == 0):
		if mark[i] == 0 and mark[i + 1] == 0:
			ab += 1
			mark[i] = 1
			mark[i + 1] = 1
	elif arr[i] == 'B' and arr[i + 1] == 'A' and (ba == 0):
		if mark[i] == 0 and mark[i + 1] == 0:
			ba += 1
			mark[i] = 1
			mark[i + 1] = 1
	if arr[n - 2 - i] == 'A' and arr[n - 1 - i] == 'B' and (ab2 == 0):
		if mark2[n - 2 - i] == 0 and mark2[n - 1 - i] == 0:
			ab2 += 1
			mark2[n - 2 - i] = 1
			mark2[n - 1 - i] = 1
	elif arr[n - 2 - i] == 'B' and arr[n - 1 - i] == 'A' and (ba2 == 0):
		if mark2[n - 2 - i] == 0 and mark2[n - 1 - i] == 0:
			ba2 += 1
			mark2[n - 2 - i] = 1
			mark2[n - 1 - i] = 1
if ab == ba == 1 or ab2 == ba2 == 1:
	print('YES')
else:
	print('NO')


s = input()
crossing = 0
ab = 0
ba = 0
n = len(s)
i = 0
while i < n - 1:
	if s[i:i + 2] == 'AB':
		if s[i + 1:i + 3] == 'BA':
			crossing += 1
			i += 3
		else:
			ab += 1
			i += 1
	elif s[i:i + 2] == 'BA':
		if s[i + 1:i + 3] == 'AB':
			crossing += 1
			i += 3
		else:
			ba += 1
			i += 1
	else:
		i += 1
if ab > 0 and ba > 0 or (ab > 0 and crossing > 0) or (ba > 0 and crossing > 0) or (crossing > 1):
	print('YES')
else:
	print('NO')


import re
string1 = input()
flag = 0
try:
	c = [m.start() for m in re.finditer('AB', string1)]
	d = [m.start() for m in re.finditer('BA', string1)]
	for c1 in c:
		for d1 in d:
			if d1 - c1 > 1 or c1 - d1 > 1:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')
except:
	print('NO')


s = input()
for x in range(len(s) - 1):
	if s[x] == 'A' and s[x + 1] == 'B':
		break
else:
	print('NO')
	quit()
for y in range(x + 2, len(s) - 1):
	if s[y] == 'B' and s[y + 1] == 'A':
		print('YES')
		quit()
for a in range(len(s) - 1):
	if s[a] == 'B' and s[a + 1] == 'A':
		break
else:
	print('NO')
	quit()
for b in range(a + 2, len(s) - 1):
	if s[b] == 'A' and s[b + 1] == 'B':
		print('YES')
		quit()
print('NO')


import re
s = input()
p1 = [m.start() for m in re.finditer('AB', s)]
p2 = [m.start() for m in re.finditer('BA', s)]
if p1 and p2:
	found = False
	for i in p1:
		if found:
			break
		for j in p2:
			if not found and abs(i - j) >= 2:
				print('YES')
				found = True
				break
	if not found:
		print('NO')
else:
	print('NO')


s = input()
L1 = []
L2 = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		L1.append(i)
	elif s[i] == 'B' and s[i + 1] == 'A':
		L2.append(i)
flag = True
i = 0
while i < len(L1) and flag:
	j = 0
	while j < len(L2) and flag:
		if abs(L2[j] - L1[i]) > 1:
			flag = False
		j = j + 1
	i = i + 1
if flag == False:
	print('YES')
else:
	print('NO')


s = input()
u = s.find('AB')
v = s.find('BA')
if u + 1 and s.find('BA', u + 2) != -1:
	print('YES')
elif v + 1 and s.find('AB', v + 2) != -1:
	print('YES')
else:
	print('NO')


s = input()
ok = False
p = s.replace('AB', 'OO', 1)
if 'BA' in p and 'AB' in s:
	ok = True
p = s.replace('BA', 'OO', 1)
if 'AB' in p and 'BA' in s:
	ok = True
print('YES' if ok else 'NO')


a = input()
i = 0
b = 0
A = 0
B = 0
while i < len(a):
	if a[i:i + 3] == 'ABA' or a[i:i + 3] == 'BAB':
		b += 1
		i += 3
	elif a[i:i + 2] == 'AB':
		A += 1
		i += 2
	elif a[i:i + 2] == 'BA':
		B += 1
		i += 2
	else:
		i += 1
if b > 1:
	print('YES')
elif b > 0 and (A > 0 or B > 0):
	print('YES')
elif A > 0 and B > 0:
	print('YES')
else:
	print('NO')


s = input()
AB = [x for x in range(len(s) - 1) if s[x] + s[x + 1] == 'AB']
BA = [x for x in range(len(s) - 1) if s[x] + s[x + 1] == 'BA']
try:
	print('YES' if AB[0] + 1 < BA[-1] or BA[0] + 1 < AB[-1] else 'NO')
except IndexError:
	print('NO')


s = input()
prev = s[0]
cond = False
for i in range(1, len(s)):
	if prev + s[i] == 'AB':
		cond = 'BA' in s[0:i - 1] + '  ' + s[i + 1:len(s)]
	elif prev + s[i] == 'BA':
		cond = 'AB' in s[0:i - 1] + '  ' + s[i + 1:len(s)]
	prev = s[i]
	if cond:
		break
print(['NO', 'YES'][cond])


s = input()
flag = False
if 'AB' in s:
	s1 = s.replace('AB', ' ', 1)
	if 'BA' in s1:
		flag = True
if 'BA' in s:
	s2 = s.replace('BA', ' ', 1)
	if 'AB' in s2:
		flag = True
if flag == False:
	print('NO')
else:
	print('YES')


class CodeforcesTask550ASolution:

	def __init__(self):
		self.result = ''
		self.string = ''

	def read_input(self):
		self.string = input()

	def process_task(self):
		if 'AB' in self.string and 'BA' in self.string:
			if 'BA' in self.string.replace('AB', '__', 1):
				self.result = 'YES'
			elif 'AB' in self.string.replace('BA', '__', 1):
				self.result = 'YES'
			else:
				self.result = 'NO'
		else:
			self.result = 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask550ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


i = input()
t = 0
for j in range(len(i) - 1):
	if i[j] + i[j + 1] == 'AB':
		if j + 2 < len(i):
			if 'BA' in i[j + 2:]:
				print('YES')
				t = 1
				break
if t == 0:
	for j in range(len(i) - 1):
		if i[j] + i[j + 1] == 'BA':
			if j + 2 < len(i):
				if 'AB' in i[j + 2:]:
					t = 1
					print('YES')
					break
if t == 0:
	print('NO')


s = input()
l1 = s.find('AB')
r1 = s.rfind('BA')
l2 = s.find('BA')
r2 = s.rfind('AB')
if l1 >= 0 and r1 >= 0 and (l1 - r1 > 1 or l1 - r1 < -1) or (l2 >= 0 and r2 >= 0 and (l2 - r2 > 1 or l2 - r2 < -1)):
	print('YES')
else:
	print('NO')


k = input()
j = k
j = j.replace('AB', '*', 1)
j = j.replace('BA', '^', 1)
if '*' in j and '^' in j:
	print('YES')
	exit(0)
j = k
j = j.replace('BA', '*', 1)
j = j.replace('AB', '^', 1)
if '*' in j and '^' in j:
	print('YES')
	exit(0)
print('NO')


s = input()
l = len(s)
lba = []
lab = []
for i in range(l - 1):
	if s[i:i + 2] == 'BA':
		lba.append(i)
	if s[i:i + 2] == 'AB':
		lab.append(i)
if len(lab) == 0 or len(lba) == 0:
	print('NO')
elif abs(lba[0] - lab[-1]) >= 2 or abs(lba[0] - lab[0]) >= 2 or abs(lba[-1] - lab[0]) >= 2:
	print('YES')
else:
	print('NO')


s = input()
_AB = 0
_BA = 0
flag = 0
n = len(s)
i = 0
while i < n:
	if s[i] == 'A':
		if i + 1 < n and s[i + 1] == 'B':
			_AB = 1
			i += 2
			break
	i += 1
while i < n:
	if s[i] == 'B':
		if i + 1 < n and s[i + 1] == 'A':
			_BA = 1
			i += 2
			break
	i += 1
if _AB and _BA:
	print('YES')
	flag = 1
_AB = 0
_BA = 0
i = 0
while i < n:
	if s[i] == 'B':
		if i + 1 < n and s[i + 1] == 'A':
			_AB = 1
			i += 2
			break
	i += 1
while i < n:
	if s[i] == 'A':
		if i + 1 < n and s[i + 1] == 'B':
			_BA = 1
			i += 2
			break
	i += 1
if flag == 0:
	if _AB and _BA:
		print('YES')
	else:
		print('NO')


import re
a = input()
b = a
flag = 0
if 'AB' in a:
	a = re.sub('AB', ' ', a, 1)
	if 'BA' in a:
		flag = 1
if 'BA' in b:
	b = re.sub('BA', ' ', b, 1)
	if 'AB' in b:
		flag = 1
if flag == 1:
	print('YES')
else:
	print('NO')


s = input()
if 'AB' in s:
	s1 = s.replace('AB', 'X', 1)
	if 'BA' in s1:
		print('YES')
	elif 'BA' in s:
		s1 = s.replace('BA', 'X', 1)
		if 'AB' in s1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')
pass


s = input()
if 'AB' in s and 'BA' in s:
	if s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB') >= 2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = str(input())
ab = s.find('AB')
ba = s.find('BA')
if ab != -1 and s.find('BA', ab + 2) != -1 or (ba != -1 and s.find('AB', ba + 2) != -1):
	print('YES')
else:
	print('NO')


def main():

	def isin(s, t):
		res = []
		for i in range(len(s) - 1):
			if s[i:i + 2] == t:
				res.append(i)
		return res
	s = input()
	ab = isin(s, 'AB')
	ba = isin(s, 'BA')
	if len(ab) == 0 or len(ba) == 0:
		print('NO')
	else:
		for a in ab:
			for b in ba:
				if abs(a - b) >= 2:
					print('YES')
					exit()
		print('NO')
main()


string = input()
if string.find('AB') == -1 or string.find('BA') == -1:
	print('NO')
elif string.find('AB', string.find('BA') + 2) != -1 or string.find('BA', string.find('AB') + 2) != -1:
	print('YES')
else:
	print('NO')


s = input()
ans = []
gans = []
for i in range(len(s) - 1):
	if s[i] == 'A':
		if s[i + 1] == 'B':
			ans.append(i)
	if s[i] == 'B':
		if s[i + 1] == 'A':
			gans.append(i)
if min(len(ans), len(gans)) == 0:
	print('NO')
	exit()
if abs(gans[-1] - ans[0]) > 1 or abs(gans[0] - ans[-1]) > 1:
	print('YES')
else:
	print('NO')


s = input()
l = s.find('AB')
l1 = s.find('BA')
r = s.rfind('BA')
r1 = s.rfind('AB')
if l == -1 or r == -1:
	print('NO')
elif r - l > 1 or r1 - l1 > 1:
	print('YES')
else:
	print('NO')


def search_podstroki(s, t):
	t1 = t + '$' + s
	p = [-1] * len(t1)
	prefix(t1, p)
	c1 = 0
	for i in range(1, len(t1)):
		if p[i] == len(t) - 1:
			c1 = -1
			return i - len(t) - 1
	if c1 != -1:
		return False

def prefix(t, p):
	k = 0
	for i in range(1, len(t)):
		k = p[i - 1]
		while k >= 0 and t[k + 1] != t[i]:
			k = p[k]
		if t[k + 1] == t[i]:
			k = k + 1
		p[i] = k
s = input()
s1 = 'AB'
s2 = 'BA'
r = search_podstroki(s, s1)
if r == False:
	print('NO')
else:
	s3 = s[r + 1:]
	e = search_podstroki(s3, s2)
	if e == False:
		r = search_podstroki(s, s2)
		if r == False:
			print('NO')
		else:
			s3 = s[r + 1:]
			e = search_podstroki(s3, s1)
			if e == False:
				print('NO')
			else:
				print('YES')
	else:
		print('YES')


def run():
	import sys
	sys.stdin = open('/home/punit/Documents/Cpp Programs/input.txt', 'r')
	sys.stdout = open('/home/punit/Documents/Cpp Programs/output.txt', 'w')
	from math import ceil, sqrt, floor
s = input()
flag1 = 0
j = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		flag1 += 1
		j = i + 2
		break
for i in range(j, len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		flag1 += 1
		break
flag2 = 0
j = 0
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		flag2 += 1
		j = i + 2
		break
for i in range(j, len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		flag2 += 1
		break
if flag2 == 2 or flag1 == 2:
	print('YES')
else:
	print('NO')


s = input()
ABfirst = s.find('AB')
BAfirst = s.find('BA')
if ABfirst == -1 or BAfirst == -1:
	print('NO')
elif abs(ABfirst - BAfirst) > 1:
	print('YES')
else:
	next_pos = min(ABfirst, BAfirst) + 3
	if s.find('AB', next_pos) >= 0 or s.find('BA', next_pos) >= 0:
		print('YES')
	else:
		print('NO')


s = input()
x = s.find('AB')
if x == -1:
	print('NO')
else:
	k = s.replace('AB', 'l', 1)
	y = k.find('BA')
	if y == -1:
		x = s.find('BA')
		if x == -1:
			print('NO')
		else:
			k = s.replace('BA', 'l', 1)
			y = k.find('AB')
			if y == -1:
				print('NO')
			else:
				print('YES')
	else:
		print('YES')


s = input()
n = len(s)
ab = []
ba = []
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	if s[i:i + 2] == 'BA':
		ba.append(i)
for x in ab:
	for y in ba:
		if y + 1 < x or x + 1 < y:
			print('YES')
			exit()
print('NO')


s = input()
l = len(s)
a = 0
b = 0
for i in range(l - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a += 1
	if s[i] == 'B' and s[i + 1] == 'A':
		b += 1
r = 'YES'
if a * b == 0:
	r = 'NO'
if a == b == 1:
	if 'ABA' in s or 'BAB' in s:
		r = 'NO'
if a == 1 and b == 2 or (a == 2 and b == 1):
	if 'ABAB' in s or 'BABA' in s:
		r = 'NO'
print(r)


s = input()
succ = False
x = s.find('AB')
if x != -1:
	z = s[:x].find('BA')
	y = s[x + 2:].find('BA')
	if z != -1 or y != -1:
		succ = True
x = s.find('BA')
if x != -1:
	z = s[:x].find('AB')
	y = s[x + 2:].find('AB')
	if z != -1 or y != -1:
		succ = True
print(['NO', 'YES'][succ])


a = input()
c = int(0)
d = int(0)
e = int(0)
f = int(0)
for i in range(len(a) - 1):
	if a[i] + a[i + 1] == 'AB':
		c = i + 1
		break
for i in range(len(a) - 2, -1, -1):
	if a[i] + a[i + 1] == 'BA':
		d = i + 1
		break
for i in range(len(a) - 2, -1, -1):
	if a[i] + a[i + 1] == 'AB':
		e = i + 1
		break
for i in range(len(a) - 1):
	if a[i] + a[i + 1] == 'BA':
		f = i + 1
		break
if max(abs(c - d), max(abs(c - f), max(abs(e - d), abs(e - f)))) > 1 and (c > 0 and d > 0):
	print('YES')
else:
	print('NO')


s = input()
i1 = s.find('AB')
i2 = s.find('BA')
found = False
if i1 >= 0:
	i3 = s.find('BA', i1 + 2)
	if i3 != -1:
		print('YES')
		found = True
if not found and i2 >= 0:
	i3 = s.find('AB', i2 + 2)
	if i3 != -1:
		print('YES')
		found = True
if not found:
	print('NO')


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
import re
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi, log
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from functools import cmp_to_key, reduce
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def solve():
	s = input()
	(ab, ba) = (s.find('AB'), s.find('BA'))
	print('YES' if ab + 1 and s.find('BA', ab + 2) + 1 or (ba + 1 and s.find('AB', ba + 2) + 1) else 'NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
solve()


s = input()
if len(s) < 4:
	print('NO')
	exit(0)
k_AB = 0
k_A = 0
k_B = 0
for i in range(len(s) - 2):
	if s[i] + s[i + 1] + s[i + 2] == 'ABA' or s[i] + s[i + 1] + s[i + 2] == 'BAB':
		k_AB += 1
		s = s[:i] + '000' + s[i + 3:]
		buf = i
if k_AB == 1:
	s = s[:buf] + s[buf + 3:]
if k_AB > 1:
	print('YES')
else:
	for i in range(len(s) - 1):
		if s[i] + s[i + 1] == 'AB':
			k_A += 1
		elif s[i] + s[i + 1] == 'BA':
			k_B += 1
	if k_AB > 2 or (k_AB == 1 and k_A + k_B > 0) or (k_AB == 0 and k_A > 0 and (k_B > 0)):
		print('YES')
	else:
		print('NO')


s = input()
n = len(s)
if n == 1 or n == 2 or n == 3:
	print('NO')
else:
	cnt1 = 0
	cnt2 = 0
	i = 0
	ind1 = []
	ind2 = []
	while i < n - 1:
		if s[i] == 'A' and s[i + 1] == 'B':
			cnt1 += 1
			ind1.append(i)
			i += 1
		i += 1
	i = 0
	while i < n - 1:
		if s[i] == 'B' and s[i + 1] == 'A':
			cnt2 += 1
			ind2.append(i)
			i += 1
		i += 1
	if cnt1 * cnt2 > 0:
		f = 0
		for i in range(len(ind1)):
			for j in range(len(ind2)):
				if abs(ind1[i] - ind2[j]) > 1:
					f = 1
					break
			if f == 1:
				break
		if f == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


n = input()
ab = -1
ba = -1
found = False
for i in range(len(n) - 1):
	check = n[i:i + 2]
	if check == 'AB':
		if ba > -1 and ba != i - 1:
			print('YES')
			found = True
			break
		elif ab == -1:
			ab = i
	elif check == 'BA':
		if ab > -1 and ab != i - 1:
			print('YES')
			found = True
			break
		elif ba == -1:
			ba = i
if found == False:
	print('NO')


s = input()

def findPattern():
	ans = ''
	ba_pos = s.find('BA')
	ab_pos = s.find('AB')
	if ab_pos != -1:
		s_new = s[ab_pos + 2:]
		if s_new.find('BA') != -1:
			ans = 'YES'
		else:
			ans = 'NO'
	else:
		ans = 'NO'
	if ba_pos != -1 and ans == 'NO':
		s_new = s[ba_pos + 2:]
		if s_new.find('AB') != -1:
			ans = 'YES'
		else:
			ans = 'NO'
	return ans
print(findPattern())


s = input()
f = 'NO'
if 'AB' in s:
	k = s.index('AB')
	for i in range(k + 2, len(s) - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			f = 'YES'
			break
	if f == 'NO':
		for i in range(k - 1):
			if s[i] == 'B' and s[i + 1] == 'A':
				f = 'YES'
				break
if 'BA' in s and f == 'NO':
	k = s.index('BA')
	for i in range(k + 2, len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			f = 'YES'
			break
	if f == 'NO':
		for i in range(k - 1):
			if s[i] == 'A' and s[i + 1] == 'B':
				f = 'YES'
				break
print(f)


string = input()
k1 = 0
i = 0
k2 = 0
k3 = 0
k4 = 0
for i in range(len(string) - 1):
	if string[i] == 'A' and string[i + 1] == 'B':
		if i > 0 and string[i - 1] == 'B':
			k3 += 1
		else:
			k1 += 1
	elif string[i] == 'B' and string[i + 1] == 'A':
		if i > 0 and string[i - 1] == 'A':
			k4 += 1
		else:
			k2 += 1
if k1 >= 1 and k2 >= 1:
	print('YES')
elif k1 >= 2 and k4 >= 1:
	print('YES')
elif k2 >= 2 and k3 >= 1:
	print('YES')
elif max(k3, k4) >= 2:
	print('YES')
else:
	print('NO')


s = input()
print('YES' if s.find('AB') >= 0 and s[s.find('AB') + 2:].find('BA') >= 0 or (s.find('BA') >= 0 and s[s.find('BA') + 2:].find('AB') >= 0) else 'NO')


a = input()
if 'AB' in a:
	if 'BA' in a[a.index('AB') + 2:]:
		exit(print('YES'))
if 'BA' in a:
	if 'AB' in a[a.index('BA') + 2:]:
		exit(print('YES'))
print('NO')


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
l = z()
a = l.count('AB')
b = l.count('BA')
c = l.count('ABA')
d = l.count('BAB')
if a == 0 or b == 0:
	print('NO')
	exit()
if a + b - c - d >= 2:
	print('YES')
else:
	print('NO')


i = input()
l = len(i)
pos_ab = []
pos_ba = []
for x in range(l - 1):
	if i[x:x + 2] == 'AB':
		pos_ab.append(x)
	elif i[x:x + 2] == 'BA':
		pos_ba.append(x)
done = False
for p in pos_ab:
	for p2 in pos_ba:
		if abs(p - p2) >= 2:
			print('YES')
			done = True
			break
	if done:
		break
else:
	print('NO')


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
s = input()
n = len(s)
if n < 4:
	print('NO')
	exit()

def check(a):
	ind = -1
	ind3 = -1
	for i in range(n - 1):
		if s[i] == a[0] and s[i + 1] == a[1]:
			ind3 = i
			ind = i + 1
			break
	ind2 = -1
	ind4 = -1
	k = i + 1
	for i in range(k, n - 1):
		if s[i] == a[1] and s[i + 1] == a[0]:
			ind4 = i + 1
			ind2 = i
	if ind == -1 or ind2 == -1 or ind3 == -1 or (ind4 == -1):
		return False
	elif ind != ind2 and ind3 != ind4:
		return True
	else:
		return False
if check('AB') or check('BA'):
	print('YES')
else:
	print('NO')


str = input()
pos = str.find('AB')
flag = False
if pos != -1:
	if pos != 0:
		mystr = str[0:pos - 1:1] + str[pos + 2:len(str):1]
	else:
		mystr = str[pos + 2:len(str):1]
	pos = mystr.find('BA')
	if pos != -1:
		flag = True
	else:
		flag = False
else:
	flag = False
if flag:
	print('YES')
else:
	pos = str.find('BA')
	if pos != -1:
		if pos != 0:
			mystr = str[0:pos - 1:1] + str[pos + 2:len(str):1]
		else:
			mystr = str[pos + 2:len(str):1]
		pos = mystr.find('AB')
		if pos != -1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


s = input()
abmin = s.find('AB')
abmax = s.rfind('AB')
bamin = s.find('BA')
bamax = s.rfind('BA')
if min(abmin, bamin) == -1:
	print('NO')
else:
	z1 = abs(abmin - bamin)
	z2 = abs(abmin - bamax)
	z3 = abs(abmax - bamin)
	z4 = abs(abmax - bamax)
	if max(z1, z2, z3, z4) > 1:
		print('YES')
	else:
		print('NO')


string = input()
print('YES' if 'AB' in string and 'BA' in string.replace('AB', '-', 1) or ('BA' in string and 'AB' in string.replace('BA', '-', 1)) else 'NO')


i = str(input())
if 'AB' in i and 'BA' in i:
	k = i.index('AB')
	d = i.index('BA')
	if 'BA' in i[k + 2:]:
		print('YES')
	elif 'AB' in i[d + 2:]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
f = False
if 'AB' in s:
	a = s.index('AB')
	if 'BA' in s[a + 2:]:
		f = True
if 'BA' in s:
	a = s.index('BA')
	if 'AB' in s[a + 2:]:
		f = True
print('YES' if f else 'NO')


import sys
s = list(sys.stdin.readline())
d = 0
e = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B' and (d == 0):
		d = i + 2
	elif s[i] == 'B' and s[i + 1] == 'A' and (e == 0):
		e = i + 2
a = ''.join(s[d:])
b = ''.join(s[e:])
if d != 0 and 'BA' in a:
	print('YES')
elif e != 0 and 'AB' in b:
	print('YES')
else:
	print('NO')


def check(a, k):
	if a.count(-1) == 0 or a.count(1) == 0:
		return 'NO'
	for i in range(k - 1):
		if a[i] != 0:
			for j in range(i + 2, k):
				if a[i] + a[j] == 0:
					return 'YES'
	return 'NO'
s = input()
a = [0] * (len(s) - 1)
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		a[i] = -1
	if s[i] == 'A' and s[i + 1] == 'B':
		a[i] = 1
print(check(a, len(s) - 1))


s = input()
ans = False
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		if i + 2 < len(s) - 1 and s[i + 2:].count('BA') != 0:
			ans = True
			break
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		if i + 2 < len(s) - 1 and s[i + 2:].count('AB') != 0:
			ans = True
			break
if ans:
	print('YES')
else:
	print('NO')


X = input()
if 'AB' in X:
	Z = X.replace('AB', '1', 1)
	Y = X[::-1].replace('BA', '1', 1)
	if 'BA' in Z or 'AB' in Y:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def any_in(subs, ss):
	return any((x in s for x in subs for s in ss))
s = input()
if 'ABA' in s:
	l = s.split('ABA', 1)
	if any_in(['AB', 'BA'], l):
		print('YES')
		exit(0)
	if 'BAB' not in s:
		print('NO')
		exit(0)
if 'BAB' in s:
	l = s.split('BAB', 1)
	if any_in(['AB', 'BA'], l):
		print('YES')
	else:
		print('NO')
	exit(0)
if 'AB' in s and 'BA' in s:
	print('YES')
	exit(0)
print('NO')


a = input()
n = len(a)
if a.count('AB') > 0 and a.count('BA') > 0 and (n >= 4):
	x1 = -1
	y1 = -1
	x2 = -1
	y2 = -1
	x1 = a.find('AB')
	if x1 != -1:
		y1 = a.find('BA', x1 + 2)
	x2 = a.find('BA')
	if x2 != -1:
		y2 = a.find('AB', x2 + 2)
	if x1 != -1 and y1 != -1:
		print('YES')
	elif x2 != -1 and y2 != -1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


q = input()
y = len(q)
(r, t) = (-1, -1)
l = 0
h = 0
for i in range(y - 1):
	if q[i] + q[i + 1] == 'AB':
		r = i
	elif q[i] + q[i + 1] == 'BA':
		t = i
if r == -1 or t == -1:
	print('NO')
else:
	for i in range(r - 1):
		if q[i] + q[i + 1] == 'BA':
			l = 1
	for i in range(r + 2, y - 1):
		if q[i] + q[i + 1] == 'BA':
			l = 1
	for i in range(t - 1):
		if q[i] + q[i + 1] == 'AB':
			h = 1
	for i in range(t + 2, y - 1):
		if q[i] + q[i + 1] == 'AB':
			h = 1
	if max(l, h) == 1:
		print('YES')
	else:
		print('NO')


def checkSubString(s, sub):
	foundAB = False
	foundBA = False
	found = False
	i = 0
	while i < len(s) - 1:
		if not found:
			if s[i] == sub[0] and s[i + 1] == sub[1]:
				found = True
				if i + 2 < len(s):
					i += 2
			else:
				i += 1
		elif s[i] == sub[1] and s[i + 1] == sub[0]:
			print('YES')
			return True
		else:
			i += 1
	return False
s = input()
if not checkSubString(s, 'AB'):
	if not checkSubString(s, 'BA'):
		print('NO')


s = input()
x1 = s.find('AB')
y1 = s.rfind('BA')
x2 = s.rfind('AB')
y2 = s.find('BA')
if x1 == -1 or y1 == -1:
	from sys import exit
	print('NO')
	exit()
if max(x1, y1) - min(x1, y1) - 1 > 0 or max(x2, y2) - min(x2, y2) - 1 > 0:
	print('YES')
else:
	print('NO')


k = input()
(a, b, c, i) = (0, 0, 0, 0)
while i < len(k):
	if k[i:i + 3] == 'ABA' or k[i:i + 3] == 'BAB':
		a = a + 1
		i = i + 3
	elif k[i:i + 2] == 'AB':
		b = b + 1
		i = i + 2
	elif k[i:i + 2] == 'BA':
		c = c + 1
		i = i + 2
	else:
		i = i + 1
if a > 1 or (a > 0 and (b > 0 or c > 0)) or (b > 0 and c > 0):
	print('YES')
else:
	print('NO')


string = input()
ab_indexes = []
ba_indexes = []
for k in range(len(string) - 1):
	part = string[k] + string[k + 1]
	if part == 'AB':
		ab_indexes.append(k)
	if part == 'BA':
		ba_indexes.append(k)

def exists():
	for k in ab_indexes:
		for i in ba_indexes:
			if abs(i - k) > 1:
				return True
	return False
if exists():
	print('YES')
else:
	print('NO')


p = ['ABBA', 'BAAB']
b = [0, 0]
pc = 'X'
block = False
for c in input():
	if not (p[0] and p[1]):
		break
	for i in [0, 1]:
		if b[i]:
			b[i] = 0
			continue
		if p[i][1] == c and p[i][0] == pc:
			p[i] = p[i][2:]
			b[i] = 1
	pc = c
print('YNEOS'[bool(p[0] and p[1])::2])


s = input()
li_s1 = []
li_s2 = []
temp = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		li_s1.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		li_s2.append(i)
if len(li_s1) >= 1 and len(li_s2) >= 1:
	temp.append(li_s1[0] - li_s2[-1])
	temp.append(li_s2[0] - li_s1[-1])
flag = any((i >= 2 or i <= -2 for i in temp))
if flag:
	print('YES')
else:
	print('NO')


def occurence():
	s = input()
	l = len(s)
	count_ab = 0
	count_ba = 0
	i = 0
	while i < l:
		if i < l - 1 and s[i] == 'A' and (s[i + 1] == 'B'):
			if count_ba > 0:
				return 'YES'
			elif i < l - 2 and s[i + 2] == 'A':
				count_ab += 1
				count_ba += 1
				i += 3
			else:
				count_ab += 1
				i += 2
		elif i < l - 1 and s[i] == 'B' and (s[i + 1] == 'A'):
			if count_ab > 0:
				return 'YES'
			elif i < l - 2 and s[i + 2] == 'B':
				count_ab += 1
				count_ba += 1
				i += 3
			else:
				count_ba += 1
				i += 2
		else:
			i += 1
	return 'NO'
print(occurence())


s = input()
n = len(s)
ans = [-1] * n
ba = False
ab = False
ab_1 = False
ba_1 = False
for i in range(n):
	if s[i] == 'B':
		ans[i] = 2
	elif s[i] == 'A':
		ans[i] = 1
ans_1 = ans[:]
for i in range(n - 1):
	if ans[i] == 2 and ans[i + 1] == 1:
		ba = True
		ans[i] = -1
		ans[i + 1] = -1
		break
for i in range(n - 1):
	if ans[i] == 1 and ans[i + 1] == 2:
		ab = True
		ans[i] = -1
		ans[i + 1] = -1
		break
for i in range(n - 1):
	if ans_1[i] == 1 and ans_1[i + 1] == 2:
		ab_1 = True
		ans_1[i] = -1
		ans_1[i + 1] = -1
		break
for i in range(n - 1):
	if ans_1[i] == 2 and ans_1[i + 1] == 1:
		ba_1 = True
		ans_1[i] = -1
		ans_1[i + 1] = -1
		break
if ba and ab:
	print('YES')
elif ab_1 and ba_1:
	print('YES')
else:
	print('NO')


inputList = input().split()
if len(inputList) == 0:
	print('NO')
else:
	ABCounter = 0
	BACounter = 0
	OverlapCounter = 0
	MayOverlapFlag = False
	testStr = inputList[0]
	i = 0
	while i < len(testStr) - 1:
		currentValue = testStr[i]
		nextValue = testStr[i + 1]
		if currentValue == 'A' and nextValue == 'B':
			ABCounter += 1
			if MayOverlapFlag:
				OverlapCounter += 1
			else:
				MayOverlapFlag = True
		elif currentValue == 'B' and nextValue == 'A':
			BACounter += 1
			if MayOverlapFlag:
				OverlapCounter += 1
			else:
				MayOverlapFlag = True
		else:
			MayOverlapFlag = False
		i += 1
	if ABCounter >= 1 and BACounter >= 1 and (ABCounter + BACounter > 3):
		print('YES')
	elif ABCounter >= 1 and BACounter >= 1 and (ABCounter + BACounter == 3) and (OverlapCounter < 2):
		print('YES')
	elif ABCounter == 1 and BACounter == 1 and (OverlapCounter == 0):
		print('YES')
	else:
		print('NO')


import math
import operator as op
from functools import reduce
from fractions import Fraction as frac

def tkp():
	import sys
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	s = input('')
	for i in range(len(s) - 1):
		if s[i:i + 2] == 'AB':
			if 'BA' in s[i + 2:]:
				print('YES')
				exit()
		if s[i:i + 2] == 'BA':
			if 'AB' in s[i + 2:]:
				print('YES')
				exit()
	print('NO')

def local():
	t = int(input())
	for i in range(t):
		print('Case', i)
		solve()

def judge():
	solve()
judge()


mot = input()
if len(mot) <= 3:
	print('NO')
else:
	ab = mot.count('AB')
	ba = mot.count('BA')
	aba = mot.count('ABA')
	bab = mot.count('BAB')
	abab = mot.count('ABAB')
	baba = mot.count('BABA')
	if abab == 1 and ab == 2 and (ba == 1):
		print('NO')
	elif baba == 1 and ba == 2 and (ab == 1):
		print('NO')
	elif aba == 1 and ab == 1 and (ba == 1):
		print('NO')
	elif bab == 1 and ab == 1 and (ba == 1):
		print('NO')
	elif ab == 0 or ba == 0:
		print('NO')
	else:
		print('YES')


s = input()
if 'AB' not in s or 'BA' not in s:
	print('NO')
	exit()
ab = [i for i in range(len(s) - 1) if s[i:i + 2] == 'AB']
ba = [i for i in range(len(s) - 1) if s[i:i + 2] == 'BA']
print(('NO', 'YES')[max(max(ab) - min(ba), max(ba) - min(ab)) > 1])


s = input()
length = len(s)
flag = 0
for x in range(length - 1):
	if flag == 0:
		if s[x:x + 2] == 'AB':
			flag = 1
	elif flag == 1:
		flag += 1
	elif s[x:x + 2] == 'BA':
		print('YES')
		exit()
flag = 0
for x in range(length - 1):
	if flag == 0:
		if s[x:x + 2] == 'BA':
			flag = 1
	elif flag == 1:
		flag += 1
	elif s[x:x + 2] == 'AB':
		print('YES')
		exit()
print('NO')


s = input().rstrip()
n = int(len(s))
if n <= 3:
	print('NO')
else:
	d = [0] * n
	for i in range(n - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			d[i] = 1
	ans = 'NO'
	for i in range(1, n):
		d[i] += d[i - 1]
	for i in range(n - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			if i - 2 >= 0:
				if d[i - 2] >= 1 or d[-1] - d[i + 1] >= 1:
					ans = 'YES'
					break
			elif i + 2 < n:
				if d[-1] - d[i + 1] >= 1:
					ans = 'YES'
					break
	print(ans)


def foo(string, sub):
	ans = []
	for i in range(len(string) - len(sub) + 1):
		for j in range(len(sub)):
			if string[i + j] != sub[j]:
				break
		else:
			ans.append(i)
	return ans
s = input()
a1 = foo(s, 'AB')
a2 = foo(s, 'BA')
f = 0
for elm in a2:
	for start in a1:
		if elm not in range(start, start + 2) and elm + 1 not in range(start, start + 2):
			print('YES')
			f = 1
			break
	if f:
		break
else:
	print('NO')


word = list(input())
flag = False
for i in range(len(word) - 1):
	if word[i] == 'A' and word[i + 1] == 'B':
		for j in range(i + 2, len(word) - 1):
			if word[j] == 'B' and word[j + 1] == 'A':
				flag = True
				break
		break
for i in range(len(word) - 1):
	if word[i] == 'B' and word[i + 1] == 'A':
		for j in range(i + 2, len(word) - 1):
			if word[j] == 'A' and word[j + 1] == 'B':
				flag = True
				break
		break
if flag:
	print('YES')
else:
	print('NO')


s = input()
index = 0
a0 = s.replace('AB', 'cc', 1).replace('BA', 'cc', 1)
a1 = s.replace('BA', 'cc', 1).replace('AB', 'cc', 1)
if a0.count('c') == 4 or a1.count('c') == 4:
	print('YES')
else:
	print('NO')


def fun(s):
	x = s.find('AB')
	y = s.find('BA')
	if x == -1 or y == -1:
		return 'NO'
	if x > 1 and s[0:x - 1].find('BA') != -1 or s[x + 2:].find('BA') != -1:
		return 'YES'
	if y > 1 and s[0:y - 1].find('AB') != -1 or s[y + 2:].find('AB') != -1:
		return 'YES'
	return 'NO'
s = input()
print(fun(s))


s = input()
ab = []
ba = []
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	elif s[i:i + 2] == 'BA':
		ba.append(i)
if len(ab) == 0 or len(ba) == 0:
	print('NO')
else:
	works = False
	for i in ab:
		if works:
			break
		for j in ba:
			if works:
				break
			if i != j - 1 and i != j + 1:
				print('YES')
				works = True
	if not works:
		print('NO')


i = input()

def contains(string):
	ab = False
	abpos = -3
	ba = False
	i = 0
	aba = False
	if string.count('AB') == 0 or string.count('BA') == 0 or ((string.count('ABAB') == 1 or string.count('BABA') == 1) and string.count('A') + string.count('B') == 4):
		return 'NO'
	if string.count('AB') > 1 and string.count('BA') > 1 or (string.count('AB') > 0 and string.count('BA') > 0 and (string.count('ABA') == 0) and (string.count('BAB') == 0)) or (string.count('AB') > 1 and string.count('BAB') == 1) or (string.count('BA') > 1 and string.count('ABA') == 1):
		return 'YES'
	while (i < len(string) - 1 or (ab and i < len(string))) and (not (ab and ba)):
		if string[i] == 'A':
			if not ab:
				if i < len(string) - 2 and string[i + 1] == 'B' and (string[i + 2] == 'A'):
					aba = True
					i += 2
				else:
					ab = string[i + 1] == 'B'
					abpos = i if ab else -3
					if i > 0 and (not ba) and (not ab):
						ba = string[i - 1] == 'B'
						if ba:
							i += 1
			elif i > abpos + 2:
				ba = string[i - 1] == 'B'
		i += 1
	return 'YES' if (ab or aba) and ba or (ab and (ba or aba)) else 'NO'
print(contains(i))


s = input()
n = len(s)
l = []
k = []
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		l.append([i + 1, i])
	if s[i] == 'B' and s[i + 1] == 'A':
		k.append([i, i + 1])
if len(l) == 0 or len(k) == 0:
	print('NO')
else:
	if abs(len(l) - len(k)) > 0 and (len(l) > 2 or len(k) > 2):
		flag = 1
	else:
		flag = 0
		for i in range(len(l)):
			if l[i][0] != k[0][0] and l[i][1] != k[0][1]:
				flag = 1
				break
		for i in range(len(k)):
			if k[i][0] != l[0][0] and k[i][1] != l[0][1]:
				flag = 1
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')


x = input()
count = 0
if 'AB' in x:
	s = x[x.index('AB') + 2::1]
	if 'BA' in s:
		count += 1
if 'BA' in x:
	s = x[x.index('BA') + 2::1]
	if 'AB' in s:
		count += 1
if count >= 1:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
i = 0
while i < n - 3:
	if s[i] == 'A' and s[i + 1] == 'B':
		i += 2
		while i < n - 1:
			if s[i] == 'B' and s[i + 1] == 'A':
				print('YES')
				exit()
			i += 1
	i += 1
i = 0
while i < n - 3:
	if s[i] == 'B' and s[i + 1] == 'A':
		i += 2
		while i < n - 1:
			if s[i] == 'A' and s[i + 1] == 'B':
				print('YES')
				exit()
			i += 1
	i += 1
print('NO')


s = input()
a = s.count('AB')
b = s.count('BA')
c = s.count('ABA')
d = s.count('BAB')
if a * b == c + d or a == 0 or b == 0:
	print('NO')
else:
	print('YES')


a = input()
b = a.find('AB')
c = a.find('BA')
flag = 0
if b + 1 and a.find('BA', b + 2) + 1 or (c + 1 and a.find('AB', c + 2) + 1):
	flag = 1
print('YES' if flag else 'NO')


s = input()
i = 0
listAB = []
listBA = []
while i < len(s) - 1:
	cCurr = s[i + 1]
	cPrev = s[i]
	if cCurr == 'B' and cPrev == 'A':
		listAB += [i]
	if cCurr == 'A' and cPrev == 'B':
		listBA += [i]
	i += 1
if len(listAB) > 0 and len(listBA) > 0 and (listAB[0] + 1 < listBA[-1] or listBA[0] + 1 < listAB[-1]):
	print('YES')
else:
	print('NO')


from sys import stdin
s = list(stdin.readline().rstrip())
a = 0
b = 0
c = 0
d = 0
le = len(s)
for i in range(le - 1):
	if i < le - 2 and s[i] == 'A' and (s[i + 1] == 'B') and (s[i + 2] == 'A'):
		s[i] = s[i + 1] = s[i + 2] = ''
		c += 1
	elif i < le - 2 and s[i] == 'B' and (s[i + 1] == 'A') and (s[i + 2] == 'B'):
		s[i] = s[i + 1] = s[i + 2] = ''
		d += 1
	elif s[i] == 'B' and s[i + 1] == 'A':
		s[i] = s[i + 1] = ''
		b = 1
	elif s[i] == 'A' and s[i + 1] == 'B':
		a = 1
		s[i] = s[i + 1] = ''
if a + b >= 2 or a + d >= 2 or a + c >= 2 or (b + d >= 2) or (b + c >= 2) or (c + d >= 2):
	print('YES')
else:
	print('NO')


import sys
from collections import Counter
sys.setrecursionlimit(1000000)

def I():
	return list(map(int, input().split()))
s = input()
n = len(s)
ab = []
ba = []
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	if s[i:i + 2] == 'BA':
		ba.append(i)
if ba and ab and (abs(ba[-1] - ab[0]) > 1 or abs(ab[-1] - ba[0]) > 1):
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	s = input()
	n = len(s)
	if s.count('A') <= 1 or s.count('B') <= 1:
		print('NO')
		continue
	aba = bab = ab = ba = 0
	p = 0
	while p < n:
		if p + 2 < n and s[p:p + 3] == 'ABA':
			aba += 1
			p += 3
		if p + 2 < n and s[p:p + 3] == 'BAB':
			bab += 1
			p += 3
		elif p + 1 < n and s[p:p + 2] == 'AB':
			ab += 1
			p += 2
		elif p + 1 < n and s[p:p + 2] == 'BA':
			ba += 1
			p += 2
		else:
			p += 1
	z = 0
	for v in [ab, ba, aba, bab]:
		if v == 0:
			z += 1
	print('YES' if z < 3 else 'NO')


s = input()
lenS = len(s)
i = 0
t = s[:]
if 'AB' in t:
	i = t.index('AB')
	t = t[:i] + 'CC' + t[i + 2:]
	if 'BA' in t:
		print('YES')
		return
t = s[:]
if 'BA' in t:
	i = t.index('BA')
	t = t[:i] + 'CC' + t[i + 2:]
	if 'AB' in t:
		print('YES')
		return
print('NO')


s = input()
x1 = s.find('AB')
x2 = s.find('BA', x1 + 2)
y1 = s.find('BA')
y2 = s.find('AB', y1 + 2)
if x1 != -1 and x2 != -1 or (y1 != -1 and y2 != -1):
	print('YES')
else:
	print('NO')


string = input()
lastone = ''
a = []
b = []
conse = 'a'
for i in range(len(string) - 1):
	if string[i] + string[i + 1] == 'AB':
		a.append(i)
	elif string[i] + string[i + 1] == 'BA':
		b.append(i)
if not a or not b:
	print('NO')
elif abs(max(a) - min(b)) >= 2 or abs(max(b) - min(a)) >= 2:
	print('YES')
else:
	print('NO')


s = input()
k1 = s.count('BA')
k2 = s.count('AB')
k3 = s.count('ABA')
k4 = s.count('BAB')
k5 = s.count('BABA')
k6 = s.count('ABAB')
if k1 == 0 or k2 == 0:
	print('NO')
elif (k3 == 1 or k4 == 1) and k1 == 1 and (k2 == 1):
	print('NO')
elif k5 == 1 and k1 == 2 and (k2 == 1) or (k6 == 1 and k2 == 2 and (k1 == 1)):
	print('NO')
else:
	print('YES')


c = str(input())
bacount = 0
abcount = 0
prev = c[0]
for i in range(1, len(c)):
	if prev == 'B' and c[i] == 'A' and (bacount < 1):
		bacount += 1
		if i + 1 < len(c):
			i += 1
	elif (prev == 'A' and c[i] == 'B') and abcount < 1:
		abcount += 1
		if i + 1 < len(c):
			i += 1
	prev = c[i]
if abcount > 0 and bacount > 0:
	print('YES')
else:
	abcount = 0
	bacount = 0
	c = c[::-1]
	for i in range(1, len(c)):
		if prev == 'B' and c[i] == 'A' and (bacount < 1):
			bacount += 1
			if i + 1 < len(c):
				i += 1
		elif (prev == 'A' and c[i] == 'B') and abcount < 1:
			abcount += 1
			if i + 1 < len(c):
				i += 1
		prev = c[i]
	if abcount > 0 and bacount > 0:
		print('YES')
	else:
		print('NO')


import sys
s = input()
t = 0
f = len(s) - 2
i = 0
while i < f:
	if s[i] == 'A' and s[i + 1] == 'B' and (s[i + 2] == 'A'):
		s = s[:i] + s[i + 3:]
		t += 1
	elif s[i] == 'B' and s[i + 1] == 'A' and (s[i + 2] == 'B'):
		s = s[:i] + s[i + 3:]
		t += 1
	f = len(s) - 2
	i += 1
if t >= 2:
	print('YES')
	sys.exit()
t2 = 0
t1 = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		t2 = 1
	elif s[i] == 'B' and s[i + 1] == 'A':
		t1 = 1
if t2 * t1 == 1:
	print('YES')
elif t == 1:
	if t1 == 1 or t2 == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
sc = s
y = len(s)
s = s.replace('AB', ';);', 1)
s = s.replace('BA', ';);', 1)
sc = sc.replace('BA', ';);', 1)
sc = sc.replace('AB', ';);', 1)
print('YES' if y + 2 in (len(s), len(sc)) else 'NO')


from collections import deque
from math import log, sqrt, ceil

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
s = si()
(f1, f2, f3) = (0, 0, 0)
n = len(s)
i = 1
while i < n - 1:
	if s[i - 1] == 'B' and s[i] == 'A' and (s[i + 1] == 'B'):
		f3 += 1
		i += 3
	elif s[i - 1] == 'A' and s[i] == 'B' and (s[i + 1] == 'A'):
		f3 += 1
		i += 3
	elif s[i - 1] == 'A' and s[i] == 'B':
		f1 += 1
		i += 2
	elif s[i - 1] == 'B' and s[i] == 'A':
		f2 += 1
		i += 2
	elif s[i] == 'A' and s[i + 1] == 'B':
		if i + 2 < n and s[i + 2] == 'A':
			f3 += 1
			i += 4
		else:
			f1 += 1
			i += 3
	elif s[i] == 'B' and s[i + 1] == 'A':
		if i + 2 < n and s[i + 2] == 'B':
			f3 += 1
			i += 4
		else:
			f2 += 1
			i += 3
	else:
		i += 1
if i == n - 1 and (s[i] == 'B' and s[i - 1] == 'A'):
	f1 += 1
if i == n - 1 and (s[i] == 'A' and s[i - 1] == 'B'):
	f2 += 1
if f3 >= 2:
	print('YES')
elif f1 and f2:
	print('YES')
elif f3 == 1 and f1 + f2 + f3 >= 2:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
(ab, ba, anyp) = (False, False, 0)
i = 0
while i < n:
	if i + 2 < n and (s[i:i + 3] == 'ABA' or s[i:i + 3] == 'BAB'):
		anyp += 1
		i += 3
	elif i + 1 < n and s[i:i + 2] == 'AB':
		ab = True
		i += 2
	elif i + 1 < n and s[i:i + 2] == 'BA':
		ba = True
		i += 2
	else:
		i += 1
print('YES' if anyp > 1 or (anyp > 0 and ab) or (anyp > 0 and ba) or (ab and ba) else 'NO')


def main():
	import sys
	s = sys.stdin.read().strip()
	n = len(s)
	result = False
	flag = False
	i = 0
	while i < n - 1:
		if not flag and s[i:i + 2] == 'AB':
			flag = True
			i += 2
		elif flag and s[i:i + 2] == 'BA':
			result = True
			break
		else:
			i += 1
	flag = False
	i = 0
	while i < n - 1:
		if not flag and s[i:i + 2] == 'BA':
			flag = True
			i += 2
		elif flag and s[i:i + 2] == 'AB':
			result = True
			break
		else:
			i += 1
	print('YES' if result else 'NO')
main()


s = input()
x = s.count('AB')
y = s.count('BA')
a1 = s.count('ABA')
a2 = s.count('BAB')
a3 = s.count('ABAB')
a4 = s.count('BABA')
f = 0
if a3 > 0:
	if x > 2 or y > 1:
		print('YES')
		exit()
elif a4 > 0:
	if y > 2 or x > 1:
		print('YES')
		exit()
elif a1 > 0 or a2 > 0:
	if x > 1 or y > 1:
		print('YES')
		exit()
elif x > 0 and y > 0:
	print('YES')
	exit()
print('NO')


import re
txt = input()
t = False
if re.search('AB', txt) != None:
	st = txt.replace('AB', 'X', 1)
	if re.search('BA', st) != None:
		t = True
if re.search('BA', txt) != None:
	st = txt.replace('BA', 'X', 1)
	if re.search('AB', st) != None:
		t = True
if t == False:
	print('NO')
else:
	print('YES')


def soln(s):
	founds1 = []
	founds2 = []
	j = float('-inf')
	for i in range(len(s) - 1):
		c1 = s[i]
		c2 = s[i + 1]
		if c1 == 'A' and c2 == 'B':
			founds1.append(i)
		elif c1 == 'B' and c2 == 'A':
			founds2.append(i)
	if len(founds1) == 0 or len(founds2) == 0:
		return 'NO'
	if len(founds1) >= 3 or len(founds2) >= 3:
		return 'YES'
	for i in founds1:
		for j in founds2:
			if abs(i - j) > 1:
				return 'YES'
	return 'NO'

def main():
	s = input()
	result = soln(s)
	print(result)
main()


s = input()
check1 = []
res = 'NO'
check2 = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		check1.append([i, i + 1])
	if s[i] == 'B' and s[i + 1] == 'A':
		check2.append([i, i + 1])
for a in check1:
	for b in check2:
		if abs(a[0] - b[1]) > 2 or abs(a[1] - b[0]) > 2:
			res = 'YES'
			break
print(res)


s = input()
a = 0
b = 0
c = 0
d = 0
j = 0
A = []
a2 = 0
b2 = 0
for i in s:
	A.append(i)
while j < len(A) - 1:
	if A[j] == 'A' and A[j + 1] == 'B' and (c != 1):
		c = 1
		a = j
		j = j + 1
	elif A[j] == 'B' and A[j + 1] == 'A' and (d != 1):
		d = 1
		b = j
		j = j + 1
	elif A[j] == 'A' and A[j + 1] == 'B' and (c == 1):
		a2 = j
	elif A[j] == 'B' and A[j + 1] == 'A' and (d == 1):
		b2 = j
	j = j + 1
if c == 1 and d == 1:
	print('YES')
elif c == 0 and d == 0:
	print('NO')
elif c == 1 and d == 0 and (a2 != 0):
	x = 0
	while x < a2 - 1:
		if A[x] == 'B' and A[x + 1] == 'A':
			d = 1
			break
		x = x + 1
	if c == 1 and d == 1:
		print('YES')
	else:
		print('NO')
elif c == 0 and d == 1 and (b2 != 0):
	y = 0
	while y < b2 - 1:
		if A[y] == 'A' and A[y + 1] == 'B':
			c = 1
			break
		y = y + 1
	if c == 1 and d == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = str(input())
flag = 0
for i in range(len(s) - 1):
	t = s[i] + s[i + 1]
	if t == 'AB':
		flag = 1 if 'BA' in s[i + 2:] else 0
	elif t == 'BA':
		flag = 1 if 'AB' in s[i + 2:] else 0
	if flag:
		break
print('YES' if flag else 'NO')


s = input().strip()

def check(s):
	ab = []
	ba = []
	for i in range(len(s)):
		if s[i:i + 2] == 'AB':
			ab.append(i)
		elif s[i:i + 2] == 'BA':
			ba.append(i)
	if len(ab) == 0 or len(ba) == 0:
		return False
	if ba[0] != ab[-1] - 1 and ba[0] != ab[-1] + 1 or (ab[0] != ba[-1] - 1 and ab[0] != ba[-1] + 1):
		return True
	return False
if check(s):
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
(flag1, flag2) = (0, 0)
k = 0
while k < n:
	if s[k:k + 2] == 'AB' and (not flag1):
		flag1 = True
		k += 1
	elif s[k:k + 2] == 'BA' and (not flag2):
		flag2 = True
		k += 1
	k += 1
	if flag1 and flag2:
		break
if not flag1 or not flag2:
	(flag1, flag2) = (0, 0)
	k = n - 1
	while k > 0:
		if s[k - 1:k + 1] == 'AB' and (not flag1):
			flag1 = True
			k -= 1
		elif s[k - 1:k + 1] == 'BA' and (not flag2):
			flag2 = True
			k -= 1
		k -= 1
		if flag1 and flag2:
			break
print(['NO', 'YES'][flag1 and flag2])


s = input()
iab = s.find('AB')
iba = s.find('BA')
if iab >= 0 and s.find('BA', iab + 2) >= 0:
	print('YES')
elif iba >= 0 and s.find('AB', iba + 2) >= 0:
	print('YES')
else:
	print('NO')


import sys
s = input()
ab = []
ba = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ab.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		ba.append(i)
c = 0
for i in ab:
	for x in ba:
		if abs(i - x) >= 2:
			print('YES')
			sys.exit()
print('NO')


s = input()
s1 = s
s2 = s
y = False
if 'AB' not in s and 'BA' not in s:
	print('NO')
else:
	if 'AB' in s:
		s1 = s1.replace('AB', '00', 1)
		if 'BA' in s1:
			y = True
	if 'BA' in s:
		s2 = s2.replace('BA', '00', 1)
		if 'AB' in s2:
			y = True
	if y:
		print('YES')
	else:
		print('NO')


s = 'a' + input() + 'a'
(cab, cba) = ([], [])
for i in range(1, len(s) - 1):
	if s[i:i + 2] == 'AB':
		cab.append(i)
		for j in cba:
			if j != i - 1 and j != i + 1:
				print('YES')
				exit()
	elif s[i:i + 2] == 'BA':
		cba.append(i)
		for j in cab:
			if j != i - 1 and j != i + 1:
				print('YES')
				exit()
print('NO')


s = input()
i = s.find('AB')
j = s.find('BA')
if i != -1 and s.find('BA', i + 2) != -1 or (j != -1 and s.find('AB', j + 2) != -1):
	print('YES')
else:
	print('NO')


s = input()
r = range(len(s))
ab_indexes = [i for i in r if s.startswith('AB', i)]
ba_indexes = [i for i in r if s.startswith('BA', i)]
breaked = False
if all([len(ab_indexes), len(ba_indexes)]):
	for i in ab_indexes:
		if breaked:
			break
		for j in ba_indexes:
			if j - 1 != i and j + 1 != i:
				breaked = True
				break
print('YES' if breaked else 'NO')


import sys
s = input()
AB = []
BA = []
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		for j in BA:
			if abs(j - i) != 1:
				print('YES')
				exit(0)
		AB.append(i)
	if s[i:i + 2] == 'BA':
		for j in AB:
			if abs(j - i) != 1:
				print('YES')
				exit(0)
		BA.append(i)
print('NO')


from collections import defaultdict
s = input().strip()
d = defaultdict(list)
for i in range(len(s) - 1):
	d[s[i:i + 2]].append(i)
k = 0
for i in d['AB']:
	for j in d['BA']:
		if abs(i - j) > 1:
			k = 1
			break
	if k == 1:
		break
print('YES' if k == 1 else 'NO')


def f(s):
	if len(s) < 4:
		return 'NO'
	ab = []
	ba = []
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			ab.append(i)
		elif s[i] == 'B' and s[i + 1] == 'A':
			ba.append(i)
	for i in range(len(ab)):
		for j in range(len(ba)):
			if abs(ab[i] - ba[j]) >= 2:
				return 'YES'
	return 'NO'
s = input()
print(f(s))


s = input()

def fn(s):
	t1 = len(s)
	for i in range(t1 - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			t2 = s[:i] + '1' + s[i + 2:]
			if 'BA' in t2:
				return 'YES'
	return 'NO'
print(fn(s))


s = input()
s1 = s.find('AB')
while s1 != -1:
	if s[:s1].find('BA') != -1 or s[s1 + 2:].find('BA') != -1:
		print('YES')
		exit()
	s1 = s.find('AB', s1 + 1)
print('NO')


import sys
input = []
input_index = 0

def next(type, number=None):

	def next():
		global input, input_index
		while input_index == len(input):
			if sys.stdin:
				input = sys.stdin.readline().split()
				input_index = 0
			else:
				raise Exception()
		input_index += 1
		return input[input_index - 1]
	if number is None:
		result = type(next())
	else:
		result = [type(next()) for _ in range(number)]
	return result
s = next(str)
_abs = []
_bas = []
for index in range(1, len(s)):
	if s[index - 1:index + 1] == 'AB':
		_abs.append(index)
	elif s[index - 1:index + 1] == 'BA':
		_bas.append(index)
if _abs and _bas and (abs(min(_abs) - max(_bas)) >= 2):
	print('YES')
elif _abs and _bas and (abs(max(_abs) - min(_bas)) >= 2):
	print('YES')
else:
	print('NO')


import math
s = input()
l = len(s)
(ab, ba) = ([], [])
for i in range(l - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ab.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		ba.append(i)
if len(ab) == 0 or len(ba) == 0:
	print('NO')
elif max(abs(ab[0] - ba[-1]), abs(ab[-1] - ba[0])) >= 2:
	print('YES')
else:
	print('NO')


s = input()
yes = False
try:
	ab = s.index('AB')
	ba = s.rindex('BA')
	if ba - ab > 1:
		yes = True
	ab = s.index('BA')
	ba = s.rindex('AB')
	if ba - ab > 1:
		yes = True
except ValueError:
	pass
print('YES' if yes else 'NO')


s = input()
r1 = s.find('AB')
r2 = s.rfind('BA')
r3 = s.find('BA')
r4 = s.rfind('AB')
if r1 == -1 and r4 == -1 or (r2 == -1 and r3 == -1):
	print('NO')
elif abs(r4 - r3) > 1 or abs(r1 - r2) > 1:
	print('YES')
else:
	print('NO')


s = input()
pos = -1
pos1 = -1
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		pos = i
		break
for i in range(len(s) - 1, 0, -1):
	if s[i] == 'A' and s[i - 1] == 'B':
		pos1 = i - 1
		break
pos2 = -1
pos3 = -1
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		pos2 = i
		break
for i in range(len(s) - 1, 0, -1):
	if s[i] == 'B' and s[i - 1] == 'A':
		pos3 = i - 1
		break
if pos == -1 or pos1 == -1:
	flag = False
elif abs(pos - pos1) > 1:
	flag = True
else:
	flag = False
if flag:
	print('YES')
elif pos2 == -1 or pos3 == -1:
	print('NO')
elif abs(pos2 - pos3) > 1:
	print('YES')
else:
	print('NO')


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	s = input()
	ls = len(s)
	i = 0
	ab = 0
	aba = 0
	bab = 0
	ba = 0
	while i + 1 < ls:
		f = 1
		if i + 2 < ls:
			if s[i] == 'A' and s[i + 1] == 'B' and (s[i + 2] == 'A'):
				f = 0
				aba += 1
				i += 3
			elif s[i] == 'B' and s[i + 1] == 'A' and (s[i + 2] == 'B'):
				f = 0
				bab += 1
				i += 3
		if f:
			if s[i] == 'A' and s[i + 1] == 'B':
				ab += 1
				i += 2
				f = 0
			elif s[i] == 'B' and s[i + 1] == 'A':
				ba += 1
				i += 1
				f = 0
		i += f
	ans = (ab > 0) + (aba > 0) + (ba > 0) + (bab > 0)
	if ans > 1:
		print('YES')
	else:
		print('NO')
main()


s = str(input())
n = len(s)
ab = []
ba = []
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	if s[i:i + 2] == 'BA':
		ba.append(i)
if len(ab) > 0 and len(ba) > 0:
	check1 = 0
	check2 = 0
	i = ab[0]
	j = ba[0]
	for x in ba:
		if x > i + 1:
			check1 = 1
			break
	for x in ab:
		if x > j + 1:
			check2 = 1
			break
	if check2 + check1 > 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


test = input()
test1 = test
i = j = None
try:
	i = test.index('AB')
	test = test.replace('AB', '__', 1)
	j = test.index('BA')
	print('YES')
except:
	try:
		i = test1.index('BA')
		test1 = test1.replace('BA', '__', 1)
		j = test1.index('AB')
		print('YES')
	except:
		print('NO')


string = input()
pos1 = []
pos2 = []
flag = 0
for i in range(0, len(string) - 1):
	if string[i] == 'A':
		if string[i + 1] == 'B':
			pos1.append(i)
	elif string[i] == 'B':
		if string[i + 1] == 'A':
			pos2.append(i)
if len(pos1) > len(pos2):
	for i in range(0, len(pos1)):
		if flag == 1:
			break
		for j in range(0, len(pos2)):
			if abs(pos1[i] - pos2[j]) > 1:
				print('YES')
				flag = 1
				break
else:
	for i in range(0, len(pos2)):
		if flag == 1:
			break
		for j in range(0, len(pos1)):
			if abs(pos2[i] - pos1[j]) > 1:
				print('YES')
				flag = 1
				break
if flag == 0:
	print('NO')


s = str(input())
ab = len(s)
ba = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ab = i
		break
for i in range(len(s) - 2, -1, -1):
	if s[i] == 'B' and s[i + 1] == 'A':
		ba = i
		break
if ba > ab + 1:
	print('YES')
	exit()
ab = 0
ba = len(s)
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		ba = i
		break
for i in range(len(s) - 2, -1, -1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ab = i
		break
if ab > ba + 1:
	print('YES')
	exit()
print('NO')


st = str(input())
i = 0
if 'AB' in st and 'BA' in st:
	if not 'ABA' in st:
		if not 'BAB' in st:
			print('YES')
		else:
			while i < len(st) - 5 and st[i:i + 3] != 'BAB':
				i += 1
			if 'AB' in st[i + 3:len(st) + 1] or 'BA' in st[i + 3:len(st) + 1]:
				print('YES')
			else:
				print('NO')
	else:
		while i < len(st) - 5 and st[i:i + 3] != 'ABA':
			i += 1
		if 'AB' in st[i + 3:len(st) + 1] or 'BA' in st[i + 3:len(st) + 1]:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


import sys
a = input()
ab = a.count('AB')
ba = a.count('BA')
aba = a.count('ABA')
bab = a.count('BAB')
if ab != 0 and ba != 0 and (ab + ba - aba - bab > 1):
	print('YES')
else:
	print('NO')


s = input()
a = []
b = []
if 'AB' in s and 'BA' in s:
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			a.append(i)
		if s[i] == 'B' and s[i + 1] == 'A':
			b.append(i)
	if abs(min(a) - max(b)) <= 1 and abs(min(b) - max(a)) <= 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj
import sys
import threading
from math import *
sys.setrecursionlimit(300000)
threading.stack_size(10 ** 8)
po = int(log(10 ** 18)) + 2
li = []
for i in range(po):
	li.append(3 ** i)
li = li[::-1]
s = sum(li)
for _ in range(1):
	a = input()
	n = len(a)
	(ind1, ind2) = (n + 4, -1)
	(f1, f2) = (0, 0)
	for i in range(n - 1):
		if a[i:i + 2] == 'AB':
			ind1 = i
			break
	for i in range(n - 1):
		if a[i:i + 2] == 'BA':
			ind2 = i
	if ind2 - ind1 >= 2:
		f1 = 1
	(ind1, ind2) = (n + 4, -1)
	for i in range(n - 1):
		if a[i:i + 2] == 'BA':
			ind1 = i
			break
	for i in range(n - 1):
		if a[i:i + 2] == 'AB':
			ind2 = i
	if ind2 - ind1 >= 2:
		f2 = 1
	if f1 or f2:
		print('YES')
	else:
		print('NO')


s = input()
try:
	ab1 = s.index('AB')
	ba1 = s[::-1].index('AB')
	ba1 = len(s) - 2 - ba1
	ab2 = s[::-1].index('BA')
	ab2 = len(s) - 2 - ab2
	ba2 = s.index('BA')
	if abs(ab1 - ba1) >= 2 or abs(ab2 - ba2) >= 2:
		print('YES')
	else:
		print('NO')
except ValueError:
	print('NO')


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
S = INS()
n = len(S)
(ans1, ans2) = (False, False)
i = 0
x = 1
while i < n - 2:
	if S[i:i + 2] == 'AB' and x:
		i += 2
		x = 0
	if not x and S[i:i + 2] == 'BA':
		ans1 = True
	i += 1
i = 0
x = 1
while i < n - 2:
	if S[i:i + 2] == 'BA' and x:
		i += 2
		x = 0
	if not x and S[i:i + 2] == 'AB':
		ans2 = True
	i += 1
if ans1 or ans2:
	OPS('YES')
else:
	OPS('NO')


s = input()
if 'AB' and 'BA' in s:
	i = 0
	splits = []
	while i < len(s) - 1:
		if s[i] == 'A' and s[i + 1] == 'B':
			x = s[:i]
			y = s[i + 2:]
			if 'BA' in x or 'BA' in y:
				print('YES')
				break
		i += 1
	else:
		print('NO')
else:
	print('NO')


s = input()
flag = 0
if 'AB' in s:
	res = s.find('AB')
	copy = s[res + 2:]
	if 'BA' in copy:
		flag = 1
	elif flag != 1:
		flag = 0
if 'BA' in s:
	res = s.find('BA')
	copy = s[res + 2:]
	if 'AB' in copy:
		flag = 1
	elif flag != 1:
		flag = 0
else:
	flag = 0
if flag == 1:
	print('YES')
else:
	print('NO')


s = input()
i = s.find('AB')
if i != -1:
	if s[i + 2:].find('BA') != -1:
		print('YES')
		exit(0)
i = s.find('BA')
if i != -1:
	if s[i + 2:].find('AB') != -1:
		print('YES')
		exit(0)
print('NO')


s = input()
s1 = 'AB'
s2 = 'BA'
a1 = s.count(s1)
a2 = s.count(s2)
if a1 == 0 or a2 == 0:
	print('NO')
elif a2 == 1 and a1 > 1:
	k1 = s.find(s2)
	k2_1 = s.find(s1)
	k2_2 = s.find(s1, k2_1 + 1, len(s))
	k2_3 = s.find(s1, k2_2 + 1, len(s))
	if k1 != k2_1 + 1 and k1 != k2_1 - 1:
		print('YES')
	elif k1 != k2_2 + 1 and k1 != k2_2 - 1:
		print('YES')
	elif k1 != k2_3 + 1 and k1 != k2_3 - 1 and (k2_3 != -1):
		print('YES')
	else:
		print('NO')
elif a1 == 1 and a2 > 1:
	k1 = s.find(s1)
	k2_1 = s.find(s2)
	k2_2 = s.find(s2, k2_1 + 1, len(s))
	k2_3 = s.find(s2, k2_2 + 1, len(s))
	if k1 != k2_1 + 1 and k1 != k2_1 - 1:
		print('YES')
	elif k1 != k2_2 + 1 and k1 != k2_2 - 1:
		print('YES')
	elif k1 != k2_3 + 1 and k1 != k2_3 - 1 and (k2_3 != -1):
		print('YES')
	else:
		print('NO')
elif a1 == 1 and a2 == 1:
	k1 = s.find(s1)
	k2 = s.find(s2)
	if k1 != k2 + 1 and k1 != k2 - 1 and (k1 != -1) and (k2 != -1):
		print('YES')
	else:
		print('NO')
else:
	print('YES')


S = input()
listA = []
listB = []
for i in range(0, len(S) - 1):
	if S[i] == 'A' and S[i + 1] == 'B':
		listA.append(i)
	if S[i] == 'B' and S[i + 1] == 'A':
		listB.append(i)
nA = len(listA)
nB = len(listB)
if nA >= 2 and nB >= 2:
	print('YES')
elif nA == 0 or nB == 0:
	print('NO')
else:
	resultA = 0
	resultB = 0
	for i in range(0, len(listA)):
		tmp = 0
		for j in range(0, len(listB)):
			if listA[i] + 1 == listB[j] or listA[i] == listB[j] + 1:
				tmp += 1
		if tmp == 0:
			resultA += 1
	for i in range(0, len(listB)):
		tmp = 0
		for j in range(0, len(listA)):
			if listB[i] + 1 == listA[j] or listB[i] == listA[j] + 1:
				tmp += 1
		if tmp == 0:
			resultB += 1
	if resultA > 0 or resultB > 0:
		print('YES')
	else:
		print('NO')


import bisect
import collections
import math
s = input()

def prefix(src):
	pi = [0] * len(src)
	for i in range(1, len(src)):
		k = pi[i - 1]
		while k > 0 and src[k] != src[i]:
			k = pi[k - 1]
		if src[k] == src[i]:
			k += 1
		pi[i] = k
	return pi

def KMP(t):
	pi_1 = prefix('AB#' + t)
	pi_2 = prefix('BA#' + t)
	return ([i - 4 for (i, x) in enumerate(pi_1) if x == 2 and i > 2], [i - 4 for (i, x) in enumerate(pi_2) if x == 2 and i > 2])
(left, right) = KMP(s)
if not left or not right:
	print('NO')
elif abs(right[-1] - left[0]) >= 2 or abs(right[0] - left[-1]) >= 2:
	print('YES')
else:
	print('NO')


s = input()
if len(s) > 3 and 'AB' in s and ('BA' in s[s.index('AB') + 2:]):
	print('YES')
elif len(s) > 3 and 'BA' in s and ('AB' in s[s.index('BA') + 2:]):
	print('YES')
else:
	print('NO')


import sys
s = input()
t1 = 0
t2 = 0
k = len(s)
l = len(s)
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB' and t1 == 0:
		t1 = 1
		k = i + 2
	if s[i:i + 2] == 'BA' and t2 == 0:
		l = i + 2
		t2 = 1
	if t1 == 1 and t2 == 1:
		break
for j in range(k, len(s) - 1):
	if s[j:j + 2] == 'BA':
		print('YES')
		sys.exit()
for j in range(l, len(s) - 1):
	if s[j:j + 2] == 'AB':
		print('YES')
		sys.exit()
print('NO')


n = input()
l = 0
c = 0
i = 0
d = 0
d1 = 0
while i < len(n) - 1:
	if n[i] + n[i + 1] == 'AB':
		c += 1
		d = i
	if n[i] + n[i + 1] == 'BA':
		l += 1
		d1 = i
	i += 1
if l > 1 and c > 1 or (l > 1 and c > 0 and (d1 - d != 1) and (d1 - d != -1)) or (c > 1 and l > 0 and (d1 - d != 1) and (d1 - d != -1)) or (l == 1 and c == 1 and (d1 - d != 1) and (d1 - d != -1)):
	print('YES')
else:
	print('NO')


s = input()
flag = False
right_ab = [0 for i in range(len(s))]
right_ba = [0 for i in range(len(s))]
count = 0
c = 0
for i in range(len(s) - 2, -1, -1):
	if s[i:i + 2] == 'AB':
		count += 1
	right_ab[i] = count
	if s[i:i + 2] == 'BA':
		c += 1
	right_ba[i] = c
flag = False
for i in range(2, len(s)):
	if s[i - 2:i] == 'AB' and right_ba[i] > 0 or (s[i - 2:i] == 'BA' and right_ab[i] > 0):
		print('YES')
		flag = True
		break
if not flag:
	print('NO')


def are_substring(s):
	i = 0
	ab = False
	ba = False
	while i < len(s) and s[i:i + 2] != 'BA':
		i += 1
	if i < len(s) and 'AB' in s[i + 2:]:
		ab = True
	j = 0
	while j < len(s) and s[j:j + 2] != 'AB':
		j += 1
	if j < len(s) and 'BA' in s[j + 2:]:
		ba = True
	if ab or ba:
		return 'YES'
	else:
		return 'NO'
s = input()
if len(s) <= 3:
	print('NO')
else:
	print(are_substring(s))


s = input()
i1 = s.find('AB')
i2 = s.find('BA', i1 + 2)
i3 = s.find('BA')
i4 = s.find('AB', i3 + 2)
if i1 != -1 and i2 != -1:
	print('YES')
elif i3 != -1 and i4 != -1:
	print('YES')
else:
	print('NO')


s = input()
a = s.find('AB')
ar = s.rfind('AB')
b = s.find('BA')
br = s.rfind('BA')
if a >= 0 and br >= 0 and (abs(br - a) != 1) or (ar >= 0 and b >= 0 and (abs(ar - b) != 1)):
	print('YES')
else:
	print('NO')


s = input()
p = list(s)
flag = False
for i in range(len(s) - 3):
	if s[i] == 'A' and s[i + 1] == 'B':
		if 'BA' in s[i + 2:]:
			print('YES')
			flag = True
	if flag == True:
		break
	if s[i] == 'B' and s[i + 1] == 'A':
		if 'AB' in s[i + 2:]:
			print('YES')
			flag = True
	if flag == True:
		break
if flag == False:
	print('NO')


s = list(input(''))
n = len(s)
indA = []
indB = []
flag = 0
for i in range(n):
	if s[i] == 'A':
		if i + 1 >= n:
			continue
		elif s[i + 1] == 'B':
			indA.append(i)
	elif s[i] == 'B':
		if i + 1 >= n:
			continue
		elif s[i + 1] == 'A':
			indB.append(i)
if len(indA) == 0 or len(indB) == 0:
	print('NO')
else:
	for i in range(len(indA)):
		for j in range(len(indB)):
			if abs(indA[i] - indB[j]) > 1:
				flag = 1
				break
	if flag:
		print('YES')
	else:
		print('NO')


str1 = input()
if str1.count('AB') == 0 or str1.count('BA') == 0:
	print('NO')
else:
	x = str1.find('AB')
	y = str1.rfind('BA')
	x1 = str1.find('BA')
	y1 = str1.rfind('AB')
	if abs(x - y) >= 2 or abs(x1 - y1) >= 2:
		print('YES')
	else:
		print('NO')


s = input()
a = []
b = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		b.append(i)
if a and b and (len(a) + len(b) >= 4):
	print('YES')
elif a and b and (len(a) + len(b) == 3):
	if 'ABAB' in s or 'BABA' in s:
		print('NO')
	else:
		print('YES')
elif a and b and (len(a) + len(b) == 2):
	if 'ABA' in s or 'BAB' in s:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


s = input()
if 'BA' not in s or 'AB' not in s:
	print('NO')
elif 'BA' in s and 'AB' in s and (s.count('A') >= 2) and (s.count('B') >= 2):
	if 'BAB' not in s and 'ABA' not in s:
		print('YES')
	elif 'ABA' in s and (s.count('BA') >= 2 or s.count('AB') >= 2) and (len(s) >= 4) and (s.count('A') > 2 or s.count('B') > 2):
		print('YES')
	elif 'BAB' in s and (s.count('AB') >= 2 or s.count('BA') >= 2) and (len(s) >= 4) and (s.count('A') > 2 or s.count('B') > 2):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


arr = input()
p = arr.find('AB')
c = arr.find('BA')
if p >= 0 and arr.find('BA', p + 2) > 0:
	print('YES')
elif c >= 0 and arr.find('AB', c + 2) > 0:
	print('YES')
else:
	print('NO')


l = input()
AB = 0
BA = 0
for i in range(0, len(l) - 1):
	if l[i:i + 2] == 'AB':
		AB += 1
	if l[i:i + 2] == 'BA':
		BA += 1
if AB == 0 or BA == 0:
	print('NO')
elif AB == 1 and BA == 1:
	if l.find('ABA') == -1 and l.find('BAB') == -1:
		print('YES')
	else:
		print('NO')
elif AB == 1 and BA == 2:
	if l.find('BABA') == -1:
		print('YES')
	else:
		print('NO')
elif BA == 1 and AB == 2:
	if l.find('ABAB') == -1:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


a = input()
n = len(a)
k = 0
l = a.find('AB')
if l >= 0:
	if l + 2 == n:
		k = 0
	else:
		b = a[l + 2:]
		if b.find('BA') >= 0:
			k = k + 1
		else:
			k = 0
l = a.find('BA')
if k == 0 and l >= 0:
	if l + 2 == n:
		k = 0
	else:
		b = a[l + 2:]
		if b.find('AB') >= 0:
			k = k + 1
		else:
			k = 0
if k == 1:
	print('YES')
else:
	print('NO')


t = input()
if 'BA' not in t:
	print('NO')
elif 'AB' not in t:
	print('NO')
else:
	u = []
	v = []
	for k in range(len(t) - 1):
		if t[k] == 'A' and t[k + 1] == 'B':
			u.append(k)
		elif t[k] == 'B' and t[k + 1] == 'A':
			v.append(k)
	if abs(min(u) - max(v)) > 1 or abs(min(v) - max(u)) > 1:
		print('YES')
	else:
		print('NO')


s = input()
flag1 = False
flag2 = False
s2 = ''
i = 0
while i < len(s):
	if i + 1 < len(s) and s[i] == 'A' and (s[i + 1] == 'B') and (flag1 == False):
		flag1 = True
		i += 1
		s2 = s2 + '..'
	else:
		s2 = s2 + s[i]
	i += 1
if flag1:
	if 'BA' in s2:
		flag2 = True
if flag1 and flag2:
	print('YES')
else:
	i = 0
	s2 = ''
	flag1 = False
	flag2 = False
	while i < len(s):
		if i + 1 < len(s) and s[i] == 'B' and (s[i + 1] == 'A') and (flag1 == False):
			flag1 = True
			i += 1
			s2 = s2 + '..'
		else:
			s2 = s2 + s[i]
		i += 1
	if flag1:
		if 'AB' in s2:
			flag2 = True
	if flag1 and flag2:
		print('YES')
	else:
		print('NO')


x = input()
i = x.find('AB')
j = x.find('BA')
if i >= 0 and x.find('BA', i + 2) + 1 or (j >= 0 and x.find('AB', j + 2) + 1):
	print('YES')
else:
	print('NO')


import re

def subs(s):
	a = list()
	b = list()
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			a.append(i)
		elif s[i] == 'B' and s[i + 1] == 'A':
			b.append(i)
	for x in range(len(a)):
		for y in range(len(b)):
			if abs(a[x] - b[y]) > 1:
				return 'YES'
	return 'NO'
t = input()
print(subs(t))


a = str(input())
r = 'NO'
n = len(a)
x = a.find('AB')
b = a[x + 2:n]
y = b.find('BA')
if x >= 0 and y >= 0:
	r = 'YES'
x = a.find('BA')
b = a[x + 2:n]
y = b.find('AB')
if x >= 0 and y >= 0:
	r = 'YES'
print(r)


word = input()
abLoc_ab = word.find('AB')
slicedWord = word[abLoc_ab + 2:len(word)]
baLoc_ab = slicedWord.rfind('BA')
baLoc_ba = word.find('BA')
slicedWord = word[baLoc_ba + 2:len(word)]
abLoc_ba = slicedWord.find('AB')
if abLoc_ab >= 0 and baLoc_ab >= 0 or (abLoc_ba >= 0 and baLoc_ba >= 0):
	print('YES')
else:
	print('NO')


s = input()
i = 0
ans = False
if min(s.count('AB'), s.count('BA')) >= 1 and s.count('AB') + s.count('BA') - int('BAB' in s) - int('ABA' in s) >= 2:
	print('YES')
else:
	print('NO')


line = str(input())
size = len(line)
list_ab = list()
list_ba = list()
for i in range(size - 1):
	if line[i:i + 2] == 'AB':
		list_ab.append(i)
	if line[i:i + 2] == 'BA':
		list_ba.append(i)
flag = False
for i in list_ab:
	for j in list_ba:
		if abs(i - j) > 1:
			flag = True
			break
	if flag:
		break
if flag:
	print('YES')
else:
	print('NO')


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt, ceil
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	n = insr()
	ab = []
	ba = []
	for (i, c) in enumerate(n):
		if i > 0:
			if c == 'B' and n[i - 1] == 'A':
				ba.append(i - 1)
			if c == 'A' and n[i - 1] == 'B':
				ab.append(i - 1)
	if ba and ab and (abs(ba[0] - ab[-1]) >= 2 or abs(ba[-1] - ab[0]) >= 2):
		print('YES')
	else:
		print('NO')
main()


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	s = input()
	n = len(s)
	l = 0
	r = 1
	(i, j) = (-1, -1)
	(i1, j1) = (-1, -1)
	while r < n:
		if s[l:r + 1] == 'AB':
			if i == -1:
				i = l
			i1 = l
		l += 1
		r += 1
	l = 0
	r = 1
	while r < n:
		if s[l:r + 1] == 'BA':
			if j1 == -1:
				j1 = l
			j = l
		l += 1
		r += 1
	if -1 < i < j and i + 1 != j:
		print('YES')
	elif -1 < j1 < i1 and j1 + 1 != i1:
		print('YES')
	else:
		print('NO')
t = 1
for _ in range(t):
	main()


line1 = str(input())
abIndexes = []
baIndexes = []
for i in range(0, len(line1) - 1):
	if line1[i] == 'A' and line1[i + 1] == 'B':
		abIndexes.append(i)
for i in range(0, len(line1) - 1):
	if line1[i] == 'B' and line1[i + 1] == 'A':
		baIndexes.append(i)
distinct = False
for i in abIndexes:
	for j in baIndexes:
		if j != i + 1 and j != i - 1:
			distinct = True
			break
			break
if distinct:
	print('YES')
else:
	print('NO')


s = input()
if s.find('AB') >= 0 and s.find('BA') >= 0 and (abs(s.find('AB') - s.rfind('BA')) > 1 or abs(s.find('BA') - s.rfind('AB')) > 1):
	print('YES')
else:
	print('NO')


s = input()
l = []
count = 0
count1 = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B' and (count == 0):
		if i not in l and i + 1 not in l:
			count = count + 1
			l.append(i)
			l.append(i + 1)
	if s[i] == 'B' and s[i + 1] == 'A' and (count1 == 0):
		if i not in l and i + 1 not in l:
			count1 = count1 + 1
			l.append(i)
			l.append(i + 1)
if count >= 1 and count1 >= 1:
	print('YES')
else:
	l = []
	count = 0
	count1 = 0
	s = s[::-1]
	for i in range(len(s) - 1):
		if s[i] == 'B' and s[i + 1] == 'A' and (count1 == 0):
			if i not in l and i + 1 not in l:
				count1 = count1 + 1
				l.append(i)
				l.append(i + 1)
		if s[i] == 'A' and s[i + 1] == 'B' and (count == 0):
			if i not in l and i + 1 not in l:
				count = count + 1
				l.append(i)
				l.append(i + 1)
	if count >= 1 and count1 >= 1:
		print('YES')
	else:
		print('NO')


import sys
s = input()
a1 = s.find('AB')
a2 = s.rfind('AB')
b1 = s.find('BA')
b2 = s.rfind('BA')
if a1 != -1 and a1 + 1 < b2:
	print('YES')
	sys.exit(0)
if b1 != -1 and b1 + 1 < a2:
	print('YES')
	sys.exit(0)
print('NO')


mainString = str(input())
ABfoundIndex = mainString.find('AB')
BAfounIndex = mainString.find('BA')
if ABfoundIndex != -1 and mainString.find('BA', ABfoundIndex + 2) != -1 or (BAfounIndex != -1 and mainString.find('AB', BAfounIndex + 2) != -1):
	print('YES')
else:
	print('NO')


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)
s = si()
if s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB') >= 2 and s.count('AB') >= 1 and (s.count('BA') >= 1):
	print('YES')
else:
	print('NO')


s = input()
if 'AB' not in s or 'BA' not in s:
	print('NO')
else:
	ab = s.index('AB')
	bar = s.rindex('BA')
	abr = s.rindex('AB')
	ba = s.index('BA')
	if bar - ab >= 2 or abr - ba >= 2:
		print('YES')
	else:
		print('NO')


s = input()
print('YNEOS'[not ('AB' in s and 'BA' in s.replace('AB', 'X', 1)) and (not ('BA' in s and 'AB' in s.replace('BA', 'X', 1)))::2])


s = input()
L = len(s)
if L > 3:
	if 'ABABA' in s or 'BABAB' in s:
		print('YES')
	elif 'ABA' in s:
		b = s.index('ABA')
		s = s[0:b] + s[b + 3:]
		if 'AB' in s or 'BA' in s:
			print('YES')
		else:
			print('NO')
	elif 'BAB' in s:
		b = s.index('BAB')
		s = s[0:b] + s[b + 3:]
		if 'AB' in s or 'BA' in s:
			print('YES')
		else:
			print('NO')
	elif 'AB' in s:
		a = s.index('AB')
		s = s[0:a] + s[a + 2:]
		if 'BA' in s:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


a = input()
x = 'AB'
y = 'BA'
first = -1
last = -1
second = -1
second_last = -1
for i in range(0, len(a) - 1):
	if a[i:i + 2] == x and first == -1:
		first = i
	if a[i:i + 2] == y and second == -1:
		second = i
for j in range(len(a), 0, -1):
	if a[j - 1:j + 1] == y and last == -1:
		last = j - 1
	if a[j - 1:j + 1] == x and second_last == -1:
		second_last = j - 1
if first == -1 and second_last == -1 or (last == -1 and second == -1):
	print('NO')
elif first != -1 and last != -1 and (abs(first - last) > 1):
	print('YES')
elif first != -1 and second != -1 and (abs(first - second) > 1):
	print('YES')
elif second_last != -1 and last != -1 and (abs(second_last - last) > 1):
	print('YES')
elif second_last != -1 and second != -1 and (abs(second_last - second) > 1):
	print('YES')
else:
	print('NO')


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
import math

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def divs(n, start=2):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors
import sys
inf = float('inf')
mod = 1000000007

def array():
	return list(map(int, sys.stdin.readline().split()))

def intt():
	return map(int, sys.stdin.readline().split())
from bisect import bisect_left
import sys
s = input()
if s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB') >= 2 and (s.count('AB') > 0 and s.count('BA') > 0):
	print('YES')
else:
	print('NO')


import re
s = input()
iter = re.finditer('AB', s)
ind = [m.start(0) for m in iter]
iter2 = re.finditer('BA', s)
ind2 = [m.start(0) for m in iter2]
if ind == [] or ind2 == []:
	print('NO')
elif abs(ind[0] - ind2[len(ind2) - 1]) >= 2 or abs(ind2[0] - ind[len(ind) - 1]) >= 2:
	print('YES')
else:
	print('NO')


S = input()
if S.count('AB') == 0 or S.count('BA') == 0:
	print('NO')
elif S[S.index('AB') + 2:].count('BA') > 0 or S[S.index('BA') + 2:].count('AB') > 0:
	print('YES')
else:
	print('NO')


ss = input()
flag = flag2 = 0
s = ss
if 'AB' in s:
	s = s.replace('AB', 'X', 1)
	flag = 1
if 'BA' in s:
	s = s.replace('BA', 'X', 1)
	flag2 = 1
if flag == 0 or flag2 == 0:
	flag = flag2 = 0
	s = ss
	if 'BA' in s:
		s = s.replace('BA', 'X', 1)
		flag2 = 1
	if 'AB' in s:
		s = s.replace('AB', 'X', 1)
		flag = 1
if flag == 1 and flag2 == 1:
	print('YES')
else:
	print('NO')


stringInput = input()
a = stringInput.find('AB')
b = stringInput.rfind('BA')
c = stringInput.rfind('AB')
d = stringInput.find('BA')
if a != b and a + 1 != b and (b + 1 != a) and (a != -1) and (b != -1) or (c != d and c + 1 != d and (d + 1 != c) and (c != -1) and (d != -1)):
	print('YES')
else:
	print('NO')


def noverlap(s):
	ab = s.count('AB')
	ba = s.count('BA')
	aba = s.count('ABA')
	bab = s.count('BAB')
	abab = s.count('ABAB')
	baba = s.count('BABA')
	if ab > 1 and ba > 1 or (ab == 1 and ba == 2 and (baba == 0)) or (ab == 2 and ba == 1 and (abab == 0)) or (ab == 1 and ba > 2) or (ab > 2 and ba == 1) or (ab == 1 and ba == 1 and (aba + bab == 0)):
		return 'YES'
	return 'NO'
print(noverlap(input()))


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
s = si()
n = len(s)
bl = [0] * n
(x, y) = (0, 0)
for i in range(1, n):
	if s[i - 1] + s[i] == 'AB':
		bl[i] = 1
		bl[i - 1] = 1
		x = 1
		break
for i in range(1, n):
	if s[i - 1] + s[i] == 'BA' and bl[i] + bl[i - 1] == 0:
		y = 1
		break
if x and y:
	print('YES')
else:
	bl = [0] * n
	(x, y) = (0, 0)
	for i in range(1, n):
		if s[i - 1] + s[i] == 'BA':
			bl[i] = 1
			bl[i - 1] = 1
			x = 1
			break
	for i in range(1, n):
		if s[i - 1] + s[i] == 'AB' and bl[i] + bl[i - 1] == 0:
			y = 1
			break
	if x and y:
		print('YES')
	else:
		print('NO')


s = input()
ai = 0
bi = 0
(flag1, flag2) = (0, 0)
if 'AB' in s:
	ai = s.index('AB')
else:
	flag1 = 1
if 'BA' in s:
	bi = s.index('BA')
else:
	flag2 = 1
if (ai < s.find('BA', ai + 2) or bi < s.find('AB', bi + 2)) and flag1 == 0 and (flag2 == 0):
	print('YES')
else:
	print('NO')


s = input()
a = list(s)
pos1 = []
pos2 = []
for i in range(len(s) - 1):
	if s[i] == 'A' and a[i + 1] == 'B':
		pos1.append([i, i + 1])
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		pos2.append([i, i + 1])
if len(pos1) == 0 or len(pos2) == 0:
	print('NO')
elif len(pos1) == 0:
	print('NO')
elif len(pos2) == 0:
	print('NO')
else:
	i = 0
	m = len(pos2) - 1
	ans = False
	while i < len(pos1):
		j = m
		while j >= 0:
			if pos1[i][0] != pos2[j][0] and pos1[i][0] != pos2[j][1] and (pos1[i][1] != pos2[j][0]) and (pos1[i][1] != pos2[j][1]):
				ans = True
				break
			j = j - 1
			if ans:
				break
		if ans:
			break
		i += 1
	if ans == True:
		print('YES')
	else:
		print('NO')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
s = '#' + input()
n = len(s)
s += '#'
ans = 'NO'
(ab, ba) = ([], [])
for i in range(2, n):
	if s[i - 1] + s[i] == 'AB':
		ab.append(i - 1)
	if s[i - 1] + s[i] == 'BA':
		ba.append(i - 1)
for i in ab:
	for j in ba:
		if i + 1 != j and i - 1 != j:
			ans = 'YES'
			break
	if ans == 'YES':
		break
print(ans)


s = input()
a = []
b = []
if 'AB' in s and 'BA' in s:
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			a.append(i)
		if s[i] == 'B' and s[i + 1] == 'A':
			b.append(i)
	a = sorted(a, reverse=True)
	b = sorted(b)
	if abs(a[0] - b[0]) > 1 or abs(a[-1] - b[-1]) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


string = input()
new_str = string
ABA = string.count('ABA')
BAB = string.count('BAB')
aba = False
if ABA > 1 or BAB > 1:
	print('YES')
	exit()
if ABA == 1:
	new_str = string.replace('ABA', '')
	if 'BA' in new_str or 'AB' in new_str:
		aba = True
if BAB == 1 or aba:
	new_str = string.replace('BAB', '')
	if 'AB' in new_str or 'BA' in new_str or aba:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
if 'AB' in new_str and 'BA' in new_str:
	print('YES')
else:
	print('NO')


def sol():
	s = input().strip()
	ab = s.find('AB')
	ba = s.find('BA')
	if ab < 0 or ba < 0:
		return False
	if abs(ba - ab) < 2:
		first = min(ab, ba)
		second = max(ab, ba)
		toFind = 'BA' if ab == first else 'AB'
		if s.find(toFind, first + 2) > 0:
			return True
		toFind = 'AB' if toFind == 'BA' else 'BA'
		if s.find(toFind, second + 2) > 0:
			return True
		return False
	return True

def main():
	if sol():
		print('YES')
	else:
		print('NO')
main()


string = input()
if 'AB' in string and 'BA' in string:
	i = string.index('AB')
	aux = string[i + 2:len(string)]
	if 'BA' in aux:
		print('YES')
	else:
		i = string.index('BA')
		aux = string[i + 2:len(string)]
		if 'AB' in aux:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


s = list(input())
s.append('0')
s.append('0')
(c1, c2, c3, c4, i) = (0, 0, 0, 0, 0)
while i < len(s):
	if s[i] == 'A' and s[i + 1] == 'B' and (s[i + 2] == 'A'):
		c1 += 1
		i += 2
	elif s[i] == 'B' and s[i + 1] == 'A' and (s[i + 2] == 'B'):
		c2 += 1
		i += 2
	elif s[i] == 'B' and s[i + 1] == 'A':
		c3 += 1
		i += 1
	elif s[i] == 'A' and s[i + 1] == 'B':
		c4 += 1
		i += 1
	i += 1
if c1 == 0 and c2 == 0 and (c3 == 0) and (c4 == 0) or (c1 == 1 and c2 == 0 and (c3 == 0) and (c4 == 0)) or (c1 == 0 and c2 == 1 and (c3 == 0) and (c4 == 0)) or (c1 == 0 and c2 == 0 and (c3 >= 1) and (c4 == 0)) or (c1 == 0 and c2 == 0 and (c3 == 0) and (c4 >= 1)):
	print('NO')
else:
	print('YES')


s = input()
X = []
a = 0
l = len(s)
while 1:
	p = s[a:l].find('AB')
	if p == -1:
		break
	X.append(p + a)
	a = a + p + 2
Y = []
a = 0
l = len(s)
while 1:
	p = s[a:l].find('BA')
	if p == -1:
		break
	Y.append(p + a)
	a = a + p + 2
f = 0
for i in X:
	if f == 1:
		break
	for j in Y:
		if i - j >= 2 or j - i >= 2:
			print('YES')
			f = 1
			break
else:
	if f == 0:
		print('NO')


s = input()
m1 = s.count('ABA')
m2 = s.count('BAB')
n1 = s.count('AB')
n2 = s.count('BA')
if n1 > 0 and n2 > 0:
	if n1 + n2 - m1 - m2 > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
x = ''
y = ''
c = 0
if s.find('AB') >= 0:
	x = s[s.find('AB') + 2:]
	if x.find('BA') >= 0:
		c += 1
if s.find('BA') >= 0:
	y = s[s.find('BA') + 2:]
	if y.find('AB') >= 0:
		c += 1
if c > 0:
	print('YES')
else:
	print('NO')


import heapq as hp
import collections
import bisect
import math
import re

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def range_n():
	return range(int(input()))

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def getint():
	return int(input())

def foo(s, i, patt):
	for i in range(i, len(s) - 1):
		if s[i:i + 2] == patt:
			return True
	return False

def main():
	s = input()
	ans = 'NO'
	fab = fba = True
	for i in range(len(s) - 1):
		x = s[i:i + 2]
		if fab and x == 'AB':
			fab = False
			if foo(s, i + 2, 'BA'):
				ans = 'YES'
				break
		elif fba and x == 'BA':
			fba = False
			if foo(s, i + 2, 'AB'):
				ans = 'YES'
				break
	print(ans)
main()


s = input()
k1 = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		k1.append(i)
kq = 'NO'
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		for item in k1:
			if item == i - 1 or item == i + 1:
				continue
			kq = 'YES'
			break
print(kq)


import sys
sys.setrecursionlimit(10 ** 5)
readline = sys.stdin.readline

def process():
	s = readline().strip()
	a = s.find('AB')
	if a != -1 and s[a + 2:].find('BA') != -1:
		print('YES')
		return
	a = s.find('BA')
	if a != -1 and s[a + 2:].find('AB') != -1:
		print('YES')
		return
	print('NO')
process()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 99999999999999999999999999999999

def outIn(x):
	print(x, flush=True)
	return input()

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		s = list(rs())
		dab = {}
		dba = {}
		for i in range(len(s) - 1):
			if s[i] + s[i + 1] == 'AB':
				dab[i] = 1
			if s[i] + s[i + 1] == 'BA':
				dba[i] = 1
		flag = 1
		ans = 'NO'
		for i in dab:
			for j in dba:
				if abs(i - j) > 1:
					ans = 'YES'
					flag = 0
					break
			if flag == 0:
				break
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from math import *
from copy import *
from heapq import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(l):
	n = len(l)
	i = l.find('AB')
	j = l.rfind('BA')
	k1 = l.rfind('AB')
	k2 = l.find('BA')
	f = 1
	if i == -1 or j == -1:
		f = 0
	elif abs(j - i) == 1 and abs(k1 - k2) == 1:
		f = 0
	return 'YES' if f else 'NO'
l = input()
ans = solve(l)
print(ans)


import sys
from functools import lru_cache
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
s = data()
(a, b) = ([], [])
i = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a.append((i, i + 1))
	if s[i] == 'B' and s[i + 1] == 'A':
		b.append((i, i + 1))
if len(a) >= 2 and len(b) >= 2:
	out('YES')
	exit()
if len(a) == 0 or len(b) == 0:
	out('NO')
	exit()
if len(a) == 1:
	cnt = 0
	for i in b:
		if a[0][0] in i or a[0][1] in i:
			cnt += 1
	if cnt == len(b):
		out('NO')
		exit()
if len(b) == 1:
	cnt = 0
	for i in a:
		if b[0][0] in i or b[0][1] in i:
			cnt += 1
	if cnt == len(a):
		out('NO')
		exit()
out('YES')


s = input()
a = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a.append((i, i + 1))
ans = False
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		for (x, y) in a:
			if x not in [i, i + 1] and y not in [i, i + 1]:
				ans = True
				break
if ans:
	print('YES')
else:
	print('NO')


import sys
import re
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	s = input().replace('\n', '')
	(ab, ba) = (s.find('AB'), s.find('BA'))
	print('YES' if ab + 1 and s.find('BA', ab + 2) + 1 or (ba + 1 and s.find('AB', ba + 2) + 1) else 'NO')
solve()


s = input()
a = s.count('AB')
b = s.count('BA')
t = s.count('ABA')
u = s.count('BAB')
s = a + b - t - u
if s >= 2 and a > 0 and (b > 0):
	print('YES')
else:
	print('NO')


r = input()
n = len(r)
e = 0
i = 0
for i in range(0, n - 1):
	if r[i:i + 2] == 'AB':
		break
for j in range(i + 2, n - 1):
	if r[j:j + 2] == 'BA':
		print('YES')
		exit(0)
i = 0
for i in range(0, n - 1):
	if r[i:i + 2] == 'BA':
		break
for j in range(i + 2, n - 1):
	if r[j:j + 2] == 'AB':
		print('YES')
		exit(0)
print('NO')


fl = lambda a: s.find(a)
fr = lambda a: s.rfind(a)
f = lambda l, r: r - l > 1 and l >= 0 and (r >= 0)
(x, y) = ('AB', 'BA')
s = input()
print('YES' if f(fl(x), fr(y)) or f(fl(y), fr(x)) else 'NO')


def ok(s, a, b):
	indexa = s.find(a)
	if indexa == -1:
		return False
	return s.find(b, indexa + 2) != -1

def __starting_point():
	s = input().strip()
	if ok(s, 'AB', 'BA') or ok(s, 'BA', 'AB'):
		print('YES')
	else:
		print('NO')
__starting_point()


s = input()
flagA = 0
flagB = 0
flagABBA = 0
(i, j) = (0, 1)
while j < len(s):
	if j + 1 < len(s) and s[i] == 'A' and (s[j] == 'B') and (s[j + 1] == 'A'):
		flagABBA += 1
		i += 3
		j += 3
	elif j + 1 < len(s) and s[i] == 'B' and (s[j] == 'A') and (s[j + 1] == 'B'):
		flagABBA += 1
		i += 3
		j += 3
	elif s[i] == 'A' and s[j] == 'B':
		flagA = 1
		i += 2
		j += 2
	elif s[i] == 'B' and s[j] == 'A':
		flagB = 1
		i += 2
		j += 2
	else:
		i += 1
		j += 1
if flagA > 0 and flagB > 0 or (flagA > 0 and flagABBA > 0) or (flagB > 0 and flagABBA > 0) or (flagABBA > 1):
	print('YES')
else:
	print('NO')


s = input()
(flag1, flag2) = (0, 0)
try:
	for i in range(len(s)):
		if s[i:i + 2] == 'AB':
			if 'BA' in s[i + 2:]:
				print('YES')
				raise
			flag1 = True
		if s[i:i + 2] == 'BA':
			if 'AB' in s[i + 2:]:
				print('YES')
				raise
			flag2 = True
		if flag1 and flag2:
			print('NO')
			raise
	else:
		print('NO')
except:
	pass


s = input()
yes = False
if 'AB' in s:
	i = s.index('AB')
	n = s[:i] + ' ' + s[i + 2:]
	if n.count('BA') > 0:
		yes = True
if 'BA' in s:
	i = s.index('BA')
	n = s[:i] + ' ' + s[i + 2:]
	if n.count('AB') > 0:
		yes = True
if yes:
	print('YES')
else:
	print('NO')


def check():
	id1 = s.find(order[0])
	id2 = s.rfind(order[1])
	if id1 == -1 or id2 == -1:
		return False
	return id1 + 1 < id2
s = input()
order = ['AB', 'BA']
if check():
	print('YES')
else:
	order = order[::-1]
	print('YES' if check() else 'NO')


s = input()
flag = False
(l1, l2) = ([], [])
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		l1.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		l2.append(i)
for i in l1:
	for j in l2:
		if abs(i - j) >= 2:
			print('YES')
			flag = True
			break
	if flag:
		break
if flag == False:
	print('NO')


s = input()
x = 1
while x < len(s):
	if s[x - 1] == 'A' and s[x] == 'B':
		if 'BA' in s[x + 1:]:
			print('YES')
			break
	elif s[x - 1] == 'B' and s[x] == 'A':
		if 'AB' in s[x + 1:]:
			print('YES')
			break
	x += 1
else:
	print('NO')


s = input()
slen = len(s)
ab = []
ba = []
start = 0
while start < slen - 1:
	if s[start] == 'A' and s[start + 1] == 'B':
		ab.append(start + 1)
	elif s[start] == 'B' and s[start + 1] == 'A':
		ba.append(start + 1)
	start += 1
flag = 0
for x in ab:
	for y in ba:
		if abs(x - y) > 1:
			flag = 1
			break
	if flag:
		break
print('YES') if flag == 1 else print('NO')


string = str(input())
flag = False
for i in range(len(string) - 1):
	if string[i] + string[i + 1] == 'AB':
		if 'BA' in string[:i]:
			flag = True
		if 'BA' in string[i + 2:]:
			flag = True
if flag:
	print('YES')
else:
	print('NO')


__author__ = 'Bian'
st = input()
ab1 = st.find('AB')
ba1 = st.find('BA', ab1 + 2)
ba2 = st.find('BA')
ab2 = st.find('AB', ba2 + 2)
if ab1 != -1 and ba1 != -1 or (ab2 != -1 and ba2 != -1):
	print('YES')
else:
	print('NO')


s = input()
(ab, ba) = ([], [])
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	elif s[i:i + 2] == 'BA':
		ba.append(i)
for u in ab:
	for v in ba:
		if abs(u - v) > 1:
			print('YES')
			exit()
print('NO')


s = input()
t = s
has_ab = has_ba = False
if 'AB' in t:
	has_ab = True
	t = t.replace('AB', ' ', 1)
if 'BA' in t:
	has_ba = True
if not (has_ab and has_ba):
	has_ab = has_ba = False
	if 'BA' in s:
		has_ba = True
		s = s.replace('BA', ' ', 1)
	if 'AB' in s:
		has_ab = True
print('YES' if has_ab and has_ba else 'NO')


s = input()
slen = len(s)
start = 0
flag = 0
ab = 0
ba = 0
while start < slen - 1:
	if s[start] == 'A' and s[start + 1] == 'B':
		if ba > 0 and abs(ba - (start + 1)) > 1:
			flag = 1
			break
		if ab == 0:
			ab = start + 1
	elif s[start] == 'B' and s[start + 1] == 'A':
		if ab > 0 and abs(ab - (start + 1)) > 1:
			flag = 1
			break
		if ba == 0:
			ba = start + 1
	start += 1
print('YES') if flag == 1 else print('NO')


import sys
s = sys.stdin.readline()
ans = 'NO'
AB = []
BA = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		AB.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		BA.append(i)
for a in AB:
	for b in BA:
		if abs(a - b) >= 2:
			ans = 'YES'
			break
print(ans)


s = input()
flag = 0
for i in range(0, len(s) - 2):
	if s[i] == 'A' and s[i + 1] == 'B':
		if 'BA' in s[i + 2:]:
			flag = 1
			break
	elif s[i] == 'B' and s[i + 1] == 'A':
		if 'AB' in s[i + 2:]:
			flag = 1
			break
if flag == 1:
	print('YES')
else:
	print('NO')


user = input()
str = ' '
A = False
B = False
n = 0
if 'AB' in user:
	n = user.find('AB')
	str = user[n + 2:]
	if 'BA' in str:
		A = True
if A == False and 'BA' in user:
	u = user.find('BA')
	str = user[u + 2:]
	if 'AB' in str:
		B = True
if A == True:
	print('YES')
elif B == True:
	print('YES')
else:
	print('NO')


s = str(input())
if 'AB' in s and 'BA' in s:
	s1 = s.replace('AB', '__', 1)
	if 'BA' in s1:
		ans1 = 1
	else:
		ans1 = 0
	s2 = s.replace('BA', '__', 1)
	if 'AB' in s2:
		ans2 = 1
	else:
		ans2 = 0
	if ans1 == 1 or ans2 == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
CA = []
CB = []
for i in range(len(s) - 1):
	if s[i] == 'A':
		if s[i + 1] == 'B':
			CA.append(i)
	if s[i] == 'B':
		if s[i + 1] == 'A':
			CB.append(i)
if len(CA) and len(CB) and (abs(CA[len(CA) - 1] - CB[0]) >= 2 or abs(CB[len(CB) - 1] - CA[0]) >= 2):
	print('YES')
else:
	print('NO')


def __starting_point():
	s = input()
	a = None
	b = None
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			if a is None:
				a = i
			if b is not None and abs(i - b) > 1:
				print('YES')
				return
		if s[i] == 'B' and s[i + 1] == 'A':
			if b is None:
				b = i
			if a is not None and abs(a - i) > 1:
				print('YES')
				return
	print('NO')
__starting_point()


s = input()
(x, y, m, n) = (-1, -1, -1, -1)
x = s.find('AB')
s1 = s[x + 2:]
y = s1.find('BA')
m = s.find('BA')
s2 = s[m + 2:]
n = s2.find('AB')
if m >= 0 and n >= 0 or (x >= 0 and y >= 0):
	print('YES')
else:
	print('NO')


s = input()
a1 = 0
a2 = 0
b1 = []
b2 = []
for i in range(1, len(s)):
	if s[i] == 'B' and s[i - 1] == 'A':
		a1 += 1
		b1.append(i - 1)
		b1.append(i)
	if s[i] == 'A' and s[i - 1] == 'B':
		a2 += 1
		b2.append(i - 1)
		b2.append(i)
if a1 == 0 or a2 == 0:
	print('NO')
elif a1 == 1 and a2 == 2:
	if b1[0] == b2[1] and b1[1] == b2[2]:
		print('NO')
	else:
		print('YES')
elif a2 == 1 and a1 == 2:
	if b2[0] == b1[1] and b2[1] == b1[2]:
		print('NO')
	else:
		print('YES')
elif a1 > 1 or a2 > 1:
	print('YES')
elif a1 == 1 and a2 == 1:
	if b1[1] == b2[0] or b1[0] == b2[1]:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


s = input()
lf = s.find('AB')
ls = s.find('BA')
rf = s.rfind('AB')
rs = s.rfind('BA')
if lf == -1 or ls == -1:
	print('NO')
elif abs(ls - lf) != 1 or abs(rs - rf) != 1:
	print('YES')
elif abs(rs - lf) != 1 or abs(rf - ls) != 1:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
l = [[0, 0] for i in range(n + 1)]
flag = 0
for i in range(len(s) - 1):
	l[i + 2][0] = l[i + 1][0]
	l[i + 2][1] = l[i + 1][1]
	if s[i:i + 2] == 'AB':
		l[i + 2][0] = l[i + 2][0] + 1
		if l[i][1] >= 1:
			flag = 1
			break
	elif s[i:i + 2] == 'BA':
		l[i + 2][1] = l[i + 2][1] + 1
		if l[i][0] >= 1:
			flag = 1
			break
print('YES' if flag == 1 else 'NO')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
s = input().strip()
c = 0
i = 0
while i < len(s):
	if c == 0:
		if i + 1 < len(s):
			if s[i] == 'A' and s[i + 1] == 'B':
				c += 1
				i += 1
	elif c > 0:
		if c == 1:
			if i + 1 < len(s):
				if s[i] == 'B' and s[i + 1] == 'A':
					print('YES')
					exit()
	i += 1
i = 0
c = 0
while i < len(s):
	if c == 0:
		if i + 1 < len(s):
			if s[i] == 'B' and s[i + 1] == 'A':
				c += 1
				i += 1
	elif c > 0:
		if c == 1:
			if i + 1 < len(s):
				if s[i] == 'A' and s[i + 1] == 'B':
					print('YES')
					exit()
	i += 1
print('NO')


s = input()
n = len(s)
i = 0
if n <= 3:
	print('NO')
else:
	i = 0
	d = []
	e = []
	while i < n:
		if i != n - 1:
			if s[i] + s[i + 1] == 'AB':
				d.append(i + 1)
				i = i + 1
			elif s[i] + s[i + 1] == 'BA':
				e.append(i + 1)
				i = i + 1
			else:
				i = i + 1
		else:
			i = i + 1
	flag = 0
	if d != []:
		for i in e:
			if abs(d[0] - i) > 1:
				print('YES')
				flag = 1
				break
	if flag == 0:
		if e != []:
			for i in d:
				if abs(e[0] - i) > 1:
					print('YES')
					flag = 1
					break
	if flag == 0:
		print('NO')


import collections
a = input()
flag = 0
flag1 = 0
i = 1
while i < len(a):
	if a[i] == 'B' and a[i - 1] == 'A' and (flag == 0):
		flag = 1
		i += 1
	elif a[i] == 'A' and a[i - 1] == 'B' and (flag1 == 0) and (flag == 1):
		flag1 = 1
		i += 1
	i += 1
if flag == 1 and flag1 == 1:
	print('YES')
else:
	flag = 0
	flag1 = 0
	i = 1
	while i < len(a):
		if a[i] == 'A' and a[i - 1] == 'B' and (flag1 == 0):
			flag1 = 1
			i += 1
		elif a[i] == 'B' and a[i - 1] == 'A' and (flag == 0) and (flag1 == 1):
			flag = 1
			i += 1
		i += 1
	if flag == 1 and flag1 == 1:
		print('YES')
	else:
		print('NO')


s = input()
if 'AB' in s:
	if 'BA' in s[s.index('AB') + 2:] or 'BA' in s[0:s.index('AB')]:
		print('YES')
	elif 'BA' in s:
		if 'AB' in s[s.index('BA') + 2:] or 'AB' in s[0:s.index('BA')]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


def solution():
	s = input()
	current_a = -2
	current_b = -2
	ab = []
	ba = []
	for i in range(len(s)):
		if s[i] == 'A':
			current_a = i
		if s[i] == 'B' and current_a == i - 1:
			ab.append((i - 1, i))
	for j in range(len(s)):
		if s[j] == 'B':
			current_b = j
		if s[j] == 'A' and current_b == j - 1:
			ba.append((j - 1, j))
	for k in range(len(ab)):
		for l in range(len(ba)):
			if not ab[k][0] == ba[l][1] and (not ab[k][1] == ba[l][0]):
				print('YES')
				return
	print('NO')
solution()


s = input()
a = s.find('AB')
b = s.find('BA')
if a != -1 and s.find('BA', a + 2) != -1:
	print('YES')
elif b != -1 and s.find('AB', b + 2) != -1:
	print('YES')
else:
	print('NO')


string = input()
output = False
if 'AB' in string and (not output):
	string2 = string.replace('AB', '*', 1)
	if 'BA' in string2:
		print('YES')
		output = True
if 'BA' in string and (not output):
	string2 = string.replace('BA', '*', 1)
	if 'AB' in string2:
		print('YES')
		output = True
if not output:
	print('NO')


s = input()
s1 = 'ABBA'
s2 = 'BAAB'
start = 0
flag = 0
prev = 0
for i in range(len(s) - 1):
	if prev == 1:
		prev = 0
		continue
	if s[i] == s1[start]:
		if s[i + 1] == s1[start + 1]:
			start += 2
			prev = 1
	if start == 4:
		flag = 1
		break
start = 0
prev = 0
for i in range(len(s) - 1):
	if prev == 1:
		prev = 0
		continue
	if s[i] == s2[start]:
		if s[i + 1] == s2[start + 1]:
			start += 2
			prev = 1
	if start == 4:
		flag = 1
		break
if flag == 0:
	print('NO')
else:
	print('YES')


s = input()
c1 = c2 = c3 = 0
i = 0
while i < len(s):
	if s[i:i + 3] == 'ABA' or s[i:i + 3] == 'BAB':
		c3 += 1
		i += 3
	elif s[i:i + 2] == 'AB':
		c1 += 1
		i += 2
	elif s[i:i + 2] == 'BA':
		c2 += 1
		i += 2
	else:
		i += 1
print('YES' if c3 >= 2 or (c1 and (c2 or c3)) or (c2 and (c1 or c3)) else 'NO')


st = input()
a = 0
if st.find('AB') != -1 and st.find('BA') != -1:
	k = st.replace('AB', 'NN', 1)
	l = st.replace('BA', 'NN', 1)
	if k.find('BA') != -1 or l.find('AB') != -1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


S = input()
N = len(S)
ab = []
ba = []
for i in range(N - 1):
	if S[i:i + 2] == 'AB':
		ab.append(i)
	elif S[i:i + 2] == 'BA':
		ba.append(i)
flg = False
for x in ab:
	if flg:
		break
	for y in ba:
		if abs(x - y) > 1:
			flg = True
			break
if flg:
	print('YES')
else:
	print('NO')


s = input()
ab = []
flag = False
ab = False
ba = False
i = 0
while i < len(s) - 1:
	if i < len(s) - 2 and s[i:i + 3] in ('ABA', 'BAB'):
		if flag:
			print('YES')
			break
		flag = True
		i += 3
		if ab + ba + flag >= 2:
			print('YES')
			break
		continue
	if s[i:i + 2] == 'AB':
		ab = True
		i += 2
		if ab + ba + flag >= 2:
			print('YES')
			break
		continue
	if s[i:i + 2] == 'BA':
		ba = True
		i += 2
		if ab + ba + flag >= 2:
			print('YES')
			break
		continue
	i += 1
else:
	print('NO')


s = input()
x = s.count('AB')
y = s.count('BA')
if x > 1:
	if y > 1:
		print('YES')
	elif y == 1:
		s = s.replace('BA', ' ')
		if s.count('AB'):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
elif x == 1:
	s = s.replace('AB', ' ')
	if s.count('BA'):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def has_non_overlapping_substrings(string):
	index = string.find('AB')
	if index >= 0 and string.find('BA', index + 2) > 0:
		return True
	index = string.find('BA')
	if index >= 0 and string.find('AB', index + 2) > 0:
		return True
	return False

def run_alg():
	result = has_non_overlapping_substrings(input())
	print('YES' if result else 'NO')
run_alg()


s = input()
l = len(s)
ab = []
ba = []
for i in range(l - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	elif s[i:i + 2] == 'BA':
		ba.append(i)
if not ab or not ba:
	print('NO')
else:
	bk = False
	for i in ab:
		for j in ba:
			if abs(i - j) >= 2:
				bk = True
				break
		if bk:
			break
	if bk:
		print('YES')
	else:
		print('NO')


s = input()
a = s.count('AB')
b = s.count('BA')
c = s.count('ABA')
d = s.count('BAB')
print(['NO', 'YES'][(a + b) * (a != 0 and b != 0) - c - d > 1])


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
s = is1()
(a, b) = ([], [])
for i in range(1, len(s)):
	if s[i] == 'B' and s[i - 1] == 'A':
		a.append(i - 1)
	elif s[i] == 'A' and s[i - 1] == 'B':
		b.append(i - 1)
if not (len(a) and len(b)):
	print('NO')
elif abs(a[0] - b[-1]) > 1 or abs(a[-1] - b[0]) > 1:
	print('YES')
else:
	print('NO')


s = input().strip()
l1 = s.find('AB')
l2 = s.find('BA')
if l1 == -1 or l2 == -1:
	print('NO')
else:
	k = s[l1 + 2:].find('BA')
	if k == -1:
		k = s[l2 + 2:].find('AB')
		if k == -1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


S = list(input())

def test_target(self, target, p):
	for i in target:
		if p - i > 1:
			return True
	self.append(p)
	return False
AB_list = list()
BA_list = list()
for i in range(1, len(S)):
	if S[i - 1] == 'A' and S[i] == 'B':
		if test_target(AB_list, BA_list, i):
			print('YES')
			break
	if S[i - 1] == 'B' and S[i] == 'A':
		if test_target(BA_list, AB_list, i):
			print('YES')
			break
else:
	print('NO')


import re
s = input()
p1 = re.compile('((?!AB)[A-Z])*AB((?!BA)[A-Z])*BA[A-Z]*')
p2 = re.compile('((?!BA)[A-Z])*BA((?!AB)[A-Z])*AB[A-Z]*')
print('YES' if p1.match(s) or p2.match(s) else 'NO')


ab = 'AB'
ba = 'BA'

def res(s, j):
	global ab, ba
	if j:
		(ab, ba) = (ba, ab)
	ai = s.find(ab)
	if ai == -1:
		return 0
	fp = s[:ai]
	sp = s[ai + 2:]
	bi = fp.find(ba)
	if bi == -1:
		bi = sp.find(ba)
	if bi == -1:
		return 0
	return 1
s = input()
s = 'YES' if res(s, 0) or res(s, 1) else 'NO'
print(s)


x = str(input())
ab = x.find('AB')
abb = x[ab + 2:].find('BA')
ba = x.find('BA')
baa = x[ba + 2:].find('AB')
print('YES' if ab != -1 and abb != -1 or (ba != -1 and baa != -1) else 'NO')


def find(d, t1, t2):
	for i in range(len(d)):
		if i + 1 < len(d) and d[i] == t1 and (d[i + 1] == t2):
			return True
	return False

def solve(d):
	found = False
	ind = 0
	n = len(d)
	f = True
	l = True
	while ind < n:
		if f and d[ind] == 'A' and (ind + 1 < n) and (d[ind + 1] == 'B'):
			found = find(d[ind + 2:], 'B', 'A')
			f = False
		elif l and d[ind] == 'B' and (ind + 1 < n) and (d[ind + 1] == 'A'):
			found = find(d[ind + 2:], 'A', 'B')
			l = False
		ind += 1
		if found:
			return 'YES'
	return 'NO'

def main():
	d = input()
	ans = solve(d)
	print(ans)
main()


def solve(s, s1, s2):
	pos = s.find(s1)
	if pos == -1:
		return False
	pos = s.find(s2, pos + 2)
	if pos == -1:
		return False
	else:
		return True
s = input()
if solve(s, 'AB', 'BA') or solve(s, 'BA', 'AB'):
	print('YES')
else:
	print('NO')


s = input()
x = 0
i = 0
while i < len(s) - 1:
	if i < len(s) - 2 and s[i] == 'A' and (s[i + 1] == 'B') and (s[i + 2] == 'A'):
		x = 1
		break
	elif i < len(s) - 2 and s[i] == 'B' and (s[i + 1] == 'A') and (s[i + 2] == 'B'):
		x = 1
		break
	elif s[i] == 'A' and s[i + 1] == 'B':
		x = 2
		break
	elif s[i] == 'B' and s[i + 1] == 'A':
		x = 3
		break
	i += 1
if x == 2:
	i += 2
	while i < len(s) - 1:
		if s[i] == 'B' and s[i + 1] == 'A':
			x = 4
			break
		i += 1
elif x == 3:
	i += 2
	while i < len(s) - 1:
		if s[i] == 'A' and s[i + 1] == 'B':
			x = 4
			break
		i += 1
elif x == 1:
	i += 3
	while i < len(s) - 1:
		if s[i] == 'B' and s[i + 1] == 'A':
			x = 4
			break
		elif s[i] == 'A' and s[i + 1] == 'B':
			x = 4
			break
		i += 1
if x == 4:
	print('YES')
else:
	print('NO')


n = input()
ab = n.find('AB')
bar = n.rfind('BA')
abr = n.rfind('AB')
ba = n.find('BA')
print(['NO', 'YES'][(abs(ab - bar) > 1 or abs(abr - ba) > 1) and min(ab, ba, abr, bar) >= 0])


def isabba(s):
	n = len(s)
	(i, ab, ba) = (0, 0, 0)
	while i < n - 1:
		if s[i] == 'A' and s[i + 1] == 'B':
			ab = 1
			i += 2
			break
		i += 1
	if ab == 0:
		return False
	while i < n - 1:
		if s[i] == 'B' and s[i + 1] == 'A':
			ba = 1
			break
		i += 1
	if ba:
		return True
	return False

def isbaab(s):
	n = len(s)
	(i, ab, ba) = (0, 0, 0)
	while i < n - 1:
		if s[i] == 'B' and s[i + 1] == 'A':
			ab = 1
			i += 2
			break
		i += 1
	if ab == 0:
		return False
	while i < n - 1:
		if s[i] == 'A' and s[i + 1] == 'B':
			ba = 1
			break
		i += 1
	if ba:
		return True
	return False
s = input()
if isabba(s) or isbaab(s):
	print('YES', end='')
else:
	print('NO', end='')


s = '*' + input() + '**'
n = len(s) - 3
if n < 1:
	print('NO')
else:
	for i in range(1, n):
		if s[i:i + 2] == 'AB':
			c = 0
			for j in range(i + 2, n):
				if s[j:j + 2] == 'BA':
					c = 1
					break
			if c == 1:
				print('YES')
				exit(0)
			break
	for i in range(1, n):
		if s[i:i + 2] == 'BA':
			c = 0
			for j in range(i + 2, n):
				if s[j:j + 2] == 'AB':
					c = 1
					break
			if c == 1:
				print('YES')
				exit(0)
			break
	print('NO')


s = input()

def check_ABBA(s, A, B):
	prev_c = '.'
	for (i, c) in enumerate(s):
		if c == B and prev_c == A:
			break
		prev_c = c
	else:
		return False
	prev_c = '.'
	for c in s[i + 1:]:
		if c == A and prev_c == B:
			return True
		prev_c = c
	return False
if check_ABBA(s, 'A', 'B'):
	print('YES')
elif check_ABBA(s, 'B', 'A'):
	print('YES')
else:
	print('NO')


from sys import *
input = stdin.readline
s = input()
if 'AB' not in s or 'BA' not in s:
	print('NO')
else:
	a = s.index('AB')
	b = s.rindex('AB')
	c = s.index('BA')
	d = s.rindex('BA')
	if d - a > 1 or b - c > 1:
		print('YES')
	else:
		print('NO')


def f(inp, ab, ba):
	ab1 = inp.find(ab)
	if ab1 == -1:
		return False
	else:
		ba1 = inp.find(ba, ab1 + 2)
		if ba1 == -1:
			return False
		else:
			return True
inp = input()
if f(inp, 'AB', 'BA') or f(inp, 'BA', 'AB'):
	print('YES')
else:
	print('NO')


x = input()
ab = x.count('AB')
aba = x.count('ABA')
ba = x.count('BA')
bab = x.count('BAB')
if ab + ba - aba - bab >= 2 and (ab >= 1 and ba >= 1):
	print('YES')
else:
	print('NO')


s = str(input())
a = s.find('AB')
b = s.rfind('BA')
if abs(a - b) > 1 and min(a, b) >= 0:
	print('YES')
	exit()
a = s.rfind('AB')
b = s.find('BA')
if abs(a - b) > 1 and min(a, b) >= 0:
	print('YES')
	exit()
print('NO')


a = []
b = []
x = input()
for i in range(len(x) - 1):
	if x[i] + x[i + 1] == 'AB':
		a.append(i)
	elif x[i] + x[i + 1] == 'BA':
		b.append(i)
if a == [] or b == []:
	print('NO')
	quit()
if abs(min(a) - max(b)) > 1 or abs(max(a) - min(b)) > 1:
	print('YES')
	quit()
print('NO')


s = input()
i = s.find('AB')
j = s.rfind('BA')
i2 = s.rfind('AB')
j2 = s.find('BA')
print('YES' if i != -1 and j != -1 and (abs(i - j) > 1 or abs(i2 - j2) > 1) else 'NO')


s = input()
s1 = s
t = 0
z = 0
if s.find('AB') != -1:
	s = s[:s.find('AB')] + '..' + s[s.find('AB') + 2:]
	if s.find('BA') != -1:
		t = 1
if s1.find('BA') != -1:
	s = s1[:s1.find('BA')] + '..' + s1[s1.find('BA') + 2:]
	if s.find('AB') != -1:
		z = 1
if t == 1 or z == 1:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
flag = 0
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		for j in range(i + 2, n - 1):
			if s[j:j + 2] == 'BA':
				flag = 1
				print('YES')
				exit()
		break
for i in range(n - 1):
	if s[i:i + 2] == 'BA':
		for j in range(i + 2, n - 1):
			if s[j:j + 2] == 'AB':
				flag = 1
				print('YES')
				exit()
		break
print('NO')


s = input()
ok = 'NO'
i1 = -1
i2 = -1
j1 = -1
j2 = -1
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		if i1 == -1:
			i1 = i
		i2 = i
	if s[i] == 'B' and s[i + 1] == 'A':
		if j1 == -1:
			j1 = i
		j2 = i
if i1 != -1 and j1 != -1:
	if j2 - i1 > 1 or i2 - j1 > 1:
		ok = 'YES'
print(ok)


n = input()
a = n.find('AB')
b = n.find('BA')
print('YES' if a != -1 and n.find('BA', a + 2) != -1 or (b != -1 and n.find('AB', b + 2) != -1) else 'NO')


s = input()
if s.count('AB'):
	tmp = s.replace('AB', ' ', 1)
	if tmp.count('BA'):
		print('YES')
	elif s.count('BA'):
		tmp = s.replace('BA', ' ', 1)
		if tmp.count('AB'):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


s = input()
n = len(s)
aba = 0
ab = 0
ba = 0
bab = 0
i = 0
while i < n:
	if i < n - 2 and s[i] == 'A' and (s[i + 1] == 'B') and (s[i + 2] == 'A'):
		aba += 1
		i += 3
		continue
	if i < n - 2 and s[i] == 'B' and (s[i + 1] == 'A') and (s[i + 2] == 'B'):
		bab += 1
		i += 3
		continue
	if i < n - 1 and s[i] == 'A' and (s[i + 1] == 'B'):
		ab += 1
		i += 2
		continue
	if i < n - 1 and s[i] == 'B' and (s[i + 1] == 'A'):
		ba += 1
		i += 2
		continue
	i += 1
if ab and ba or (ab and aba) or (ba and aba) or (ab and bab) or (bab and aba) or (ba and bab):
	print('YES')
else:
	print('NO')


s = input()
poss = False
try:
	i = s.index('BA')
	j = s[i + 2:].index('AB')
	poss = True
except ValueError:
	pass
try:
	i = s.index('AB')
	j = s[i + 2:].index('BA')
	poss = True
except ValueError:
	pass
if poss:
	print('YES')
else:
	print('NO')


s = input()
x = s.find('AB', 0, len(s))
if x == -1:
	print('NO')
else:
	y = s.find('BA', 0, x)
	z = s.find('BA', x + 2, len(s))
	if y != -1 or z != -1:
		print('YES')
	else:
		x = s.find('BA', 0, len(s))
		if x == -1:
			print('NO')
		else:
			y = s.find('AB', 0, x)
			z = s.find('AB', x + 2, len(s))
			if y != -1 or z != -1:
				print('YES')
			else:
				print('NO')


s = input()
a = []
for i in s:
	a.append(i)
f = 0
if 'AB' in s and 'BA' in s:
	if 'ABA' not in s and 'BAB' not in s:
		f = 1
	else:
		if 'ABA' in s and 'BAB' in s:
			m = min(s.index('ABA'), s.index('BAB'))
			s = s[:m] + s[m + 3:]
		elif 'ABA' in s:
			s = s[:s.index('ABA')] + s[s.index('ABA') + 3:]
		elif 'BAB' in s:
			s = s[:s.index('BAB')] + s[s.index('BAB') + 3:]
		if 'AB' in s or 'BA' in s:
			f = 1
if f == 1:
	print('YES')
else:
	print('NO')


s = input()
l = len(s)
i = 0
ab = s.find('AB')
ba = s.find('BA')
if ab >= 0 and ba >= 0:
	if ab > ba + 1 or ba > ab + 1:
		print('YES')
	else:
		s = s[max(ab, ba) + 2:]
		ab = s.find('AB')
		ba = s.find('BA')
		if ab >= 0 or ba >= 0:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
s = cin()[:-1]
t = 0
ab = []
ba = []
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == 'AB':
		ab += [i]
	elif s[i:i + 2] == 'BA':
		ba += [i]
	i += 1
if not ab or not ba:
	cout('NO')
elif abs(min(ab) - max(ba)) > 1 or abs(min(ba) - max(ab)) > 1:
	cout('YES')
else:
	cout('NO')


n = input().strip()
l = n.rfind('BA')
k = n.find('AB')
j = n.rfind('AB')
p = n.find('BA')
t = False
for i in [l, p]:
	for x in [k, j]:
		if i != -1 and x != -1:
			if min(i, x) + 2 <= max(i, x):
				t = True
				print('YES')
				break
	if t == True:
		break
if t == False:
	print('NO')


s = input()
n = len(s)
flag = False
arr1 = []
arr2 = []
i = 1
for i in range(1, n):
	if s[i - 1:i + 1] == 'AB':
		arr1.append(i)
	if s[i - 1:i + 1] == 'BA':
		arr2.append(i)
flag = False
if len(arr1) >= 1 and len(arr2) >= 1:
	if arr1[0] + 1 < arr2[len(arr2) - 1]:
		flag = True
	if arr2[0] + 1 < arr1[len(arr1) - 1]:
		flag = True
if flag:
	print('YES')
else:
	print('NO')


s = input()
check1 = 0
check2 = 0
word1 = []
word2 = []
for i in range(len(s)):
	word1.append(s[i])
	word2.append(s[i])
if len(word1) <= 3:
	print('NO')
else:
	for i in range(len(word1) - 1):
		if word1[i] == 'A' and word1[i + 1] == 'B' and (check1 == 0):
			check1 += 1
			word1[i] = 0
			word1[i + 1] = 0
		elif word1[i] == 'B' and word1[i + 1] == 'A' and (check1 > 0):
			check2 += 1
			word1[i] = 0
			word1[i + 1] = 0
	if check1 > 0 and check2 > 0:
		print('YES')
	else:
		check1 = check2 = 0
		for i in range(len(word2) - 1):
			if word2[i] == 'B' and word2[i + 1] == 'A' and (check1 == 0):
				check1 += 1
				word2[i] = 0
				word2[i + 1] = 0
			elif word2[i] == 'A' and word2[i + 1] == 'B' and (check1 > 0):
				check2 += 1
				word2[i] = 0
				word2[i + 1] = 0
		if check1 > 0 and check2 > 0:
			print('YES')
		else:
			print('NO')


s = input()
pos1 = []
pos2 = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		pos1.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		pos2.append(i)
if len(pos1) > 0 and len(pos2) > 0:
	for i in pos1:
		for c in pos2:
			if i + 1 != c and c + 1 != i:
				print('YES')
				exit()
	print('NO')
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase

def main():
	s = input()
	if s.count('AB') == 0 or s.count('BA') == 0:
		print('NO')
	else:
		t = s.replace('AB', 'xx', 1)
		tt = s.replace('BA', 'xx', 1)
		if t.count('BA') >= 1 or tt.count('AB') >= 1:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import re
s = input()
ab = [i.start() for i in re.finditer('AB', s)]
ba = [i.start() for i in re.finditer('BA', s)]
ans = 0
for i in ab:
	for j in ba:
		if abs(i - j) > 1:
			ans = 1
			break
if ans:
	print('YES')
else:
	print('NO')


s = input()
a = []
b = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		b.append(i)
if len(a) == 0 or len(b) == 0:
	print('NO')
	exit(0)
for x in a:
	for y in b:
		if abs(x - y) > 1:
			print('YES')
			exit(0)
print('NO')


import re
a = input()
x = [m.start() for m in re.finditer('AB', a)]
y = [m.start() for m in re.finditer('BA', a)]
res = 0
i = 0
j = len(y) - 1
k = len(x) - 1
l = 0
while i < len(x) and j > -1 and (k > -1) and (l < len(y)):
	if abs(x[i] - y[j]) > 1 or abs(x[k] - y[l]) > 1:
		res = 1
	i += 1
	j -= 1
	k -= 1
	l += 1
if res:
	print('YES')
else:
	print('NO')


def solve(s):
	starts_count = 0
	for i in range(len(s)):
		if i + 1 < len(s) and s[i] == 'A' and (s[i + 1] == 'B'):
			starts_count += 1
	for i in range(len(s)):
		kill_count = 0
		if i + 1 < len(s) and s[i] == 'B' and (s[i + 1] == 'A'):
			if i - 1 >= 0 and s[i - 1] == 'A':
				kill_count += 1
			if i + 2 < len(s) and s[i + 2] == 'B':
				kill_count += 1
			if starts_count - kill_count > 0:
				return 'YES'
	return 'NO'
print(solve(input()))


import re
S = input()
if S.find('AB') >= 0 and 'BA' in S[S.find('AB') + 2:]:
	print('YES')
elif S.find('BA') >= 0 and 'AB' in S[S.find('BA') + 2:]:
	print('YES')
else:
	print('NO')


s = input()
a = s.find('AB')
b = s.rfind('AB')
c = s.find('BA')
d = s.rfind('BA')
e = min(a, b, c, d)
if (abs(a - d) > 1 or abs(b - c) > 1) and e >= 0:
	print('YES')
else:
	print('NO')


x = input()
i = 0
c = 0
d = 0
lol = []
yo = []
for i in range(len(x) - 1):
	if x[i] == 'A':
		if x[i + 1] == 'B':
			c += 1
			lol.append(i)
for i in range(len(x) - 1):
	if x[i] == 'B':
		if x[i + 1] == 'A':
			d += 1
			yo.append(i)
if c >= 1 and d >= 1:
	if c == 1 and d == 1:
		if lol[0] == yo[0] + 1 or yo[0] == lol[0] + 1:
			print('NO')
		else:
			print('YES')
	elif c == 1 and d == 2:
		if lol[0] == yo[0] + 1 and lol[0] == yo[1] - 1:
			print('NO')
		else:
			print('YES')
	elif c == 2 and d == 1:
		if yo[0] == lol[0] + 1 and yo[0] == lol[1] - 1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')
else:
	print('NO')


word = input()
AB = word.find('AB')
BA = word.find('BA')
print('YES' if AB > -1 and word.find('BA', AB + 2) > -1 or (BA > -1 and word.find('AB', BA + 2) > -1) else 'NO')


s = input()
iab = -1
iba = -1
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		if iab == -1:
			iab = i
		if iba != -1 and abs(i - iba) > 1:
			print('YES')
			break
	elif s[i:i + 2] == 'BA':
		if iba == -1:
			iba = i
		if iab != -1 and abs(i - iab) > 1:
			print('YES')
			break
else:
	print('NO')


import math
ch = input()
if 'AB' in ch and 'BA' in ch:
	ind1 = ch.index('AB')
	ind2 = ch.index('BA')
	if 'BA' in ch[ind1 + 2:] or 'BA' in ch[:ind1] or 'AB' in ch[ind2 + 2:] or ('AB' in ch[:ind2]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
n = len(s)
(abl, abr) = (s.find('AB'), s.rfind('AB'))
(bal, bar) = (s.find('BA'), s.rfind('BA'))
if abl >= 0 and bar >= 0 and (abs(abl - bar) > 1):
	print('YES')
elif bal >= 0 and abr >= 0 and (abs(bal - abr) > 1):
	print('YES')
else:
	print('NO')


s = input()
(cA, cB, cABA, cBAB) = (0, 0, 0, 0)
cA = s.count('AB')
cB = s.count('BA')
cABA = s.count('ABA')
cBAB = s.count('BAB')
if cA * cB > 2 and cA - cABA - cBAB + cB >= 0 or (cA * cB > 0 and (cA - cABA - cBAB > 0 or cB - cABA - cBAB > 0)):
	print('YES')
else:
	print('NO')


s = input()
first = s.find('AB')
second = s.find('BA', first + 2)
if first == -1 or second == -1:
	first = s.find('BA')
	second = s.find('AB', first + 2)
	if first == -1 or second == -1:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


s = input()
a = s.find('AB')
b = s.find('BA')
print(['NO', 'YES'][a + 1 > 0 and s.find('BA', a + 2) + 1 > 0 or (b + 1 > 0 and s.find('AB', b + 2) + 1 > 0)])


i = input()
c1 = i.count('AB')
c2 = i.count('BA')
if c1 > 0 and c2 > 0:
	j = i.find('AB')
	tmp = i[:j] + '00' + i[j + 2:]
	c2 = tmp.count('BA')
	if c2 > 0:
		print('YES')
	else:
		k = i.find('BA')
		tmp = i[:k] + '00' + i[k + 2:]
		c1 = tmp.count('AB')
		if c1 > 0:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


def indices(ls, a):
	ind = []
	for i in range(len(ls)):
		if ls[i] == a:
			ind.append(i)
	return ind

def match(AB, BA):
	for i in AB:
		for j in BA:
			if abs(i - j) > 1:
				return True
	return False

def main():
	s = list(input().rstrip())
	ls = []
	for i in range(len(s) - 1):
		ls.append(s[i] + s[i + 1])
	AB = indices(ls, 'AB')
	BA = indices(ls, 'BA')
	flag = match(AB, BA)
	ind = 0
	check = {True: 'YES', False: 'NO'}
	print(check[flag])
main()


def containsNonOverlappingABandBA(string):
	ABmatches = matchingPositions(string, 'AB')
	BAmatches = matchingPositions(string, 'BA')
	return contains(ABmatches, BAmatches) and (not overlap(ABmatches, BAmatches))

def matchingPositions(string, substring):
	return set((i for i in range(len(string) - 1) if match(string, i, substring)))

def match(string, i, substring):
	return string[i:i + len(substring)] == substring

def contains(ABmatches, BAmatches):
	return len(ABmatches) != 0 and len(BAmatches) != 0

def overlap(ABmatches, BAmatches):
	return len(ABmatches) < 3 and len(BAmatches) < 3 and all((abs(ABpos - BApos) < 2 for ABpos in ABmatches for BApos in BAmatches))
print('YES' if containsNonOverlappingABandBA(input()) else 'NO')


s = input()
t = 0
f = 0
i = 0
while i < len(s) and t < 2:
	if s[i:i + 3] == 'ABA' or s[i:i + 3] == 'BAB':
		f = 0
		t += 1
		i += 2
	elif (f == 1 or f == 0) and s[i:i + 2] == 'AB':
		f = 2
		t += 1
		i += 1
	elif (f == 2 or f == 0) and s[i:i + 2] == 'BA':
		f = 1
		t += 1
		i += 1
	i += 1
if t == 2:
	print('YES')
else:
	print('NO')


a = input()
if 'AB' in a and 'BA' in a:
	b = [i for i in range(len(a) - 1) if a[i] + a[i + 1] == 'AB']
	c = [i for i in range(len(a) - 1) if a[i] + a[i + 1] == 'BA']
	if abs(max(b) - min(c)) > 1 or abs(max(c) - min(b)) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
if 'AB' in s and 'BA' in s:
	abi = []
	bai = []
	for i in range(len(s) - 1):
		if s[i] + s[i + 1] == 'AB':
			abi.append(i)
		if s[i] + s[i + 1] == 'BA':
			bai.append(i)
	print('YES' if abs(bai[-1] - abi[0]) > 1 or abs(bai[0] - abi[-1]) > 1 or abs(bai[0] - abi[0]) > 1 or (abs(bai[-1] - abi[-1]) > 1) else 'NO')
else:
	print('NO')


def find_by_ab(ab_ba, w1, w2):
	a = ab_ba.find(w1)
	if a != -1:
		ab_ba = ab_ba[a + 2:]
		b = ab_ba.find(w2)
		if b != -1:
			return 'YES'
	else:
		return 'NO'
ab_ba = input()
res = find_by_ab(ab_ba, 'AB', 'BA')
if res == 'YES':
	print('YES')
else:
	res = find_by_ab(ab_ba, 'BA', 'AB')
	if res == 'YES':
		print('YES')
	else:
		print('NO')


inputString = input()
(indexAB, indexBA) = ([-1 for i in range(2)], [-1 for i in range(2)])
for i in range(len(inputString) - 1):
	if inputString[i] == 'A' and inputString[i + 1] == 'B':
		if indexAB[0] == -1:
			indexAB[0] = i
		if indexAB[1] < i:
			indexAB[1] = i
	elif inputString[i] == 'B' and inputString[i + 1] == 'A':
		if indexBA[0] == -1:
			indexBA[0] = i
		if indexBA[1] < i:
			indexBA[1] = i
if indexAB[0] != -1 and indexBA[0] != -1 and (indexBA[1] - indexAB[0] >= 2 or indexAB[1] - indexBA[0] >= 2):
	print('YES')
else:
	print('NO')


st = input()
s1 = st.replace('AB', '0', 1)
s1 = s1.replace('BA', '1', 1)
s2 = st.replace('BA', '1', 1)
s2 = s2.replace('AB', '0', 1)
if '0' in s1 and '1' in s1 or ('0' in s2 and '1' in s2):
	print('YES')
else:
	print('NO')


s = input()
l1 = []
l2 = []
(c1, c2) = (0, 0)
n = len(s)
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		l1.append(i)
		c1 += 1
	elif s[i:i + 2] == 'BA':
		l2.append(i)
		c2 += 1
if c1 == 0 or c2 == 0:
	print('NO')
elif abs(l1[c1 - 1] - l2[0]) >= 2 or abs(l1[0] - l2[c2 - 1]) >= 2:
	print('YES')
else:
	print('NO')


s = input()
flag = 0
pos = 0
ab = s.find('AB')
if ab != -1:
	ba = s.find('BA', ab + 2)
	if ba != -1:
		flag = 1
ba = s.find('BA')
if ba != -1:
	ab = s.find('AB', ba + 2)
	if ab != -1:
		pos = 1
if pos == 1 or flag == 1:
	print('YES')
else:
	print('NO')


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi
import math
from itertools import permutations
from copy import deepcopy

def main():
	s = input().rstrip()
	n = int(len(s))
	if n <= 3:
		print('NO')
	else:
		d = [0] * n
		for i in range(n - 1):
			if s[i] == 'A' and s[i + 1] == 'B':
				d[i] = 1
		ans = 'NO'
		for i in range(1, n):
			d[i] += d[i - 1]
		for i in range(n - 1):
			if s[i] == 'B' and s[i + 1] == 'A':
				if i - 2 >= 0:
					if d[i - 2] >= 1 or d[-1] - d[i + 1] >= 1:
						ans = 'YES'
						break
				elif i + 2 < n:
					if d[-1] - d[i + 1] >= 1:
						ans = 'YES'
						break
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


s = input().strip()
a = s.find('AB')
b = s.find('BA')
if a == -1 or b == -1:
	print('NO')
elif a > b + 1 or b > a + 1:
	print('YES')
else:
	a2 = s.find('AB', b + 2)
	b2 = s.find('BA', a + 2)
	if a2 != -1 or b2 != -1:
		print('YES')
	else:
		print('NO')


def findAB(string):
	ia = string.find('AB')
	if ia == -1:
		return False
	else:
		ib = string[ia + 2:].find('BA')
		return ib != -1

def findBA(string):
	ib = string.find('BA')
	if ib == -1:
		return False
	else:
		ia = string[ib + 2:].find('AB')
		return ia != -1
s = input().strip()
if findAB(s) or findBA(s):
	print('YES')
else:
	print('NO')


a = input()
ind1 = a.find('AB')
ind2 = a.find('BA')
ind3 = a.rfind('BA')
ind4 = a.rfind('AB')
sz = min(ind1 + 2, ind3 + 2) - max(ind1, ind3)
sz2 = min(ind2 + 2, ind4 + 2) - max(ind2, ind4)
if (sz <= 0 or sz2 <= 0) and ind1 != -1 and (ind2 != -1):
	print('YES')
else:
	print('NO')


import re
s = str(input())
ab = len(list(re.finditer('AB', s)))
ba = len(list(re.finditer('BA', s)))
if ab == 0 and ba == 0:
	print('NO')
	exit()
aba = len(list(re.finditer('ABA', s)))
bab = len(list(re.finditer('BAB', s)))
abab = len(list(re.finditer('ABAB', s)))
baba = len(list(re.finditer('BABA', s)))
if aba > 1 or bab > 1:
	print('YES')
	exit()
if len(list(re.finditer('BABAB', s))) >= 1 or len(list(re.finditer('ABABA', s))) >= 1:
	print('YES')
	exit()
if abab == 1 and baba == 0 and (ab < 3) and (ba < 2) or (baba == 1 and abab == 0 and (ab < 2) and (ba < 3)):
	print('NO')
	exit()
if bab == 1 or aba == 1:
	if ab > 1 or ba > 1:
		print('YES')
	else:
		print('NO')
elif bab == 0 and aba == 0:
	if ab > 0 and ba > 0:
		print('YES')
	else:
		print('NO')


def solve():
	s = input()
	(ab, ba) = (0, 0)
	i = 0
	while i < len(s) - 1:
		if ab == 0 and s[i:i + 2] == 'AB':
			ab = 1
			i += 1
		elif ba == 0 and ab != 0 and (s[i:i + 2] == 'BA'):
			ba = 1
			i += 1
		i += 1
	if ab == 0 or ba == 0:
		(ab, ba) = (0, 0)
		i = 0
		while i < len(s) - 1:
			if ba == 0 and s[i:i + 2] == 'BA':
				ba = 1
				i += 1
			elif ab == 0 and ba != 0 and (s[i:i + 2] == 'AB'):
				ab = 1
				i += 1
			i += 1
	print('NO' if ab == 0 or ba == 0 else 'YES')
solve()


s = input()
q = 0
t = s.find('AB')
if t != -1 and t <= len(s) - 4 and (s.find('BA', t + 2) != -1):
	q = 1
t = s.find('BA')
if t != -1 and t <= len(s) - 4 and (s.find('AB', t + 2) != -1):
	q = 1
if q == 1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline

def prog():
	s = input().strip()
	flag = False
	worked = False
	for i in range(len(s) - 1):
		substring = s[i:i + 2]
		if substring == 'AB' and flag == False:
			flag = True
			start = i + 2
			break
	if flag:
		for i in range(start, len(s) - 1):
			substring = s[i:i + 2]
			if substring == 'BA':
				worked = True
				break
	if worked:
		print('YES')
		return
	flag = False
	worked = False
	for i in range(len(s) - 1):
		substring = s[i:i + 2]
		if substring == 'BA' and flag == False:
			flag = True
			start = i + 2
			break
	if flag:
		for i in range(start, len(s) - 1):
			substring = s[i:i + 2]
			if substring == 'AB':
				worked = True
				break
	if worked:
		print('YES')
	else:
		print('NO')
prog()


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque

def VI():
	return list(map(int, input().split()))

def main(s):
	ab = []
	ba = []
	ni = s.count('AB')
	nj = s.count('BA')
	if ni + nj >= 4 and ni >= 1 and (nj >= 1):
		print('YES')
		return
	if ni + nj <= 1 or ni == 0 or nj == 0:
		print('NO')
		return
	last = 0
	for i in range(ni):
		pi = s.index('AB', last)
		lastJ = 0
		for j in range(nj):
			pj = s.index('BA', lastJ)
			if abs(pi - pj) >= 2:
				print('YES')
				return
			lastJ = pj + 1
		last = pi + 1
	print('NO')

def main_input(info=0):
	s = input()
	main(s)
main_input()


string = input()
AB = []
BA = []
for i in range(len(string) - 1):
	current = string[i:i + 2]
	if current == 'AB':
		AB.append(i)
	elif current == 'BA':
		BA.append(i)
result = 'NO'
for item1 in AB:
	for item2 in BA:
		if abs(item1 - item2) > 1:
			result = 'YES'
			break
print(result)


s = [i for i in input()]
n = len(s)
fx = False
fy = False
i = 0
while i < n:
	if s[i] == 'A':
		if i + 1 < n and fx is False:
			if s[i + 1] == 'B':
				fx = True
				i += 2
				break
	i += 1
while i < n:
	if s[i] == 'B':
		if i + 1 < n and fy is False:
			if s[i + 1] == 'A':
				fy = True
				i += 2
				break
	i += 1
if fx and fy:
	print('YES')
else:
	fx = False
	fy = False
	i = 0
	while i < n:
		if s[i] == 'B':
			if i + 1 < n and fx is False:
				if s[i + 1] == 'A':
					fx = True
					i += 2
					break
		i += 1
	while i < n:
		if s[i] == 'A':
			if i + 1 < n and fy is False:
				if s[i + 1] == 'B':
					fy = True
					i += 2
					break
		i += 1
	if fx and fy:
		print('YES')
	else:
		print('NO')


st = input()

def ans(st):
	try:
		(a, b) = st.split('AB', 1)
		if 'BA' in a or 'BA' in b:
			return 'YES'
		(a, b) = st.split('BA', 1)
		if 'AB' in a or 'AB' in b:
			return 'YES'
		else:
			return 'NO'
	except:
		return 'NO'
print(ans(st))


import re
s = str(input())
isFind = False
iAB = [i.start() for i in re.finditer('AB', s)]
iBA = [i.start() for i in re.finditer('BA', s)]
for i in range(int(len(iAB))):
	for j in range(int(len(iBA))):
		if abs(iAB[i] - iBA[j]) >= 2:
			isFind = True
			break
print('YES' if isFind else 'NO')


a = input()

def valid(s, x, y):
	try:
		s.index(x)
		s = s.replace(x, '*', 1)
		s.index(y)
		s = s.replace(y, '*', 1)
		return True
	except:
		return False
print(('NO', 'YES')[valid(a, 'AB', 'BA') or valid(a, 'BA', 'AB')])


s = input()
print(['NO', 'YES'][s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB') > 1 and s.find('AB') >= 0 and (s.find('BA') >= 0)])


def func(str):
	s = str
	AB = False
	BA = False
	flag = False
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			AB = True
			s[i] = 'X'
			s[i + 1] = 'X'
			index = i
			flag = True
			break
	for i in range(len(s) - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			BA = True
			break
	if AB and BA:
		return True
	if flag:
		s[index] = 'A'
		s[index + 1] = 'B'
	AB = False
	BA = False
	for i in range(len(s) - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			BA = True
			s[i] = 'X'
			s[i + 1] = 'X'
			break
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			AB = True
			break
	if AB and BA:
		return True
	return False
s = list(input())
if func(s):
	print('Yes')
else:
	print('No')


def solve():
	s = input()
	(c1, c2) = (s.count('AB'), s.count('BA'))
	if c1 == 0 or c2 == 0:
		return 'NO'
	else:
		ind = s.find('AB')
		if s[ind + 2:].find('BA') != -1:
			return 'YES'
		ind = s.find('BA')
		if s[ind + 2:].find('AB') != -1:
			return 'YES'
		return 'NO'
print(solve())


s = input()
ab = False
ba = False
one = False
x = s
for i in range(len(s)):
	if s[i:i + 2] == 'AB':
		ab = True
		x = s[0:i] + s[i + 2:]
for i in range(len(x)):
	if x[i:i + 2] == 'BA':
		ba = True
if ab and ba:
	one = True
if not one:
	print('NO')
else:
	ab = False
	ba = False
	one = False
	x = s
	for i in range(len(s)):
		if s[i:i + 2] == 'BA':
			ba = True
			x = s[0:i] + s[i + 2:]
	for i in range(len(x)):
		if x[i:i + 2] == 'AB':
			ab = True
	if ab and ba:
		print('YES')
	else:
		print('NO')


str = input()
condition = False
i = 0
for i in range(0, len(str)):
	if str[i:i + 2] == 'AB':
		break
j = i + 2
for i in range(j, len(str)):
	if str[i:i + 2] == 'BA':
		condition = True
		break
if condition == True:
	print('YES')
else:
	for i in range(0, len(str)):
		if str[i:i + 2] == 'BA':
			break
	j = i + 2
	for i in range(j, len(str)):
		if str[i:i + 2] == 'AB':
			condition = True
			break
	if condition == True:
		print('YES')
	else:
		print('NO')


import re
s = input()
x = s.find('AB')
if x != -1:
	if s.find('BA', x + 2) != -1:
		print('YES')
		exit()
x = s.find('BA')
if x != -1:
	if s.find('AB', x + 2) != -1:
		print('YES')
		exit()
print('NO')


s = input()
n = len(s)
s1 = s[::-1]
count = 0
if 'AB' in s and 'AB' in s1:
	if s.index('BA') < n - 1 - s1.index('BA'):
		if s.index('BA') + 1 != n - 1 - s1.index('BA') - 1:
			count += 2
		else:
			count -= 1
	if s.index('AB') < n - 1 - s1.index('AB'):
		if s.index('AB') + 1 != n - 1 - s1.index('AB') - 1:
			count += 2
		else:
			count -= 1
	if count <= 0:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


s = input()
AB_b = False
BA_b = False
AB = []
BA = []

def f(ind, s):
	if ind > -1 and ind < len(s):
		return s[ind]
	return None
for i in range(len(s)):
	if s[i] == 'B':
		if f(i - 1, s) == 'A':
			AB_b = True
			AB.append(i - 1)
		if f(i + 1, s) == 'A':
			BA_b = True
			BA.append(i)
if AB_b and BA_b and (abs(AB[0] - BA[-1]) > 1 or abs(AB[-1] - BA[0]) > 1):
	print('YES')
else:
	print('NO')


import os
DEBUG = 'DEBUG' in os.environ

def debug(*args):
	if DEBUG:
		print('>', *args)

def solution(originalValue):
	originalLength = len(originalValue)
	value = originalValue
	value = value.replace('AB', '_', 1)
	value = value.replace('BA', '_', 1)
	value = value.replace('_', '')
	if len(value) + 4 == originalLength:
		return 'YES'
	value = originalValue
	value = value.replace('BA', '_', 1)
	value = value.replace('AB', '_', 1)
	value = value.replace('_', '')
	if len(value) + 4 == originalLength:
		return 'YES'
	return 'NO'
inputValue = input()
print(solution(inputValue))


s = input()
ab = set()
ba = set()
for i in range(len(s) - 1):
	if s[i] + s[i + 1] == 'AB':
		ab.add(i)
	elif s[i] + s[i + 1] == 'BA':
		ba.add(i)
fl = 0
if ab == set() or ba == set():
	print('NO')
	exit(0)
for s1 in (min(ab), max(ab)):
	for s2 in (min(ba), max(ba)):
		if abs(s1 - s2) > 1:
			fl = 1
if fl:
	print('YES')
else:
	print('NO')


s = input()
(ab, ba) = (s.find('AB'), s.find('BA'))
ans = False
if ab != -1 and s.find('BA', ab + 2) != -1:
	ans = True
if ba != -1 and s.find('AB', ba + 2) != -1:
	ans = True
print('YES' if ans else 'NO')


from sys import stdin, stdout
s = stdin.readline().strip()
lAB = s.find('AB')
rAB = s.rfind('AB')
lBA = s.find('BA')
rBA = s.rfind('BA')
if lAB == -1 or lBA == -1:
	stdout.write('NO')
elif lAB + 1 < rBA:
	stdout.write('YES')
elif lBA + 1 < rAB:
	stdout.write('YES')
else:
	stdout.write('NO')
stdout.write('\n')


word = input()
ab = {}
ba = {}
for i in range(len(word) - 1):
	if word[i] + word[i + 1] == 'AB':
		ab[i] = 1
	elif word[i] + word[i + 1] == 'BA':
		ba[i] = 1
f = 0
for i in ab:
	for j in ba:
		if j != i - 1 and j != i + 1:
			f = 1
			break
	if f == 1:
		break
if f == 0:
	print('NO')
else:
	print('YES')


s = input()
a = False
b = False
i = 0
while i < len(s) - 1:
	if not a and s[i:i + 2] == 'AB':
		a = True
		i += 2
	elif not b and s[i:i + 2] == 'BA':
		b = True
		i += 2
	else:
		i += 1
	if a and b:
		break
if a and b:
	print('YES')
else:
	i = 0
	a = False
	b = False
	s = s[::-1]
	while i < len(s) - 1:
		if not a and s[i:i + 2] == 'AB':
			a = True
			i += 2
		elif not b and s[i:i + 2] == 'BA':
			b = True
			i += 2
		else:
			i += 1
		if a and b:
			break
	if a and b:
		print('YES')
	else:
		print('NO')


from sys import maxsize, stdout, stdin, stderr
mod = int(1e+20 + 7)
import sys

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
import heapq
from heapq import heappop, heappush
import bisect
from itertools import groupby

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a // gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def Bs(a, x):
	i = 0
	j = 0
	left = 1
	right = x
	flag = False
	while left < right:
		mi = (left + right) // 2
		if a[mi] <= x:
			left = mi + 1
			i += 1
		else:
			right = mi
			j += 1
	if left > 0 and a[left - 1] == x:
		return (i - 1, j)
	else:
		return (-1, -1)

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a):
	print('? {}'.format(a), flush=True)
	n = I()
	return n

def dfs(i, p):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	if n > 2:
		l.append(n)
	return l
s = S()
n = len(s)
(ab, ba) = ([], [])
flag = False
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		ab.append(i + 1)
		if len(ba):
			if ba[0] != i:
				flag = True
				break
	if s[i:i + 2] == 'BA':
		ba.append(i + 1)
		if len(ab):
			if ab[0] != i:
				flag = True
				break
if flag:
	print('YES')
else:
	print('NO')


a = input()
ab = 0
ba = 0
all = 0
i = 1
while i < len(a):
	if a[i - 1] + a[i] == 'AB':
		c = 'B'
		i1 = i - 1
		while i < len(a) and a[i] == c:
			i += 1
			if c == 'B':
				c = 'A'
			else:
				c = 'B'
		ln = i - i1
		if ln == 2:
			ab += 1
		elif ln == 3 or ln == 4:
			all += 1
		else:
			all += 2
			break
	elif a[i - 1] + a[i] == 'BA':
		c = 'A'
		i1 = i - 1
		while i < len(a) and a[i] == c:
			i += 1
			if c == 'B':
				c = 'A'
			else:
				c = 'B'
		ln = i - i1
		if ln == 2:
			ba += 1
		elif ln == 3 or ln == 4:
			all += 1
		else:
			all += 2
			break
	i += 1
if bool(ab) and bool(ba) or (bool(all) and (bool(ab) or bool(ba))) or all > 1:
	print('YES')
else:
	print('NO')


s = list(input())
n = len(s)
split_place = 0
flag1 = 0
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		split_place = i
		flag1 = 1
		break
flag = 0
if flag1 == 1:
	temp_string1 = s[0:split_place]
	temp_string2 = s[split_place + 2:n]
	for i in range(len(temp_string1) - 1):
		if temp_string1[i] == 'B' and temp_string1[i + 1] == 'A':
			flag = 1
			break
	if flag == 0:
		for i in range(len(temp_string2) - 1):
			if temp_string2[i] == 'B' and temp_string2[i + 1] == 'A':
				flag = 1
				break
flag1 = 0
flagg = 0
split_place = 0
for i in range(n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		split_place = i
		flag1 = 1
		break
if flag1 == 1:
	temp_string1 = s[0:split_place]
	temp_string2 = s[split_place + 2:n]
	for i in range(len(temp_string1) - 1):
		if temp_string1[i] == 'A' and temp_string1[i + 1] == 'B':
			flagg = 1
			break
	if flagg == 0:
		for i in range(len(temp_string2) - 1):
			if temp_string2[i] == 'A' and temp_string2[i + 1] == 'B':
				flagg = 1
				break
if flag == 1 or flagg == 1:
	print('YES')
else:
	print('NO')


def overlappingStrings(s):
	(t1, t2, t3, t4) = (s.count('AB'), s.count('BA'), s.count('ABA'), s.count('BAB'))
	return 'YES' if (t1 + t2) * (t1 != 0 and t2 != 0) - t3 - t4 > 1 else 'NO'
s = input()
print(overlappingStrings(s))


a = input()
c = len(a)
(x, y, z, w) = (0, 0, 0, 0)
for i in range(c - 1):
	if a[i] == 'A' and a[i + 1] == 'B':
		x = x + 1
	if a[i] == 'B' and a[i + 1] == 'A':
		y = y + 1
for i in range(c - 2):
	if a[i] == 'A' and a[i + 1] == 'B' and (a[i + 2] == 'A'):
		z = z + 1
	if a[i] == 'B' and a[i + 1] == 'A' and (a[i + 2] == 'B'):
		w = w + 1
if x > 1 and y > 1 or (x == 1 and y > 2) or (x > 2 and y == 1):
	print('YES')
elif x > 0 and y > 0 and (w == 0) and (z == 0):
	print('YES')
elif w == 1 and z == 0:
	if x == 1 and y == 1:
		print('NO')
	else:
		print('YES')
elif z == 1 and w == 0:
	if x == 1 and y == 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


strABA = list(input())
AB = []
BA = []
lg = len(strABA)
for i in range(lg - 1):
	if strABA[i] == 'A' and strABA[i + 1] == 'B':
		AB.append(i)
	if strABA[i] == 'B' and strABA[i + 1] == 'A':
		BA.append(i)
if len(AB) * len(BA) > 0:
	if abs(AB[0] - BA[-1]) > 1 or abs(AB[-1] - BA[0]) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def printFunc(string):
	ab = []
	ba = []
	if len(string) <= 3:
		print('NO')
	else:
		for i in range(len(string) - 1):
			if string[i:i + 2] == 'AB':
				ab.append(i)
			if string[i:i + 2] == 'BA':
				ba.append(i)
		try:
			if ba[-1] - ab[0] > 1:
				print('YES')
				return
			if ab[-1] - ba[0] > 1:
				print('YES')
				return
			print('NO')
		except:
			print('NO')
string = input()
printFunc(string)


import math
s = input()
answer = 'NO'
if 'AB' in s:
	s1 = s[s.index('AB') + 2:]
	if 'BA' in s1:
		answer = 'YES'
if answer == 'NO':
	if 'BA' in s:
		s = s[s.index('BA') + 2:]
		if 'AB' in s:
			answer = 'YES'
print(answer)


def main():
	from sys import stdout
	s = input() + 'X'
	pure_AB = 0
	pure_BA = 0
	mixed = 0
	i = 0
	while i < len(s) - 1:
		substring = s[i - 1] + s[i]
		if substring == 'AB':
			if s[i + 1] == 'A':
				mixed += 1
				i += 3
			else:
				pure_AB += 1
				i += 2
		elif substring == 'BA':
			if s[i + 1] == 'B':
				mixed += 1
				i += 3
			else:
				pure_BA += 1
				i += 2
		else:
			i += 1
	if pure_AB > 0 and pure_BA > 0:
		stdout.write('YES')
	elif mixed > 0 and (pure_AB > 0 or pure_BA > 0):
		stdout.write('YES')
	elif mixed >= 2:
		stdout.write('YES')
	else:
		stdout.write('NO')
main()


s = input()
i = s.find('AB')
ans = False
if i >= 0:
	if s[i + 2:].find('BA') >= 0:
		ans = True
if ans:
	print('YES')
	exit(0)
i = s.find('BA')
if i >= 0:
	if s[i + 2:].find('AB') >= 0:
		print('YES')
	else:
		print('NO')
	exit(0)
print('NO')


x = y = input()
(s1, s2) = (x.count('AB'), x.count('BA'))
x = x.replace('AB', '11').replace('BA', '11')
y = y.replace('BA', '11').replace('AB', '11')
if s1 > 0 and s2 > 0 and (x.count('1') >= 4) and (y.count('1') >= 4):
	print('YES')
else:
	print('NO')


s = input()
ans = 1
ab = s.find('AB')
ba = s.find('BA')
if ab >= 0:
	if s.find('BA', ab + 2) >= 0:
		ans = 0
if ans and ba >= 0:
	if s.find('AB', ba + 2) >= 0:
		ans = 0
print('YNEOS'[ans % 2::2])


def take_AB(_list: [[str]]) -> bool:
	AB = False
	for i in range(len(_list) - 1):
		if not AB and _list[i][0] == 'A' and (_list[i + 1][0] == 'B'):
			_list[i][0] = 'X'
			_list[i + 1][0] = 'X'
			AB = True
	if AB:
		return True
	else:
		return False

def take_BA(_list: [[str]]) -> bool:
	BA = False
	for i in range(len(_list) - 1):
		if not BA and _list[i][0] == 'B' and (_list[i + 1][0] == 'A'):
			_list[i][0] = 'X'
			_list[i + 1][0] = 'X'
			BA = True
	if BA:
		return True
	else:
		return False
letter_list = []
dup_letter_list = []
string = input()
for i in range(len(string)):
	letter_list.append([])
	dup_letter_list.append([])
	letter_list[i].append(string[i])
	dup_letter_list[i].append(string[i])
if take_AB(letter_list) and take_BA(letter_list) or (take_BA(dup_letter_list) and take_AB(dup_letter_list)):
	print('YES')
else:
	print('NO')


a = input()
p = a.count('AB')
b = a.replace('AB', '.', 1)
q = b.count('BA')
if p > 0 and q > 0:
	y = 1
else:
	y = 0
r = a.count('BA')
c = a.replace('BA', '.', 1)
s = c.count('AB')
if r > 0 and s > 0:
	x = 1
else:
	x = 0
if x == 1 or y == 1:
	print('YES')
else:
	print('NO')


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
S = input()
N = len(S)
if N <= 3:
	print('NO')
	exit(0)
(maxab, minab, maxba, minba) = (-1, N, -1, N)
for i in range(N):
	if S[i:i + 2] == 'AB':
		maxab = max(maxab, i)
		minab = min(minab, i)
	if S[i:i + 2] == 'BA':
		maxba = max(maxba, i)
		minba = min(minba, i)
for a in [maxab, minab]:
	for b in [minba, maxba]:
		if 0 <= a < N and 0 <= b < N and (abs(a - b) > 1):
			print('YES')
			exit(0)
print('NO')


a = input()
b = len(a)
c = a.find('AB')
d = a.find('BA', c + 2)
e = a.find('BA')
f = a.find('AB', e + 2)
if c != -1 and d != -1 or (e != -1 and f != -1):
	print('YES')
else:
	print('NO')


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import *
s = read()
n = len(s)
isAB = False
isBA = False
isABA = False
isBAB = False
i = 0
while i < n - 1:
	if s[i:i + 3] == 'ABA' and (not isABA):
		isABA = True
		i += 2
	elif s[i:i + 3] == 'BAB' and (not isBAB):
		isBAB = True
		i += 2
	elif s[i:i + 2] == 'AB' and (not isAB):
		isAB = True
		i += 1
	elif s[i:i + 2] == 'BA' and (not isBA):
		isBA = True
		i += 1
	i += 1
if (isAB or isBA) and (isABA or isBAB) or (isAB and isBA) or (isABA and isBAB):
	print('YES')
else:
	print('NO')


s = input().strip()
f = False
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		for j in range(i + 2, len(s) - 1):
			if s[j] == 'B' and s[j + 1] == 'A':
				f = True
		break
for i in range(len(s) - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		for j in range(i + 2, len(s) - 1):
			if s[j] == 'A' and s[j + 1] == 'B':
				f = True
		break
if f:
	print('YES')
else:
	print('NO')


n = input()
if 'AB' not in n or 'BA' not in n:
	print('NO')
elif n.count('AB') + n.count('BA') - n.count('BAB') - n.count('ABA') > 1:
	print('YES')
else:
	print('NO')


while True:
	try:
		s = input().strip()
		if s == '':
			break
		idx_AB = []
		idx_BA = []
		for i in range(len(s)):
			if s[i:i + 2] == 'AB':
				idx_AB.append(i)
			if s[i:i + 2] == 'BA':
				idx_BA.append(i)
		flag = False
		for i in idx_AB:
			for j in idx_BA:
				if abs(i - j) >= 2:
					flag = True
					break
		if flag:
			print('YES')
		else:
			print('NO')
	except:
		break


s = input()
x = s.find('AB')
y = s.find('BA')
if x == -1 or y == -1:
	print('NO')
	exit(0)
z1 = s[:x].find('BA')
z2 = s[x + 2:].find('BA')
z3 = s[:y].find('AB')
z4 = s[y + 2:].find('AB')
if z1 == z2 and z3 == z4 and (z1 == -1):
	print('NO')
else:
	print('YES')


line = input()
ab = ba = 0
for i in range(len(line) - 1):
	if line[i] + line[i + 1] == 'AB':
		ab += 1
	elif line[i] + line[i + 1] == 'BA':
		ba += 1
if ab * ba == 0:
	print('NO')
elif ab * ba == 1 and line.count('ABA') + line.count('BAB') == 1:
	print('NO')
elif (max(ab, ba), min(ab, ba)) == (2, 1) and line.count('ABAB') + line.count('BABA') == 1:
	print('NO')
else:
	print('YES')


s = input()
flag = 0
if 'AB' in s:
	if 'BA' in s[s.index('AB') + 2:]:
		flag = 1
if 'BA' in s:
	if 'AB' in s[s.index('BA') + 2:]:
		flag = 1
if flag == 1:
	print('YES')
else:
	print('NO')


flag = 1
s = input()
if s.find('AB') != -1:
	i = s.find('AB')
	if s.find('BA', i + 2) != -1:
		print('YES')
		flag = 0
if s.find('BA') != -1 and flag == 1:
	i = s.find('BA')
	if s.find('AB', i + 2) != -1:
		print('YES')
		flag = 0
if flag == 1:
	print('NO')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
s = input()
try:
	ind = s.index('AB')
except:
	print('NO')
	exit()
if 'BA' in s[ind + 2:]:
	print('YES')
	exit()
try:
	ind = s.index('BA')
except:
	print('NO')
	exit()
if 'AB' in s[ind + 2:]:
	print('YES')
else:
	print('NO')


def simplify(seq):
	new_seq = []
	for i in range(len(seq) - 1):
		if seq[i] == 'A' or seq[i] == 'B':
			new_seq.append(seq[i])
		elif seq[i + 1] == 'A' or seq[i + 1] == 'B':
			new_seq.append(seq[i])
		else:
			continue
	new_seq.append(seq[-1])
	return ''.join(new_seq)

def is_valid(seq):
	if 'AB' in seq and 'BA' in seq:
		return True
	return False

def find_occurrence(seq, depth):
	if depth == 2:
		for i in range(len(seq)):
			if seq[i:i + 2] == 'BA':
				return True
		return False
	else:
		for i in range(len(seq)):
			if seq[i:i + 2] == 'AB':
				new_seq = seq[:i] + 'XX' + seq[i + 2:]
				found = find_occurrence(new_seq, 2)
				if found:
					return True
your_string = input()
your_string = simplify(your_string)
if is_valid(your_string):
	contains_substrings = find_occurrence(your_string, 1)
	if contains_substrings:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


string = list(input())
stringVertwo = string.copy()
points = 0
substring = []
substringVertwo = []
if len(string) > 3:
	for i in range(len(string) - 1):
		if string[i] == 'A' and string[i + 1] == 'B':
			x = string[i] + string[i + 1]
			substring.append(x)
			string[i] = ''
			string[i + 1] = ''
			break
	for n in range(len(string) - 1):
		if string[n] == 'B' and string[n + 1] == 'A':
			y = string[n] + string[n + 1]
			substring.append(y)
			break
	if 'AB' in substring and 'BA' in substring:
		print('YES')
	elif len(stringVertwo) > 4:
		for j in range(len(stringVertwo) - 1):
			if stringVertwo[j] == 'B' and stringVertwo[j + 1] == 'A':
				a = stringVertwo[j] + stringVertwo[j + 1]
				substringVertwo.append(a)
				string[j] = ''
				string[j + 1] = ''
				break
		for k in range(len(stringVertwo) - 1):
			if string[k] == 'A' and string[k + 1] == 'B':
				b = string[k] + string[k + 1]
				substringVertwo.append(b)
				break
		if 'AB' in substringVertwo and 'BA' in substringVertwo:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


s = list(input())
found1 = False
found2 = False
ABA = False
for i in range(len(s) - 2):
	if s[i] == 'A' and s[i + 2] == 'A' and (s[i + 1] == 'B') or (s[i] == 'B' and s[i + 2] == 'B' and (s[i + 1] == 'A')):
		ABA = True
		s.pop(i)
		s.pop(i)
		s.pop(i)
		break
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		s.pop(i)
		s.pop(i)
		found1 = True
		break
for i in range(len(s) - 1):
	if found1 or ABA:
		if s[i] == 'B' and s[i + 1] == 'A':
			found2 = True
			break
	else:
		break
if found1 and found2 or (found1 and ABA) or (found2 and ABA):
	print('YES')
else:
	print('NO')


st = str(input())
x = []
for i in range(len(st)):
	x.append(st[i:i + 2])
AB = []
BA = []
for i in range(len(x)):
	if x[i] == 'AB':
		AB.append(i)
	elif x[i] == 'BA':
		BA.append(i)
for i in range(len(AB)):
	for j in range(len(BA)):
		if abs(AB[i] - BA[j]) > 1:
			print('YES')
			exit()
print('NO')


mystr = input()
if 'ABA' in mystr or 'BAB' in mystr:
	if 'ABA' in mystr and 'BAB' in mystr:
		first = mystr.find('ABA') < mystr.find('BAB')
	else:
		first = mystr.find('ABA') >= 0
	subst = 'ABA' * int(first) + 'BAB' * int(not first)
	strmod = mystr.replace(subst, '', 1)
	contains = 'AB' in strmod or 'BA' in strmod
else:
	contains = 'AB' in mystr and 'BA' in mystr
print('YES' if contains else 'NO')


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(lst):
	n = len(lst)
	overlap = 0
	i = 0
	while i <= n - 1:
		if i + 2 < n and lst[i] == 'A' and (lst[i + 1] == 'B') and (lst[i + 2] == 'A'):
			overlap += 1
			i += 3
		elif i + 2 < n and lst[i] == 'B' and (lst[i + 1] == 'A') and (lst[i + 2] == 'B'):
			overlap += 1
			i += 3
		else:
			i += 1
	if overlap >= 2:
		return 'YES'
	count = [0] * 2
	i = 0
	while i < n - 1:
		if lst[i] == 'A' and lst[i + 1] == 'B':
			if i + 2 >= n or lst[i + 2] != 'A':
				count[0] += 1
				i += 2
			else:
				i += 3
		elif lst[i] == 'B' and lst[i + 1] == 'A':
			if i + 2 >= n or lst[i + 2] != 'B':
				count[1] += 1
				i += 2
			else:
				i += 3
		else:
			i += 1
	if count[0] >= 1 and count[1] >= 1:
		return 'YES'
	if overlap == 1 and count[0] + count[1] >= 1:
		return 'YES'
	return 'NO'
lst = input()
print(solve(lst))


s = input()
a = s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB')
if a >= 2 and s.count('AB') > 0 and (s.count('BA') > 0):
	print('YES')
else:
	print('NO')


s = input()
m = ''
n = ''
for x in range(len(s) - 1):
	if s[x:x + 2] == 'AB':
		m += str(x) + ' '
	else:
		pass
for y in range(1, len(s)):
	if s[y - 1:y + 1] == 'BA':
		n += str(y) + ' '
	else:
		pass
if m == '' or n == '':
	print('NO')
else:
	m = m.split()
	n = n.split()
	for x in range(len(m)):
		for y in range(len(n)):
			if m[x] != n[y] and int(m[x]) != int(n[y]) - 2:
				print('YES')
				break
			else:
				pass
		if m[x] != n[y] and int(m[x]) != int(n[y]) - 2:
			break
		elif x == len(m) - 1:
			print('NO')
		else:
			pass


s = input()
abEarly = 0
baEarly = 0
aSeen = False
bSeen = False
done = False
for i in range(len(s)):
	if baEarly > 0:
		baEarly += 1
	if abEarly > 0:
		abEarly += 1
	next = s[i]
	if next == 'A':
		if bSeen:
			baEarly += 1
			if abEarly > 2:
				done = True
		aSeen = True
		bSeen = False
	elif next == 'B':
		if aSeen:
			abEarly += 1
			if baEarly > 2:
				done = True
		bSeen = True
		aSeen = False
	else:
		aSeen = False
		bSeen = False
if done:
	print('YES')
else:
	print('NO')


import sys
r = lambda : sys.stdin.readline().rstrip()

def find_ab(n):
	for i in range(len(n) - 1):
		if n[i:i + 2] == 'AB':
			return i
	return -1

def find_ba(n):
	for i in range(len(n) - 1):
		if n[i:i + 2] == 'BA':
			return i
	return -1
n = r()
idx1 = find_ab(n)
idx2 = find_ba(n)
if idx1 != -1 and find_ba(n[idx1 + 2:]) != -1:
	print('YES')
elif idx2 != -1 and find_ab(n[idx2 + 2:]) != -1:
	print('YES')
else:
	print('NO')


a = input()
if a.find('AB') >= 0 and a[a.find('AB') + 2:].find('BA') >= 0 or (a.find('BA') >= 0 and a[a.find('BA') + 2:].find('AB') >= 0):
	print('Yes')
else:
	print('No')


s = input()
n = len(s)
(b, b1) = ([], [])
for i in range(n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		b1.append(i)
	if s[i] == 'A' and s[i + 1] == 'B':
		b.append(i)
for i in range(len(b)):
	c = 0
	if b[i] - 1 in b1:
		c += 1
	if b[i] + 1 in b1:
		c += 1
	if len(b1) > c:
		print('YES')
		exit()
print('NO')


string = str(input())
answer = 'NO'
(indexAB, indexBA) = (-1, -1)
(countAB, countBA) = (0, 0)
for i in range(2, len(string) + 1):
	sub = string[i - 2:i]
	if sub == 'AB':
		indexAB = i - 2
		countAB += 1
	if sub == 'BA':
		indexBA = i - 2
		countBA += 1
if indexAB + 1 == indexBA or indexAB == indexBA + 1:
	if countAB > 1 and countBA > 1:
		answer = 'YES'
elif countAB != 0 and countBA != 0:
	answer = 'YES'
print(answer)


s = input()
a = []
i = s.find('AB')
while i != -1:
	a += [i]
	i = s.find('AB', i + 2)
b = []
i = s.find('BA')
while i != -1:
	b += [i]
	i = s.find('BA', i + 2)
n = len(a)
m = len(b)
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) > 1:
			print('YES')
			exit()
print('NO')


s = input()
n = len(s)
flag1 = 0
flag2 = 0
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		for j in range(i + 2, n - 1):
			if s[j] == 'B' and s[j + 1] == 'A':
				flag1 = 1
				break
		break
for i in range(n - 1):
	if s[i] == 'B' and s[i + 1] == 'A':
		for j in range(i + 2, n - 1):
			if s[j] == 'A' and s[j + 1] == 'B':
				flag2 = 1
				break
		break
if flag1 or flag2:
	print('YES')
else:
	print('NO')


s = input()
a1 = s.find('AB')
a2 = s.find('BA')
a3 = s[a1 + 2:].find('BA')
a4 = s[a2 + 2:].find('AB')
if a1 >= 0 and a3 >= 0 or (a2 >= 0 and a4 >= 0):
	print('YES')
else:
	print('NO')


from sys import *
s = input()
if s.find('ABA') + 1:
	sc = s[:s.find('ABA')] + s[s.find('ABA') + 3:]
	if sc.find('AB') + 1 or sc.find('BA') + 1:
		print('YES')
		exit(0)
if s.find('BAB') + 1:
	sc = s[:s.rfind('BAB')] + s[s.rfind('BAB') + 3:]
	if sc.find('AB') + 1 or sc.find('BA') + 1:
		print('YES')
		exit(0)
if not s.find('ABA') + 1 and (not s.find('BAB') + 1):
	if s.find('AB') + 1 and s.find('BA') + 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
n = len(s)
abmishe = False
bamishe = False
abmisherev = False
bamisherev = False
cnt = 0
while cnt < n - 1:
	if not abmishe and s[cnt:cnt + 2] == 'AB':
		abmishe = True
		cnt += 1
	elif not bamishe and s[cnt:cnt + 2] == 'BA':
		bamishe = True
		cnt += 1
	cnt += 1
cnt2 = n - 1
while cnt2 > 0:
	if not bamisherev and s[cnt2 - 1:cnt2 + 1] == 'BA':
		bamisherev = True
		cnt2 -= 1
	elif not abmisherev and s[cnt2 - 1:cnt2 + 1] == 'AB':
		abmisherev = True
		cnt2 -= 1
	cnt2 -= 1
if abmishe and bamishe or (abmisherev and bamisherev):
	print('YES')
else:
	print('NO')


def compute_prefix_function(p):
	s = [0] * len(p)
	border = 0
	for i in range(1, len(p)):
		while border > 0 and p[i] != p[border]:
			border = s[border - 1]
		if p[i] == p[border]:
			border += 1
		else:
			border = 0
		s[i] = border
	return s

def kmp(p, t, sep='$'):
	S = '{}{}{}'.format(p, sep, t)
	s = compute_prefix_function(S)
	result = []
	for i in range(len(p), len(S)):
		if s[i] == len(p):
			result.append(i - 2 * len(p))
	return result

def exist_two_non_overlapping(first, second):
	if not first or not second:
		return False
	ok = False
	for i in first:
		for j in second:
			if abs(i - j) >= 2:
				return True
	return ok
word = input()
first = kmp('AB', word)
second = kmp('BA', word)
if exist_two_non_overlapping(first, second):
	print('YES')
else:
	print('NO')


from sys import exit

def func():
	s = input().strip()
	AIDX = []
	BIDX = []
	for i in range(len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			AIDX.append(i)
		if s[i] == 'B' and s[i + 1] == 'A':
			BIDX.append(i)
	if len(AIDX) == 0 or len(BIDX) == 0:
		print('NO')
		return
	if abs(min(AIDX) - min(BIDX)) > 1 or abs(max(AIDX) - min(BIDX)) > 1 or abs(max(BIDX) - min(AIDX)) > 1:
		print('YES')
	else:
		print('NO')
func()


s = input()
if 'AB' in s and 'BA' in s:
	a = s.count('AB')
	b = s.count('BA')
	x = s.count('ABA')
	y = s.count('BAB')
	if a == 1 and b == 1 and (x + y == 1):
		print('NO')
	elif a == 1 and b == 2 and (s.count('BABA') == 1):
		print('NO')
	elif a == 2 and b == 1 and (s.count('ABAB') == 1):
		print('NO')
	else:
		print('YES')
else:
	print('NO')


from bisect import bisect_right as br
s = input()
ab = []
ba = []
ans = 'NO'
for i in range(1, len(s)):
	if s[i - 1] == 'B' and s[i] == 'A':
		idx = br(ab, i - 1)
		if idx > 0 and ab[idx - 1] != i - 1 or idx > 1:
			ans = 'YES'
		ba.append(i)
	if s[i - 1] == 'A' and s[i] == 'B':
		idx = br(ba, i - 1)
		if idx > 0 and ba[idx - 1] != i - 1 or idx > 1:
			ans = 'YES'
		ab.append(i)
print(ans)


s = str(input())
a = s.find('AB')
b = s.find('BA')
print('YES' if a + 1 and s.find('BA', a + 2) + 1 or (b + 1 and s.find('AB', b + 2) + 1) else 'NO')


s = input()
abfound = bafound = -1
for i in range(len(s) - 1):
	if abfound == -1 and s[i] == 'A' and (s[i + 1] == 'B'):
		abfound = i
	elif bafound == -1 and s[i] == 'B' and (s[i + 1] == 'A'):
		bafound = i
	if abfound != -1 and bafound != -1:
		break
if abfound == -1 or bafound == -1:
	print('NO')
	exit(0)
if abfound == bafound + 1 or bafound == abfound + 1:
	for i in range(max(bafound + 2, abfound + 2), len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			newabfound = True
			print('YES')
			exit(0)
		elif s[i] == 'B' and s[i + 1] == 'A':
			newbafound = True
			print('YES')
			exit(0)
else:
	print('YES')
	exit(0)
print('NO')


s = input()
a = s.find('AB')
b = s.rfind('AB')
c = s.find('BA')
d = s.rfind('BA')
print('YNEOS'[not ((abs(a - d) > 1 or abs(b - c) > 1) and min(a, b, c, d) >= 0)::2])


import re
s = input()
if re.search('AB', s) is None or re.search('BA', s) is None:
	print('NO')
else:
	presence = re.search('AB.*BA|BA.*AB', s)
	if presence is None:
		print('NO')
	else:
		print('YES')


string = input()
temp = string
a = len(string)
string = string.replace('AB', '  ', 1)
string = string.replace('BA', '  ', 1)
string = string.replace('  ', '')
b = len(string)
if a - 4 == b:
	print('YES')
else:
	string = temp
	a = len(string)
	string = string.replace('BA', '  ', 1)
	string = string.replace('AB', '  ', 1)
	string = string.replace('  ', '')
	b = len(string)
	if a - 4 == b:
		print('YES')
	else:
		print('NO')


import string
a = input()
if 'AB' in a:
	b = a.replace('AB', '-', 1)
	if 'BA' in b:
		print('YES')
	elif 'BA' in a:
		a = a.replace('BA', '-', 1)
		if 'AB' in a:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


list1 = list(input())
pos = -1
for i in range(len(list1) - 1):
	if list1[i] == 'A':
		if list1[i + 1] == 'B':
			pos = i
			break
if pos == -1:
	print('NO')
else:
	k = 0
	for i in range(pos + 2, len(list1) - 1):
		if list1[i] == 'B':
			if list1[i + 1] == 'A':
				k = 1
				break
	if k == 1:
		print('YES')
	else:
		pos = -1
		k = 0
		for i in range(len(list1) - 1):
			if list1[i] == 'B':
				if list1[i + 1] == 'A':
					pos = i
					break
		if pos == -1:
			print('NO')
		else:
			for i in range(pos + 2, len(list1) - 1):
				if list1[i] == 'A':
					if list1[i + 1] == 'B':
						k = 1
						break
			if k == 1:
				print('YES')
			else:
				print('NO')


inputsa = input().lower()
inputs = inputsa
ab_ex = False
ba_ex = False
it = True
var1 = 'ab'
var2 = 'ba'
while 1:
	if inputs.find(var1) > -1:
		temp = inputs.find(var1)
		inputs = inputs[:temp] + '0' + inputs[temp + 2:]
		ab_ex = True
	if inputs.find(var2) > -1:
		temp = inputs.find(var2)
		inputs = inputs[:temp] + '0' + inputs[temp + 2:]
		ba_ex = True
	if ab_ex == True and ba_ex == False and (it == True):
		inputs = inputsa
		var1 = 'ba'
		var2 = 'ab'
		ab_ex = False
		it = False
		continue
	break
if ab_ex == True and ba_ex == True:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
import bisect
I = lambda : stdin.readline().strip()
read = lambda : map(int, stdin.readline().split())
s = I()
x = s.find('AB')
if x > -1:
	if s[x + 2:].find('BA') > -1:
		print('YES')
		quit()
x = s.find('BA')
if x > -1:
	if s[x + 2:].find('AB') > -1:
		print('YES')
		quit()
print('NO')
quit()
n = int(I())
s = tuple(read())
c = tuple(read())
INF = 10 ** 9
min_so_far = INF
for j in range(n):
	m1 = min([INF] + [c[i] for i in range(j) if s[i] < s[j]])
	m2 = min([INF] + [c[i] for i in range(j + 1, n) if s[i] > s[j]])
	min_so_far = min(min_so_far, c[j] + m1 + m2)
print(min_so_far if min_so_far < INF else -1)
quit()
(n, m, d) = read()
arr = []
for i in range(n):
	arr.extend(list(read()))
base = arr[0]
for i in arr:
	if (i - base) % d:
		print(-1)
		quit()
arr.sort()
s = n * m
Sum = 0
dev1 = dev2 = 0
if s % 2:
	median = arr[s // 2]
	for i in arr:
		Sum += abs(i - median)
else:
	(m1, m2) = (arr[s // 2 - 1], arr[s // 2])
	Sum2 = 0
	for i in arr:
		Sum += abs(i - m1)
		Sum2 += abs(i - m2)
	Sum = min(Sum, Sum2)
print(Sum // d)


s = input()
r = [i for i in range(len(s)) if s.startswith('AB', i)]
l = [i for i in range(len(s)) if s.startswith('BA', i)]
if len(r) and len(l) and (abs(r[len(r) - 1] - l[0]) > 1 or abs(l[len(l) - 1] - r[0]) > 1):
	print('YES')
else:
	print('NO')


s = input()
fi = s.find('AB')
sc = s.rfind('BA')
if fi == -1 or sc == -1:
	print('NO')
	exit(0)
if sc >= fi + 2:
	print('YES')
else:
	fi = s.rfind('AB')
	sc = s.find('BA')
	if fi >= sc + 2:
		print('YES')
	else:
		print('NO')


s = input()
AB = list()
BA = list()
i = 0
while s.find('AB', i, len(s)) != -1:
	AB.append(s.find('AB', i, len(s)))
	i = s.find('AB', i, len(s)) + 1
i = 0
while s.find('BA', i, len(s)) != -1:
	BA.append(s.find('BA', i, len(s)))
	i = s.find('BA', i, len(s)) + 1
if AB and BA:
	for a in AB:
		for b in BA:
			if abs(a - b) >= 2:
				print('YES')
				exit()
print('NO')


import math
s = input()
sl = len(s)
aNos = []
bNos = []
for i in range(sl - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		aNos.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		bNos.append(i)
if len(aNos) and len(bNos) and (abs(aNos[0] - bNos[-1]) >= 2 or abs(aNos[-1] - bNos[0]) >= 2):
	print('YES')
else:
	print('NO')


s = input()
AB_left = min([i if s[i:i + 2] == 'AB' else 100000000 for i in range(len(s))])
AB_right = max([i if s[i:i + 2] == 'AB' else -100000000 for i in range(len(s))])
BA_left = min([i if s[i:i + 2] == 'BA' else 100000000 for i in range(len(s))])
BA_right = max([i if s[i:i + 2] == 'BA' else -100000000 for i in range(len(s))])
print('YES' if AB_left + 1 < BA_right or BA_left + 1 < AB_right else 'NO')


s = input()
a = []
b = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		b.append(i)
if a and b and (len(a) + len(b) >= 4):
	print('YES')
elif a and b and (len(a) + len(b) == 3):
	if 'ABAB' in s:
		print('NO')
	elif 'BABA' in s:
		print('NO')
	else:
		print('YES')
elif a and b and (len(a) + len(b) == 2):
	if abs(a[0] - b[0]) >= 2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
pos = s.find('AB')
if pos < 0:
	print('NO')
	quit()
ls = [s[:pos], s[pos + 2:]]
for m in ls:
	if 'BA' in m:
		print('YES')
		quit()
pos = s.find('BA')
if pos < 0:
	print('NO')
	quit()
ls = [s[:pos], s[pos + 2:]]
for m in ls:
	if 'AB' in m:
		print('YES')
		quit()
print('NO')


from os import path
import sys, time, collections as c, math as m, pprint as p
(maxx, localsys, mod) = (float('inf'), 0, int(1000000000.0 + 7))
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
S = input()
s = S
s = s.replace('AB', '0', 1)
s = s.replace('BA', '1', 1)
if '0' in s and '1' in s:
	print('YES')
else:
	S = S.replace('BA', '1', 1)
	S = S.replace('AB', '0', 1)
	print('YES') if '1' in S and '0' in S else print('NO')


s = input()
n = len(s)
i = 0
pab = 0
pba = 0
flag = 0
while i < n:
	if s[i] == 'A' and (pab == 0 or flag == 1):
		if i + 1 < n and s[i + 1] == 'B':
			pab = 1
			if flag == 1:
				pba = 1
				break
			if i + 2 < n and s[i + 2] == 'A':
				flag = 1
			if flag == 1:
				i += 3
			else:
				i += 2
		else:
			i += 1
	elif s[i] == 'B' and (pba == 0 or flag == 1):
		if i + 1 < n and s[i + 1] == 'A':
			pba = 1
			if flag == 1:
				pab = 1
				break
			if i + 2 < n and s[i + 2] == 'B':
				flag = 1
			if flag == 1:
				i += 3
			else:
				i += 2
		else:
			i += 1
	else:
		i += 1
if pab == 1 and pba == 1:
	print('YES')
else:
	print('NO')


string1 = input()
ab = string1.count('ABA')
string = string1.replace('ABA', 'h')
ab += string.count('BAB')
string = string.replace('BAB', 'h')
a = string.count('AB')
b = string.count('BA')
if ab > 0 and ab + a + b > 1 or (a > 0 and b > 0) or 'BABAB' in string1:
	print('YES')
else:
	print('NO')


def func(s, pat1, pat2):
	if len(s) < 4:
		return False
	i1 = s.find(pat1)
	i2 = s.rfind(pat2)
	if i1 == -1 or i2 == -1:
		return False
	if max(i1 - i2, i2 - i1) > 1:
		return True
	return False
s = input()
if func(s, 'AB', 'BA') or func(s, 'BA', 'AB'):
	print('YES')
else:
	print('NO')


from collections import defaultdict, deque, Counter, OrderedDict

def main():
	s = input()
	(aba, ab, ba) = (0, 0, 0)
	curr = ''
	for c in s:
		if curr == 'AB' and c == 'A':
			aba += 1
			curr = ''
		elif curr == 'BA' and c == 'B':
			aba += 1
			curr = ''
		elif c == 'A' and curr == 'B':
			curr = 'BA'
		elif c == 'B' and curr == 'A':
			curr = 'AB'
		else:
			if curr == 'AB':
				ab += 1
			if curr == 'BA':
				ba += 1
			curr = c
	if curr == 'AB':
		ab += 1
	if curr == 'BA':
		ba += 1
	ans = ab >= 1 and ba >= 1
	ans |= ab >= 1 and ba + aba >= 1
	ans |= ab + aba >= 1 and ba >= 1
	ans |= aba >= 2
	if ans:
		print('YES')
	else:
		print('NO')
main()


a = input()
b = len(a)
c = 0
d = 0
e = 0
f = 0
g = 0
l = 0
for i in range(0, b - 1):
	if a[i] == 'A':
		if a[i + 1] == 'B':
			c = 1
			if i + 2 < b:
				if a[i + 2] == 'A':
					f = 1
	elif a[i] == 'B':
		if a[i + 1] == 'A':
			e = 1
			if i + 2 < b:
				if a[i + 2] == 'B':
					g = 1
	if c == 1:
		if f == 1:
			for j in range(i + 3, b - 1):
				if a[j] == 'B':
					if a[j + 1] == 'A':
						d = 1
						break
				elif a[j] == 'A':
					if a[j + 1] == 'B':
						d = 1
						break
				else:
					continue
			break
		else:
			for j in range(i + 2, b - 1):
				if a[j] == 'B':
					if a[j + 1] == 'A':
						d = 1
						break
				else:
					continue
			break
	if e == 1:
		if g == 1:
			for j in range(i + 3, b - 1):
				if a[j] == 'B':
					if a[j + 1] == 'A':
						d = 1
						break
				elif a[j] == 'A':
					if a[j + 1] == 'B':
						d = 1
						break
				else:
					continue
			break
		else:
			for j in range(i + 2, b - 1):
				if a[j] == 'A':
					if a[j + 1] == 'B':
						d = 1
						break
				else:
					continue
			break
	if d == 1:
		break
if d == 1:
	print('YES')
else:
	print('NO')


string = str(input())
ABindex = string.find('AB')
BAindex = string.find('BA')
if (ABindex != -1) & (string.find('BA', ABindex + 2) != -1):
	print('YES')
elif (BAindex != -1) & (string.find('AB', BAindex + 2) != -1):
	print('YES')
else:
	print('NO')


def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	S = getStr()
	(AB, BA) = ([], [])
	for j in range(len(S) - 1):
		tmp = S[j] + S[j + 1]
		if tmp == 'AB':
			AB.append(j)
		elif tmp == 'BA':
			BA.append(j)
	(LA, LB) = (len(AB), len(BA))
	if min(LA, LB) == 0:
		return 'NO'
	if LA > 1 and LB > 1:
		return 'YES'
	if LA == 1 and LB == 1:
		if abs(AB[0] - BA[0]) > 1:
			return 'YES'
		return 'NO'
	if LA == 1:
		ind = AB[0]
		for index in BA:
			if abs(index - ind) > 1:
				return 'YES'
	if LB == 1:
		ind = BA[0]
		for index in AB:
			if abs(index - ind) > 1:
				return 'YES'
	return 'NO'
ans = solve()
print(ans)


import sys
a = input()
if a.find('AB') == -1 or a.find('BA') == -1:
	print('NO')
	sys.exit()
f1 = a.find('AB')
if a.find('BA', f1 + 2, len(a)) != -1:
	print('YES')
	sys.exit()
f2 = a.find('BA')
if a.find('AB', f2 + 2, len(a)) != -1:
	print('YES')
	sys.exit()
print('NO')


s = input()
k = 0
ab = -1
ba = -1
ab = s.find('AB')
if ab != -1:
	ba = s[ab + 2:].find('BA')
	if ba != -1:
		print('YES')
	else:
		ba = s.find('BA')
		if ba != -1:
			ab = s[ba + 2:].find('AB')
			if ab != -1:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
else:
	print('NO')


s = str(input())
(temp1, temp2) = ([], [])
count = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		temp1.append(i + i + 1)
		count += 1
for i in range(len(s) - 1, 0, -1):
	if s[i] == 'A' and s[i - 1] == 'B':
		temp2.append(i - 1 + i)
		count += 1
if temp1 and temp2:
	if count >= 2:
		if temp1 == temp2:
			print('NO')
		elif len(temp1) + len(temp2) == 3:
			if sum(temp1) // 2 == sum(temp2) or sum(temp2) // 2 == sum(temp1):
				print('NO')
			else:
				print('YES')
		elif len(temp1) + len(temp2) > 3:
			print('YES')
		elif len(temp1) == 1 and len(temp2) == 1:
			if abs(temp1[0] - temp2[0]) == 2:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


s = input()
n = len(s)
cnt1 = [0] * (n - 1)
cnt2 = [0] * (n - 1)
stat = 0
if s[0:2] == 'AB':
	cnt1[0] = 1
elif s[0:2] == 'BA':
	cnt2[0] = 1
for i in range(1, n - 1):
	if s[i:i + 2] == 'BA':
		cnt2[i] = cnt2[i - 1] + 1
		if i >= 2 and cnt1[i - 2] > 0:
			stat = 1
			print('YES')
			break
	else:
		cnt2[i] = cnt2[i - 1]
	if s[i:i + 2] == 'AB':
		cnt1[i] = cnt1[i - 1] + 1
		if i >= 2 and cnt2[i - 2] > 0:
			stat = 1
			print('YES')
			break
	else:
		cnt1[i] = cnt1[i - 1]
if stat == 0:
	print('NO')


st = input()
if 'AB' in st and 'BA' in st:
	stt = st
	index = stt.index('AB')
	stt = stt[:index] + '0' + stt[index + 2:]
	if 'BA' in stt:
		print('YES')
	else:
		stt = st
		index = stt.index('BA')
		stt = stt[:index] + '0' + stt[index + 2:]
		if 'AB' in stt:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


S = input()
k1 = 0
k2 = 0
n = len(S)
c = 0
p = 0
for i in range(n - 2):
	if S[i] == 'A' and S[i + 1] == 'B' and (S[i + 2] != 'A'):
		k1 = 1
		p = i + 2
		break
	if S[i] == 'B' and S[i + 1] == 'A' and (S[i + 2] != 'B'):
		k2 = 1
		p = i + 2
		break
	if S[i] == 'B' and S[i + 1] == 'A' and (S[i + 2] == 'B'):
		k1 = 1
		k2 = 1
		p = i + 3
		c = 1
		break
	if S[i] == 'A' and S[i + 1] == 'B' and (S[i + 2] == 'A'):
		k1 = 1
		k2 = 1
		p = i + 3
		c = 1
		break
for i in range(p, n - 2):
	if S[i] == 'A' and S[i + 1] == 'B' and (S[i + 2] != 'A'):
		k1 = k1 + 1
	if S[i] == 'B' and S[i + 1] == 'A' and (S[i + 2] != 'B'):
		k2 = 1 + 1
	if S[i] == 'B' and S[i + 1] == 'A' and (S[i + 2] == 'B'):
		k1 = k1 + 1
		k2 = k2 + 1
	if S[i] == 'A' and S[i + 1] == 'B' and (S[i + 2] == 'A'):
		k1 = k1 + 1
		k2 = k2 + 1
if n >= 3 and p < n - 1:
	if S[n - 2] == 'A' and S[n - 1] == 'B' and (S[n - 3] != 'B'):
		k1 = k1 + 1
	if S[n - 2] == 'B' and S[n - 1] == 'A' and (S[n - 3] != 'A'):
		k2 = k2 + 1
	if S[n - 2] == 'A' and S[n - 1] == 'B' and (S[n - 3] == 'B'):
		k1 = k1 + 1
		k2 = k2 + 1
		c = 1
	if S[n - 2] == 'B' and S[n - 1] == 'A' and (S[n - 3] == 'A'):
		k1 = k1 + 1
		k2 = k2 + 1
		c = 1
if k1 >= 1 and k2 >= 2 and (c == 1) or (k1 >= 2 and k2 >= 1 and (c == 1)):
	print('YES')
if c == 0 and k1 >= 1 and (k2 >= 1):
	print('YES')
if c == 0 and k1 < 1 or (k2 < 1 and c == 0):
	print('NO')
if c == 1 and k1 <= 1 and (k2 < 2) or (k2 <= 1 and c == 1 and (k1 < 2)):
	print('NO')


s = input()
d = {'AB': [], 'BA': []}
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		d['AB'].append(i)
	elif s[i:i + 2] == 'BA':
		d['BA'].append(i)

def f(d):
	for i in d['AB']:
		for j in d['BA']:
			if abs(i - j) >= 2:
				return 'YES'
	return 'NO'
print(f(d))


from sys import exit
s = input()
if s.count('AB') * s.count('BA') == 0:
	print('NO')
	exit(0)
if s.count('AB') + s.count('BA') - s.count('BAB') - s.count('ABA') >= 2:
	print('YES')
else:
	print('NO')


s = input()
min_AB = len(s) + 10
max_AB = 0
min_BA = len(s) + 10
max_BA = 0
i = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		min_AB = min(min_AB, i)
		max_AB = max(max_AB, i)
	if s[i] == 'B' and s[i + 1] == 'A':
		min_BA = min(min_BA, i)
		max_BA = max(max_BA, i)
if min_AB < max_BA - 1 or min_BA < max_AB - 1:
	print('YES')
else:
	print('NO')


n1 = input()
n2 = n1
AB1 = False
BA1 = False
AB2 = False
BA2 = False
if 'AB' in n1:
	AB1 = True
	firstAB = n1.find('AB')
	n1 = n1[:firstAB] + ' ' + n1[firstAB + 2:]
	if 'BA' in n1:
		BA1 = True
if 'BA' in n2:
	BA2 = True
	firstBA = n2.find('BA')
	n2 = n2[:firstBA] + ' ' + n2[firstBA + 2:]
	if 'AB' in n2:
		AB2 = True
if AB1 == True and BA1 == True or (AB2 == True and BA2 == True):
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
w = 0
if 'AB' not in s or 'BA' not in s:
	print('NO')
else:
	arr1 = []
	arr2 = []
	for i in range(n - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			arr1.append(i)
		elif s[i] == 'B' and s[i + 1] == 'A':
			arr2.append(i)
	if arr2[-1] > arr1[0] + 1 or arr1[-1] > arr2[0] + 1:
		print('YES')
	else:
		print('NO')


s = input()
AB = []
BA = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		AB.append(i)
	elif s[i] == 'B' and s[i + 1] == 'A':
		BA.append(i)
if len(AB) >= 2 and len(BA) >= 2:
	print('YES')
elif len(AB) == 0 or len(BA) == 0:
	print('NO')
elif len(AB) == 1:
	out = 'NO'
	for i in BA:
		if i != AB[0] + 1 and i != AB[0] - 1:
			out = 'YES'
			break
	print(out)
elif len(BA) == 1:
	out = 'NO'
	for i in AB:
		if i != BA[0] + 1 and i != BA[0] - 1:
			out = 'YES'
			break
	print(out)


import sys
ab = []
ba = []

def search(txt):
	prev = txt[0]
	global ab
	global ba
	for i in range(1, len(txt)):
		cur = txt[i]
		if prev == 'A' and cur == 'B':
			ab.append(i - 1)
		if prev == 'B' and cur == 'A':
			ba.append(i - 1)
		prev = cur
txt = input()
search(txt)
for item in ab:
	for item2 in ba:
		if item2 != item + 1 and item2 != item - 1:
			print('YES')
			sys.exit()
print('NO')


s = input().strip()
ls = len(s)
flags = [0, 0]
i = 0
d = dict()
while i < ls - 1:
	if s[i:i + 2] == 'AB':
		if 'AB' in d:
			d['AB'] += [i]
		else:
			d['AB'] = [i]
	elif s[i:i + 2] == 'BA':
		if 'BA' in d:
			d['BA'] += [i]
		else:
			d['BA'] = [i]
	else:
		pass
	i += 1
s1 = {}
s2 = {}
if 'AB' in d:
	s1 = set(d['AB'])
if 'BA' in d:
	s2 = set(d['BA'])
if len(s1) > 0 and len(s2) > 0:
	if max(s2) - min(s1) > 1 or max(s1) - min(s2) > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
a = s.find('AB')
b = s.find('BA')
f = 0
if a != -1 and s.find('BA', a + 2) != -1 or (b != -1 and s.find('AB', b + 2) != -1):
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
i = 0
sa = s
nk = 0
while i < n - 1:
	if s[i] == 'A' and s[i + 1] == 'B':
		s = s[0:i] + 'D' + s[i + 2:]
		if 'BA' in s:
			print('YES')
			nk = 1
			break
		else:
			break
	i += 1
if nk == 0:
	i = 0
	s = sa
	nk = 0
	while i < n - 1:
		if s[i] == 'B' and s[i + 1] == 'A':
			s = s[0:i] + 'D' + s[i + 2:]
			if 'AB' in s:
				print('YES')
				nk = 1
				break
			else:
				break
		i += 1
	if nk == 0:
		print('NO')


from sys import stdin
input = stdin.readline

def substr(s):
	b = b2 = c = c2 = -2
	for ptr in range(len(s) - 1):
		if s[ptr] == 'A':
			if s[ptr + 1] == 'B':
				if 0 <= c < ptr - 1 or 0 <= c2 < ptr - 1:
					return 'YES'
				elif b == -2:
					b = ptr
				else:
					b2 = ptr
		if s[ptr] == 'B':
			if s[ptr + 1] == 'A':
				if 0 <= b < ptr - 1 or 0 <= b2 < ptr - 1:
					return 'YES'
				elif c == -2:
					c = ptr
				else:
					c2 = ptr
		ptr += 1
	return 'NO'
print(substr(input().strip()))


s = input()
lab = s.find('AB')
rab = s.rfind('AB')
lba = s.find('BA')
rba = s.rfind('BA')
print(['NO', 'YES'][(abs(lab - rba) > 1 or abs(rab - lba) > 1) and min(lab, rab, lba, rba) >= 0])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	s = [c for c in S()]
	t = []
	u = []
	for i in range(len(s) - 1):
		if s[i] == 'A':
			if s[i + 1] == 'B':
				t.append(i)
		elif s[i] == 'B':
			if s[i + 1] == 'A':
				u.append(i)
	for c in t:
		for d in u:
			if abs(c - d) > 1:
				return 'YES'
	return 'NO'
print(main())


s = input()
(a, b) = (list(), list())
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		a.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		b.append(i)
if len(a) == 0 or len(b) == 0:
	print('NO')
else:
	f = 0
	for i in a:
		for j in b:
			if i - 1 != j and i + 1 != j:
				f = 1
				break
		if f == 1:
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


str = input()
ab = []
ba = []
for i in range(len(str) - 1):
	if str[i] == 'A' and str[i + 1] == 'B':
		ab.append(i)
	if str[i] == 'B' and str[i + 1] == 'A':
		ba.append(i)
for i in range(len(ab)):
	for j in range(len(ba)):
		if abs(ab[i] - ba[j]) > 1:
			print('YES')
			break
	else:
		continue
	break
else:
	print('NO')


s = input()
(k, x) = (s, 1)
if 'AB' in s:
	s = s.replace('AB', ' ', 1)
	if 'BA' in s:
		x = 0
s = k
if 'BA' in s:
	s = s.replace('BA', ' ', 1)
	if 'AB' in s:
		x = 0
print('YNEOS'[x::2])


def two_substring(string):
	AB = []
	BA = []
	for i in range(len(string)):
		if string[i] == 'A' and i < len(string) - 1:
			if string[i + 1] == 'B':
				AB.append([i, i + 1])
		elif string[i] == 'B' and i < len(string) - 1:
			if string[i + 1] == 'A':
				BA.append([i, i + 1])
	if len(AB) == 0 or len(BA) == 0:
		return 'no'
	for i in range(len(AB)):
		for j in range(len(BA)):
			if AB[i][0] == BA[j][1] or AB[i][1] == BA[j][0]:
				continue
			else:
				return 'yes'
	return 'no'
string = input().strip()
print(two_substring(string))


s = input()
if 'AB' in s and 'BA' in s:
	if s.count('A') == 2 and s.count('B') == 2:
		if s.count('AABB') != 0 or s.count('ABAB') != 0 or s.count('BBAA') != 0 or s.count('BABA') or s.count('AABB'):
			print('NO')
		else:
			print('YES')
	elif s.count('AB') > 1 or s.count('BA') > 1:
		print('YES')
	elif 'ABA' not in s and 'BAB' not in s:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
x = len(s)
i = 0
t = ''
l = ''
done = 0
a = -1
b = -1
while i < x - 1:
	if s[i] == 'A':
		if s[i + 1] == 'B':
			if b != i:
				if len(l) != 0:
					if l[0] == 'B' and l[1] == 'A':
						done = 1
						break
			if len(t) == 0:
				t += 'AB'
				a = i + 1
	elif s[i] == 'B':
		if s[i + 1] == 'A':
			if a != i:
				if len(t) != 0:
					if t[0] == 'A' and t[1] == 'B':
						done = 1
						break
			if len(l) == 0:
				l += 'BA'
				b = i + 1
	i += 1
if done == 1:
	print('YES')
else:
	print('NO')


s = str(input())
i = 0
flag = False
if s.count('AB') != 0:
	h = s.index('AB')
	for i in range(h + 2, len(s) - 1):
		if s[i] + s[i + 1] == 'BA':
			flag = True
if s.count('BA') != 0:
	h = s.index('BA')
	for i in range(h + 2, len(s) - 1):
		if s[i] + s[i + 1] == 'AB':
			flag = True
if flag:
	print('YES')
else:
	print('NO')


def f(s):
	(ab, ba) = (0, 0)
	(last_ab, last_ba) = (-1, -1)
	n = len(s)
	for i in range(n):
		if s[i] == 'B' and (i > 0 and s[i - 1] == 'A'):
			j = i - 1
			ab += 1
			if ba > 1 or (last_ba >= 0 and last_ba != j - 1):
				return 'YES'
			last_ab = j
		if s[i] == 'B' and (i + 1 < n and s[i + 1] == 'A'):
			ba += 1
			if ab > 1 or (last_ab >= 0 and last_ab != i - 1):
				return 'YES'
			last_ba = i
	return 'NO'
assert f('BAB') == 'NO'
assert f('ABABAB') == 'YES'
assert f('BABABA') == 'YES'
assert f('ABA') == 'NO'
assert f('BACFAB') == 'YES'
assert f('AXBYBXA') == 'NO'
assert f('ABAXXXAB') == 'YES'
s = input()
ans = f(s)
print(ans)


s = input()
ab = 0
ba = 0
aba = 0
bab = 0
n = len(s)
if n < 4:
	print('NO')
else:
	for i in range(n - 1):
		if s[i:i + 2] == 'AB':
			ab += 1
	for i in range(n - 1):
		if s[i:i + 2] == 'BA':
			ba += 1
	for i in range(n - 2):
		if s[i:i + 3] == 'ABA':
			aba += 1
	for i in range(n - 2):
		if s[i:i + 3] == 'BAB':
			bab += 1
	if ab == 0 or ba == 0:
		print('NO')
	elif ab == 1 and ba == 1:
		if bab == 1 or aba == 1:
			print('NO')
		else:
			print('YES')
	elif ab == 1 and ba == 2:
		if bab == 1 and aba == 1:
			print('NO')
		else:
			print('YES')
	elif ab == 2 and ba == 1:
		if bab == 1 and aba == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


s = input()
ss = s
s = s.replace('AB', 'x', 1)
s = s.replace('BA', 'y', 1)
ss = ss.replace('BA', 'y', 1)
ss = ss.replace('AB', 'x', 1)
if 'x' in s and 'y' in s:
	print('YES')
elif 'x' in ss and 'y' in ss:
	print('YES')
else:
	print('NO')


import math
from collections import defaultdict
from heapq import heappush, heappop
from decimal import Decimal, getcontext

def solve(arr):
	ab_ints = []
	ba_ints = []
	for i in range(len(arr) - 1):
		if arr[i] == 'A' and arr[i + 1] == 'B':
			ab_ints.append((i, i + 1))
	for i in range(len(arr) - 1):
		if arr[i] == 'B' and arr[i + 1] == 'A':
			ba_ints.append((i, i + 1))
	for ab in ab_ints:
		for ba in ba_ints:
			if ab[0] != ba[0] and ab[0] != ba[1] and (ab[1] != ba[0]) and (ab[1] != ba[1]):
				print('YES')
				return
	print('NO')
arr = list(input())
solve(arr)


s = input()
ab = 0
ba = 0
i = 0
for i in range(len(s) - 1):
	if i != len(s) - 1:
		if s[i] == 'A' and s[i + 1] == 'B':
			ab += 1
			break
for j in range(i + 2, len(s) - 1):
	if j != len(s) - 1:
		if s[j] == 'B' and s[j + 1] == 'A':
			ba += 1
			break
if ab >= 1 and ba >= 1:
	print('YES')
else:
	ab = 0
	ba = 0
	i = 0
	for i in range(len(s) - 1):
		if i != len(s) - 1:
			if s[i] == 'B' and s[i + 1] == 'A':
				ba += 1
				break
	for j in range(i + 2, len(s) - 1):
		if j != len(s) - 1:
			if s[j] == 'A' and s[j + 1] == 'B':
				ab += 1
				break
	if ab >= 1 and ba >= 1:
		print('YES')
	else:
		print('NO')


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
sys.setrecursionlimit(10 ** 4)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	if n == 1:
		return 1
	cnt = 2
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != n // i:
				cnt += 2
			else:
				cnt += 1
	return cnt

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	s = I().strip()
	ab = []
	ba = []
	i = 0
	while i < len(s) - 1:
		if s[i:i + 2] == 'AB':
			ab.append(i + 1)
		elif s[i:i + 2] == 'BA':
			ba.append(i + 1)
		i += 1
	if len(ab) == 0 or len(ba) == 0:
		print('NO')
	elif abs(ba[-1] - ab[0]) > 1:
		print('YES')
	elif abs(ba[0] - ab[-1]) > 1:
		print('YES')
	else:
		print('NO')
main()


s = input()
ans = False
ab = False
ba = False
n = len(s)
i = 0
while i < n - 1:
	if ab == False:
		if s[i] == 'A' and s[i + 1] == 'B':
			ab = True
			i += 1
	elif s[i] == 'B' and s[i + 1] == 'A':
		ba = True
	i += 1
if ab and ba:
	ans = True
ab = False
ba = False
i = 0
while i < n - 1:
	if ba == False:
		if s[i] == 'B' and s[i + 1] == 'A':
			ba = True
			i += 1
	elif s[i] == 'A' and s[i + 1] == 'B':
		ab = True
	i += 1
if ab and ba:
	ans = True
if ans:
	print('YES')
else:
	print('NO')


a = input()
c = []
d = []
for i in range(len(a) - 1):
	if a[i] + a[i + 1] == 'AB':
		c.append(i)
	elif a[i] + a[i + 1] == 'BA':
		d.append(i)
if len(c) >= 1 and len(d) >= 1:
	for i in c:
		for e in d:
			if abs(e - i) > 1:
				print('YES')
				quit()
	print('NO')
else:
	print('NO')


string = input()
a = string.count('AB')
b = string.count('BA')
c = string.count('ABA')
d = string.count('BAB')
ans = a + b - c - d
if a == 0 or b == 0:
	print('NO')
	exit()
print('YES' if ans > 1 else 'NO')


a = input()
flag = 0
i = 0
n = len(a)
while i < n - 1:
	if a[i] == 'A' and a[i + 1] == 'B':
		i += 2
		while i < n - 1:
			if a[i] == 'B' and a[i + 1] == 'A':
				flag = 1
				break
			i += 1
	i += 1
i = 0
while i < n - 1:
	if a[i] == 'B' and a[i + 1] == 'A':
		i += 2
		while i < n - 1:
			if a[i] == 'A' and a[i + 1] == 'B':
				flag = 1
				break
			i += 1
	i += 1
if flag == 1:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
c = 0
i = 0
while i < n - 1:
	if s[i] == 'A' and s[i + 1] == 'B':
		c += 1
		i += 2
		break
	else:
		i += 1
for j in range(i, n - 1):
	if s[j] == 'B' and s[j + 1] == 'A':
		c += 1
		break
ii = 0
d = 0
while ii < n - 1:
	if s[ii] == 'B' and s[ii + 1] == 'A':
		d += 1
		ii += 2
		break
	else:
		ii += 1
for jj in range(ii, n - 1):
	if s[jj] == 'A' and s[jj + 1] == 'B':
		d += 1
		break
if c % 2 == 0 or d % 2 == 0:
	if d % 2 == 0 and d != 0:
		print('YES')
	elif c % 2 == 0 and c != 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


a = input()
c = a[:]
k = a.find('BA')
o = 0
oz = 0
if k != -1:
	a = a[k + 2:]
	k1 = a.find('AB')
	if k1 != -1:
		o = 1
kk = c.find('AB')
if kk != -1:
	a = c[kk + 2:]
	kk1 = a.find('BA')
	if kk1 != -1:
		oz = 1
if o == 1 or oz == 1:
	print('YES')
else:
	print('NO')


def findAB(s):
	ab = s.find('AB')
	ba = s.rfind('BA')
	if ab == -1 or ba == -1:
		return False
	if ab + 1 < ba:
		return True
	ba = s.find('BA')
	ab = s.rfind('AB')
	if ba + 1 < ab:
		return True
	return False
if findAB(input()):
	print('YES')
else:
	print('NO')


substring = input()[0:]
subtext = ''
ab = 0
ba = 0
aba = 0
contain = False
for i in range(0, len(substring)):
	if len(subtext) >= 3:
		aba += 1
		subtext = ''
	if subtext == '':
		if substring[i] == 'A' or substring[i] == 'B':
			subtext += substring[i]
			continue
	if substring[i] == 'A' or substring[i] == 'B':
		if substring[i] != substring[i - 1]:
			subtext += substring[i]
		else:
			if subtext == 'AB':
				ab = 1
			elif subtext == 'BA':
				ba = 1
			subtext = substring[i]
		continue
	if subtext == 'AB':
		ab = 1
	elif subtext == 'BA':
		ba = 1
	elif len(subtext) >= 3:
		aba += 1
	subtext = ''
	if ab + ba + aba > 1:
		contain = True
		break
if subtext == 'AB':
	ab = 1
elif subtext == 'BA':
	ba = 1
elif len(subtext) >= 3:
	aba += 1
if ab + ba + aba > 1:
	contain = True
if contain:
	print('YES')
else:
	print('NO')


s = str(input())
suc = 0
suc2 = 0
k = [0]
j = [0]
if 'AB' in s:
	suc += 1
	k = s.replace('AB', 'DD', 1)
if 'BA' in k:
	suc += 1
if suc == 2:
	print('YES')
else:
	if 'BA' in s:
		suc2 += 1
		j = s.replace('BA', 'DD', 1)
	if 'AB' in j:
		suc2 += 1
	if suc2 == 2:
		print('YES')
	else:
		print('NO')


s = input()
s = s.upper()
l = s.find('AB')
m = s.find('BA')
if l != -1 and s.find('BA', l + 2) != -1:
	print('YES')
elif m != -1 and s.find('AB', m + 2) != -1:
	print('YES')
else:
	print('NO')


x = input()
y1 = x.find('AB')
y2 = x.find('BA')
flag = 0
if y1 >= 0:
	y3 = x.find('BA', y1 + 2)
	if y3 >= 0:
		flag = 1
if flag == 0 and y2 >= 0:
	y4 = x.find('AB', y2 + 2)
	if y4 >= 0:
		flag = 1
if flag == 1:
	print('YES')
else:
	print('NO')


s = input()
s = list(s)
ab = []
ba = []
n = len(s)
for i in range(len(s)):
	if i + 1 < n and s[i] == 'A' and (s[i + 1] == 'B'):
		ab.append(i)
	if i + 1 < n and s[i] == 'B' and (s[i + 1] == 'A'):
		ba.append(i)
if len(ab) == 0 or len(ba) == 0:
	print('NO')
elif abs(ab[0] - ba[len(ba) - 1]) > 1 or abs(ab[len(ab) - 1] - ba[0]) > 1:
	print('YES')
else:
	print('NO')


import math
import operator as op
from functools import reduce
from fractions import Fraction as frac
s = input('')
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		if 'BA' in s[i + 2:]:
			print('YES')
			exit()
	if s[i:i + 2] == 'BA':
		if 'AB' in s[i + 2:]:
			print('YES')
			exit()
print('NO')


string = list(input())
n = len(string)
i = 0
checkAB = []
checkBA = []
while i < n - 1:
	if string[i] == 'A' and string[i + 1] == 'B':
		checkAB.append([i, i + 1])
	elif string[i] == 'B' and string[i + 1] == 'A':
		checkBA.append([i, i + 1])
	i += 1
check = False
for x in checkAB:
	for y in checkBA:
		if x[0] not in y and x[1] not in y:
			check = True
			break
if check:
	print('YES')
else:
	print('NO')


import sys
s = input()
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == 'AB':
		i += 2
		while i < len(s) - 1:
			if s[i:i + 2] == 'BA':
				print('YES')
				sys.exit()
			i += 1
	i += 1
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == 'BA':
		i += 2
		while i < len(s) - 1:
			if s[i:i + 2] == 'AB':
				print('YES')
				sys.exit()
			i += 1
	i += 1
print('NO')


import re
mystr = input()
indexOFB = []
count = 0
tempsaleem = mystr.find('AB')
tempreverse = mystr.rfind('AB')
if tempsaleem != -1 and tempsaleem != tempreverse:
	tempstr1 = mystr.find('BA', 0, tempsaleem)
	tempstr2 = mystr.find('BA', tempsaleem + 2)
	tempstr3 = mystr.find('BA', 0, tempreverse)
	tempstr4 = mystr.find('BA', tempreverse + 2)
	if tempstr1 != -1 or tempstr2 != -1 or tempstr3 != -1 or (tempstr4 != -1):
		print('YES')
	else:
		print('NO')
elif tempsaleem != -1:
	tempstr1 = mystr.find('BA', 0, tempsaleem)
	tempstr2 = mystr.find('BA', tempsaleem + 2)
	if tempstr1 != -1 or tempstr2 != -1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


x = input()
ba = x.rfind('BA')
bar = x.find('BA')
ab = x.find('AB')
abr = x.rfind('AB')
if abs(ab - ba) >= 2 and ab != -1 and (ba != -1) or (abs(ab - bar) >= 2 and ab != -1 and (bar != -1)) or (abs(ba - abr) >= 2 and ba != -1 and (abr != -1)) or (abs(abr - bar) >= 2 and abr != -1 and (bar != -1)):
	print('YES')
else:
	print('NO')


def pos_ab(s, direction):
	if direction is True:
		for i in range(len(s) - 1):
			if 'AB' == s[i:i + 2]:
				return i + 1
	else:
		ql = len(s) - 1
		for i in range(ql):
			if 'AB' == s[ql - i - 1:ql - i + 1]:
				return ql - i - 1
	return None

def pos_ba(s, k, direction):
	if direction is True:
		for i in range(k + 1, len(s) - 1):
			if 'BA' == s[i:i + 2]:
				return i + 1
	else:
		for i in range(k):
			if 'BA' == s[k - i - 2:k - i]:
				return k
	return None
S = input()
if not pos_ab(S, True) is None:
	if not pos_ba(S, pos_ab(S, True), True) is None:
		print('Yes')
	elif not pos_ab(S, False) is None:
		if pos_ba(S, pos_ab(S, False), False) is None:
			print('No')
		else:
			print('Yes')
else:
	print('No')


s = input()
(left, right) = (s.find('AB'), s.rfind('BA'))
(left1, right1) = (s.find('BA'), s.rfind('AB'))
(r1, r2) = (abs(left - right), abs(left1 - right1))
if left < 0 or right < 0:
	print('NO')
elif r1 + r2 == 2:
	print('NO')
else:
	print('YES')


s = input()
ab = 0
ba = 0
n = len(s)
for i in range(1, n):
	if s[i] == 'A' and s[i - 1] == 'B':
		ba += 1
	elif s[i] == 'B' and s[i - 1] == 'A':
		ab += 1
if ab == 0 or ba == 0:
	print('NO')
elif ab == 1 and ba == 1:
	if 'ABA' in s:
		print('NO')
	elif 'BAB' in s:
		print('NO')
	else:
		print('YES')
elif ab == 1 and ba == 2:
	if 'BABA' in s:
		print('NO')
	else:
		print('YES')
elif ba == 1 and ab == 2:
	if 'ABAB' in s:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


s = input()
if 'AB' in s and 'BA' in s:
	s1 = s.replace('AB', '*', 1)
	s2 = s.replace('BA', '*', 1)
	if 'BA' in s1:
		print('YES')
	elif 'AB' in s2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
if s.find('AB') == -1 or s.find('BA') == -1:
	print('NO')
	exit()

def func(a, b):
	idx = s.find(a)
	if s[idx + 2:].find(b) != -1:
		return True
if func('AB', 'BA') or func('BA', 'AB'):
	print('YES')
else:
	print('NO')


def method(a, string):
	count = a.count(string)
	a = a.replace(string, ' ', 1)
	count *= a.count(string[::-1])
	return count

def find_str(a):
	count = method(a, 'AB')
	if count:
		return 'YES'
	else:
		count = method(a, 'BA')
	return 'YES' if count else 'NO'
a = input()
print(find_str(a))


def solve():
	(ins, used, ab, ba) = (input(), [], 0, 0)
	uppend = used.append
	for i in range(len(ins)):
		uppend(0)
	for i in range(len(ins) - 1):
		if not ab and ins[i] == 'A' and (ins[i + 1] == 'B') and (not used[i]):
			(ab, used[i], used[i + 1]) = (1, 1, 1)
		if ab and ins[i] == 'B' and (ins[i + 1] == 'A') and (not used[i]):
			(ba, used[i], used[i + 1]) = (1, 1, 1)
			break
	if ba:
		print('YES')
		return 0
	(ab, ba) = (0, 0)
	for i in range(len(used)):
		used[i] = 0
	for i in range(len(ins) - 1):
		if not ba and ins[i] == 'B' and (ins[i + 1] == 'A') and (not used[i]):
			(ba, used[i], used[i + 1]) = (1, 1, 1)
		if ba and ins[i] == 'A' and (ins[i + 1] == 'B') and (not used[i]):
			(ab, used[i], used[i + 1]) = (1, 1, 1)
			break
	if ab:
		print('YES')
		return 0
	print('NO')
solve()


s = input()
l = []
cnt = 0
for i in range(len(s) - 1):
	l.append(s[i] + s[i + 1])
n = -10
m = -10
n1 = 1000000
m1 = 1000000
cnt = 0
va = 0
if 'AB' not in l or 'BA' not in l:
	print('NO')
else:
	for i in range(len(l) - 1):
		if l[i] == 'AB':
			m = i
			break
		elif l[i] == 'BA':
			n = i
			break
	for i in range(len(l) - 1, -1, -1):
		if l[i] == 'AB':
			m = i
			break
		elif l[i] == 'BA':
			n = i
			break
	if n > m:
		for i in range(len(l)):
			if l[i] == 'AB':
				if abs(n - i) >= 2:
					print('YES')
					va = 1
					break
		else:
			cnt = 1
	elif n1 < m1 and va != 1:
		for i in range(len(l) - 1, -1, -1):
			if l[i] == 'AB':
				if abs(n - i) >= 2:
					print('YES')
					break
		else:
			cnt = 1
	if m > n:
		for i in range(len(l)):
			if l[i] == 'BA':
				if abs(m - i) >= 2:
					print('YES')
					va = 1
					break
		else:
			cnt = 1
	elif m1 < n1 and va != 1:
		for i in range(len(l) - 1, -1, -1):
			if l[i] == 'BA':
				if abs(m - i) >= 2:
					print('YES')
					break
		else:
			cnt = 1
	if cnt == 1:
		print('NO')


def containsNonOverlappingABandBA(string):
	ABp = string.find('AB')
	if ABp == -1:
		return False
	BAp = string.find('BA')
	if BAp == -1:
		return False
	if abs(ABp - BAp) > 1:
		return True
	return string.find('BA', ABp + 2) != -1 or string.find('AB', BAp + 2) != -1
print('YES' if containsNonOverlappingABandBA(input()) else 'NO')


a = input()
b = 0
d = 0
c = []
f = []
i = 0
while i < len(a) - 1:
	if a[i] == 'B' and a[i + 1] == 'A':
		f.append([i, i + 1])
		d += 1
	if a[i] == 'A' and a[i + 1] == 'B':
		c.append([i, i + 1])
		b += 1
	i += 1
	if b > 2 and d >= 1 or (b >= 1 and d > 2) or (b >= 2 and d >= 2):
		i = len(a) + 5
		print('YES')
if i != len(a) + 5:
	for i in c:
		for j in f:
			if i[0] != j[0] and i[0] != j[1] and (i[1] != j[0]) and (i[1] != j[1]):
				print('YES')
				i = -2
				break
			if i == -2:
				break
		if i == -2:
			break
	if i != -2:
		print('NO')


def solve_wa():
	s = input()
	z = [False for c in s]
	n = len(s)
	if n < 4:
		print('NO')
		return
	for i in range(n - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			z[i] = True
			z[i + 1] = True
	for i in range(n - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			if not z[i] and (not z[i + 1]):
				print('YES')
				return
	print('NO')

def find(t, s, n):
	for i in range(n - 1):
		if s[i] == t[0] and s[i + 1] == t[1]:
			for j in range(i + 2, n - 1):
				if s[j] == t[1] and s[j + 1] == t[0]:
					return True
			return False
	return False

def solve():
	s = input()
	n = len(s)
	if n < 4:
		print('NO')
		return
	x = find('AB', s, n)
	y = find('BA', s, n)
	print('YES' if x or y else 'NO')
solve()


s = input()
p = s.find('AB')
if p + 1:
	if s.find('BA', p + 2) + 1:
		print('YES')
		exit()
p = s.find('BA')
if p + 1:
	if s.find('AB', p + 2) + 1:
		print('YES')
		exit()
print('NO')


s = input()
ans = False
find1 = s.find('AB')
find2 = s.find('BA')
if find1 != -1:
	if s.find('BA', find1 + 2) != -1:
		ans = True
if find2 != -1:
	if s.find('AB', find2 + 2) != -1:
		ans = True
if ans:
	print('YES')
else:
	print('NO')
import sys
sys.exit(0)


def solve():
	m = [[[False for _ in range(2)] for _ in range(2)] for _ in range(n + 1)]
	for i in range(n, -1, -1):
		for ab in [0, 1]:
			for ba in [0, 1]:
				if i >= n - 1:
					m[i][ab][ba] = True if ab == ba == 1 else False
				else:
					x = m[i + 1][ab][ba]
					if s[i:i + 2] == 'AB':
						m[i][ab][ba] = m[i + 2][1][ba] or x
					elif s[i:i + 2] == 'BA':
						m[i][ab][ba] = m[i + 2][ab][1] or x
					else:
						m[i][ab][ba] = x
	return 'YES' if m[0][0][0] else 'NO'

def main():
	global s, n
	s = input()
	n = len(s)
	print(solve())
main()


str = input()
ab1 = ab2 = ba1 = ba2 = -1
for i in range(1, len(str)):
	if str[i - 1] == 'A' and str[i] == 'B':
		if ab1 == -1:
			ab1 = i
		ab2 = i
	if str[i - 1] == 'B' and str[i] == 'A':
		if ba1 == -1:
			ba1 = i
		ba2 = i
if ab1 == -1 or ba1 == -1 or (not (ba2 - ab1 >= 2 or ab2 - ba1 >= 2)):
	print('NO')
else:
	print('YES')


a = input()
p1 = a.find('AB')
p2 = a.find('BA')
p3 = a.rfind('AB')
p4 = a.rfind('BA')
if p1 == -1 or p2 == -1:
	print('NO')
elif abs(p1 - p4) != 1 or abs(p2 - p3) != 1:
	print('YES')
else:
	print('NO')


s = input()
s1 = s.find('AB')
s2 = s.find('BA', s1 + 2)
s3 = s.find('BA')
s4 = s.find('AB', s3 + 2)
if s1 >= 0 and s2 >= 0 or (s3 >= 0 and s4 >= 0):
	print('YES')
else:
	print('NO')


s = input().strip()
n = len(s)
T = False
if s[:2] == 'AB' or s[:2] == 'BA':
	h = 1
k = []
h = []
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		k.append(i)
	if s[i:i + 2] == 'BA':
		h.append(i)
if len(k) > 1 and len(h) > 1:
	print('YES')
elif len(h) == 0 or len(k) == 0:
	print('NO')
elif len(h) == 1 or len(k) == 1:
	if abs(h[-1] - k[-1]) == 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


s = input()
fl = False
t = s.find('BA')
if t != -1:
	x = s[t + 2:]
	if x.find('AB') != -1:
		fl = True
t = s.find('AB')
if t != -1:
	x = s[t + 2:]
	if x.find('BA') != -1:
		fl = True
if fl:
	print('YES')
else:
	print('NO')


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
t = 1
for i in range(t):
	s = read_line()
	cnt1 = 0
	cnt2 = 0
	i = 0
	while i < len(s) - 1:
		if s[i] == 'A' and cnt1 < 1:
			if s[i + 1] == 'B':
				cnt1 += 1
				i += 2
				break
			else:
				i += 1
		else:
			i += 1
	while i < len(s) - 1:
		if s[i] == 'B' and cnt2 < 1:
			if s[i + 1] == 'A':
				cnt2 += 1
				i += 2
				break
			else:
				i += 1
		else:
			i += 1
	cnt3 = 0
	cnt4 = 0
	i = 0
	while i < len(s) - 1:
		if s[i] == 'B' and cnt3 < 1:
			if s[i + 1] == 'A':
				cnt3 += 1
				i += 2
				break
			else:
				i += 1
		else:
			i += 1
	while i < len(s) - 1:
		if s[i] == 'A' and cnt4 < 1:
			if s[i + 1] == 'B':
				cnt4 += 1
				i += 2
				break
			else:
				i += 1
		else:
			i += 1
	if cnt1 > 0 and cnt2 > 0 or (cnt3 > 0 and cnt4 > 0):
		print('YES')
	else:
		print('NO')


import re
s = input()
ab = s.find('AB')
ba = s.find('BA')
print('NYOE S'[(ab > -1 and s.find('BA', ab + 2) > -1 or s.find('BA', 0, max(0, ab - 1)) > -1) or (ba > -1 and s.find('AB', ba + 2) > -1 or s.find('AB', 0, max(0, ba - 1)) > -1)::2])


def NotOverlap(i, y, z, x):
	d = set()
	d.add(i)
	d.add(y)
	d.add(z)
	d.add(x)
	if len(d) == 4:
		return True
	return False
n = input()
(A, B, BAs, ABs) = (0, 0, [], [])
for i in range(len(n) - 1):
	if n[i] == 'A' and n[i + 1] == 'B':
		ABs.append((i, i + 1))
	elif n[i] == 'B' and n[i + 1] == 'A':
		BAs.append((i, i + 1))
overlap = False
if BAs != [] or ABs != []:
	for i in ABs:
		for j in BAs:
			if NotOverlap(i[0], i[1], j[0], j[1]):
				overlap = True
				break
if overlap:
	print('YES')
else:
	print('NO')


s = input().strip()
abIndices = []
baIndices = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		abIndices.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		baIndices.append(i)
if len(abIndices) == 0 or len(baIndices) == 0:
	print('NO')
elif baIndices[-1] - abIndices[0] > 1 or abIndices[-1] - baIndices[0] > 1:
	print('YES')
else:
	print('NO')


s = str(input())
n = len(s)
A = []
B = []
for i in range(n - 1):
	if s[i:i + 2] == 'AB':
		A += [i]
	if s[i:i + 2] == 'BA':
		B += [i]
ok = 0
for a in A:
	for b in B:
		if abs(a - b) > 1:
			print('YES')
			ok = 1
			break
	if ok:
		break
if ok == 0:
	print('NO')


from __future__ import print_function
import sys
from collections import *
from heapq import *
INF = float('inf')
NINF = float('-inf')
try:
	input = raw_input
except:
	pass

def read_string():
	return input()

def read_int_line():
	return [int(x) for x in input().split(' ')]

def read_int():
	return int(input())

class TreeNode(object):

	def __init__(self, x):
		self.val = x
		self.left = None
		self.right = None

	def __str__(self):
		q = deque()
		ans = []
		q.append(self)
		ans.append(self.val)
		while q:
			cur = q.popleft()
			ans.append(cur.left.val if cur.left else 'null')
			ans.append(cur.right.val if cur.right else 'null')
			if cur.left:
				q.append(cur.left)
			if cur.right:
				q.append(cur.right)
		while ans and ans[-1] == 'null':
			ans.pop()
		return str(ans).replace("'null'", 'null')

def toTreeNode(s):
	l = eval(s.replace('null', 'None'))
	n = len(l)
	if not n:
		return None
	root = TreeNode(l[0])
	q = deque()
	q.append(root)
	i = 1
	while q and i < n:
		cur = q.popleft()
		if l[i] != None:
			cur.left = TreeNode(l[i])
			q.append(cur.left)
		i += 1
		if i >= n:
			break
		if l[i] != None:
			cur.right = TreeNode(l[i])
			q.append(cur.right)
		i += 1
	return root

class Djs:

	def __init__(self, n):
		self.w = [1] * n
		self.p = [-1] * n

	def find(self, x):
		p = self.p[x]
		if p == -1:
			return x
		else:
			self.p[x] = self.find(p)
			return self.p[x]

	def union(self, x, y):
		(x, y) = (self.find(x), self.find(y))
		if x == y:
			return
		if self.w[x] > self.w[y]:
			(x, y) = (y, x)
		self.p[x] = y
		self.w[y] += self.w[x]

	def roots(self):
		return [x for (x, y) in enumerate(self.p) if y == -1]

def doit():
	s = read_string()
	(minAB, minBA, maxAB, maxBA) = (INF, INF, NINF, NINF)
	for i in range(0, len(s) - 1):
		if s[i] == 'A' and s[i + 1] == 'B':
			minAB = min(minAB, i)
			maxAB = max(maxAB, i)
		elif s[i] == 'B' and s[i + 1] == 'A':
			minBA = min(minBA, i)
			maxBA = max(maxBA, i)
	print('%s' % ('YES' if minAB + 1 < maxBA or minBA + 1 < maxAB else 'NO'))
try:
	while True:
		doit()
except EOFError:
	pass


s = str(input())
i = 0
arr1 = []
arr2 = []
while i < len(s) - 1:
	if s[i] == 'A' and s[i + 1] == 'B':
		arr1.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		arr2.append(i)
	i += 1
if len(arr1) == 0 or len(arr2) == 0:
	print('NO')
elif max(len(arr1), len(arr2)) > 2 and min(len(arr1), len(arr2)) >= 1:
	print('YES')
elif len(arr1) == 2 and len(arr2) == 2:
	print('YES')
elif len(arr1) == 2 and len(arr2) == 1:
	if arr1[0] + 1 == arr2[0] and arr1[1] == arr2[0] + 1:
		print('NO')
	else:
		print('YES')
elif len(arr1) == 1 and len(arr2) == 2:
	if arr2[0] + 1 == arr1[0] and arr2[1] == arr1[0] + 1:
		print('NO')
	else:
		print('YES')
elif arr1[0] + 1 == arr2[0] or arr2[0] + 1 == arr1[0]:
	print('NO')
else:
	print('YES')


s = input()
slen = len(s)
if slen <= 3:
	print('NO')
else:
	abCount = s.count('AB')
	baCount = s.count('BA')
	flag1 = 0
	flag2 = 0
	if abCount > 0 and baCount > 0:
		f1 = s.find('AB')
		x1 = s.count('BA', f1 + 2, slen)
		if x1 > 0:
			flag1 = 1
		f2 = s.find('BA')
		x2 = s.count('AB', f2 + 2, slen)
		if x2 > 0:
			flag2 = 1
	if flag1 == 1 or flag2 == 1:
		print('YES')
	else:
		print('NO')


s = str(input())
tab = s.count('AB')
tba = s.count('BA')
flag = 1 if tab > 0 and tba > 0 and (tab + tba - s.count('ABA') - s.count('BAB') >= 2) else 0
print('YES' if flag else 'NO')


s = input()
matches = {'AB': [], 'BA': []}
for i in range(len(s) - 1):
	substring = s[i:i + 2]
	if substring in matches:
		matches[substring].append(i)
if not matches['AB'] or not matches['BA']:
	print('NO')
elif abs(max(matches['AB']) - min(matches['BA'])) > 1:
	print('YES')
elif abs(min(matches['AB']) - max(matches['BA'])) > 1:
	print('YES')
else:
	print('NO')


n = input()
print(['NO', 'YES'][n.count('AB') + n.count('BA') - n.count('ABA') - n.count('BAB') >= 2 and n.count('AB') > 0 and (n.count('BA') > 0)])


a = input().strip()
n = len(a)
ans = False
try:
	x = a.index('AB')
	y = a.rindex('BA')
	if abs(x - y) > 1:
		ans = True
except:
	pass
try:
	x = a.index('BA')
	y = a.rindex('AB')
	if abs(x - y) > 1:
		ans = True
except:
	pass
if ans:
	print('YES')
else:
	print('NO')


def solve(s):
	n = len(s)
	try:
		fab = s.index('AB')
		fba = s.index('BA')
	except ValueError:
		return False
	good = [False] * (n + 1)
	for i in range(4, n + 1):
		ss = s[i - 2:i]
		if ss == 'AB':
			good[i] = good[i - 1] or fba + 1 < i - 2
		elif ss == 'BA':
			good[i] = good[i - 1] or fab + 1 < i - 2
		else:
			good[i] = good[i - 1]
	return good[n]
s = input()
print('YES' if solve(s) else 'NO')


inp_str = input()
l_inp_str = len(inp_str)
found = False
x = inp_str.find('AB')
if x != -1:
	rem_str = inp_str[x + 2:]
	y = rem_str.find('BA')
	if y != -1:
		found = True
if found == False:
	x = inp_str.find('BA')
	if x != -1:
		rem_str = inp_str[x + 2:]
		y = rem_str.find('AB')
		if y != -1:
			found = True
if found:
	print('YES')
else:
	print('NO')


a = input()
l = len(a)
f = 0
if l <= 3:
	print('NO')
else:
	s = a
	if 'AB' in s:
		s = s.replace('AB', ' ', 1)
		if 'BA' in s:
			print('YES')
			f = 1
	s = a
	if 'BA' in s and f == 0:
		s = s.replace('BA', ' ', 1)
		if 'AB' in s:
			print('YES')
			f = 1
	if f == 0:
		print('NO')


def find(st):
	a = 'AB'
	b = 'BA'
	return check(st, a, b) or check(st, b, a)

def check(st, x, y):
	temp = st.find(x)
	if temp < 0:
		return False
	return st.find(y, temp + len(x)) >= 0
s = input()
if find(s):
	print('YES')
else:
	print('NO')


import math as m
s = input()
l = len(s)
abPos = []
baPos = []
for i in range(0, l - 1):
	if s[i:i + 2] == 'AB':
		abPos.append(i)
	if s[i:i + 2] == 'BA':
		baPos.append(i)
f = 0
for a in abPos:
	for b in baPos:
		if m.fabs(a - b) >= 2:
			f = 1
			break
if f == 0:
	print('NO')
else:
	print('YES')


s = input()
if s.count('AB') > 0:
	l = s.find('AB')
	t = s[:l]
	v = s[l + 2:]
	if t.count('BA') > 0 or v.count('BA'):
		print('YES')
	elif s.count('BA') > 0:
		l = s.find('BA')
		t = s[:l]
		v = s[l + 2:]
		if t.count('AB') > 0 or v.count('AB'):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


a = input()
c = 0
d = 0
for i in range(len(a) - 1):
	if a[i] == 'A':
		if a[i + 1] == 'B':
			c = c + 1
	if a[i] == 'B':
		if a[i + 1] == 'A':
			d = d + 1
if c == 0:
	print('NO')
elif d == 0:
	print('NO')
if c > 1:
	if d > 1:
		print('YES')
	if d == 1:
		a = a.replace('ABAB', '')
		if a.find('AB') != -1:
			print('YES')
		else:
			print('NO')
if d > 1:
	if c == 1:
		a = a.replace('BABA', '')
		if a.find('BA') != -1:
			print('YES')
		else:
			print('NO')
if c == 1:
	if d == 1:
		a = a.replace('AB', '')
		if a.find('BA') != -1:
			print('YES')
		else:
			print('NO')


def main():
	a = input()
	c = 0
	d = 0
	for i in range(1, len(a)):
		if a[i] == 'A' and a[i - 1] == 'B':
			d = 1
			if i == len(a) - 1:
				break
			elif a[i + 1] != 'B':
				break
		elif a[i] == 'B' and a[i - 1] == 'A':
			c = 1
			if i == len(a) - 1:
				break
			if a[i + 1] != 'A':
				break
		if c == 1 and d == 1:
			break
	if c == 1 and i < len(a) - 2:
		for j in range(i + 2, len(a)):
			if a[j] == 'A' and a[j - 1] == 'B':
				c = 2
				break
	if d == 1 and i < len(a) - 2:
		for j in range(i + 2, len(a)):
			if a[j] == 'B' and a[j - 1] == 'A':
				d = 2
				break
	if c == 2 or d == 2:
		print('YES')
	else:
		print('NO')
main()


flag = 0
s = input().strip(' ')
try:
	i = s.index('AB')
	if 'BA' in s[i + 2:]:
		print('YES')
		flag = 1
except ValueError:
	pass
if not flag:
	try:
		i = s.index('BA')
		if 'AB' in s[i + 2:]:
			print('YES')
			flag = 1
	except:
		pass
	if not flag:
		print('NO')


def work():
	for i in a:
		for j in b:
			if abs(i - j) >= 2:
				return True
	return False
s = input()
l = len(s)
a = []
b = []
for i in range(l - 1):
	if s[i] + s[i + 1] == 'AB':
		a.append(i)
	elif s[i] + s[i + 1] == 'BA':
		b.append(i)
if a and b:
	if work():
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
p = s.find('AB')
f = s.find('BA')
if p != -1 and s.find('BA', p + 2) != -1:
	print('YES')
elif f != -1 and s.find('AB', f + 2) != -1:
	print('YES')
else:
	print('NO')


import re
a = input()
z = re.compile('BA')
d = z.search(str(a))
if d == None:
	print('NO')
else:
	p = re.compile('AB')
	e = p.search(str(a))
	if e == None:
		print('NO')
	else:
		x = re.compile('AB.*BA')
		b = x.search(str(a))
		y = re.compile('BA.*AB')
		c = y.search(str(a))
		if c != None or b != None:
			print('YES')
		else:
			print('NO')


s = input()
abx = s.replace('AB', 'X', 1)
bax = s.replace('BA', 'X', 1)
print('YES' if len(abx) != len(s) and abx.count('BA') or (len(bax) != len(s) and bax.count('AB')) else 'NO')


def substrings(s):
	a = s.count('AB')
	b = s.count('BA')
	c = s.count('ABA')
	d = s.count('BAB')
	if (a != 0 and b != 0) and a + b - c - d > 1:
		return 'YES'
	else:
		return 'NO'
s = input()
print(substrings(s))


s = input().strip()
(acnt, bcnt) = (0, 0)
(MaxA, MaxB, MinA, MinB) = (-1, -1, 9999999999999, 9999999999999)
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		acnt += 1
		if i < MinA:
			MinA = i
		if i > MaxA:
			MaxA = i
	if s[i] == 'B' and s[i + 1] == 'A':
		bcnt += 1
		if i < MinB:
			MinB = i
		if i > MaxB:
			MaxB = i
if (acnt >= 1 and bcnt >= 1) and (MaxB - MinA > 1 or MaxA - MinB > 1):
	print('YES')
else:
	print('NO')


def main():
	s = input().strip()
	ab_idxs = []
	ba_idxs = []
	find_e_idxs(s, ab_idxs, 'AB')
	find_e_idxs(s, ba_idxs, 'BA')
	found_two_substrings = False
	for i in range(len(ab_idxs)):
		curr_ab_idx = ab_idxs[i]
		for j in range(len(ba_idxs)):
			curr_ba_idx = ba_idxs[j]
			if curr_ba_idx + 2 <= curr_ab_idx or curr_ab_idx + 2 <= curr_ba_idx:
				found_two_substrings = True
				break
		if found_two_substrings:
			break
	print('YES' if found_two_substrings else 'NO')

def find_e_idxs(lst, idxs, e):
	lst_len = len(lst)
	for i in range(lst_len):
		if i + 1 < lst_len and lst[i] == e[0] and (lst[i + 1] == e[1]):
			idxs.append(i)
main()


a = list(input())
i = 0
ab = 0
ba = 0
f = 0
while i < len(a) - 1:
	if (a[i] == 'A' and a[i + 1] == 'B') and ab == 0:
		ab = 1
		f = 1
		i += 2
	elif (a[i] == 'B' and a[i + 1] == 'A') and f == 1 and (ba == 0):
		ba = 1
		f = 2
		i += 2
	else:
		i += 1
	if ab == 1 and ba == 1:
		break
if f == 2:
	print('YES')
else:
	i = 0
	ab = 0
	ba = 0
	f = 0
	while i < len(a) - 1:
		if (a[i] == 'B' and a[i + 1] == 'A') and ba == 0:
			ba = 1
			f = 1
			i += 2
		elif (a[i] == 'A' and a[i + 1] == 'B') and f == 1 and (ab == 0):
			ab = 1
			f = 2
			i += 2
		else:
			i += 1
		if ab == 1 and ba == 1:
			break
	if f == 2:
		print('YES')
	else:
		print('NO')


s = input()
a = s.rfind('AB')
b = s.find('BA')
x = False
if a != -1 and b != -1 and (abs(a - b) >= 2):
	x = True
a = s.rfind('BA')
b = s.find('AB')
y = False
if a != -1 and b != -1 and (abs(a - b) >= 2):
	y = True
if x or y:
	print('YES')
else:
	print('NO')


s1 = input().strip()
AB = []
BA = []
for i in range(len(s1) - 1):
	if s1[i] == 'A' and s1[i + 1] == 'B':
		AB.append(i)
	elif s1[i] == 'B' and s1[i + 1] == 'A':
		BA.append(i)
x = True
for i in AB:
	for j in BA:
		if abs(i - j) > 1:
			print('YES')
			x = False
			break
	if not x:
		break
if x:
	print('NO')


def mod(a):
	if a < 0:
		return -a
	else:
		return a
s = input()
x = []
indAB = []
indBA = []
for i in range(0, len(s) - 1):
	x.append(s[i] + s[i + 1])
if 'AB' in x and 'BA' in x:
	for i in range(0, len(s) - 1):
		if x[i] == 'AB':
			indAB.append(i)
		elif x[i] == 'BA':
			indBA.append(i)
	sorted(indAB)
	sorted(indBA)
	if indAB[len(indAB) - 1] - indBA[0] > 1:
		print('YES')
		quit()
	elif indBA[len(indBA) - 1] - indAB[0] > 1:
		print('YES')
		quit()
print('NO')


s = input()
x = s.find('AB')
y = s.rfind('BA')
z = s.find('BA')
w = s.rfind('AB')
if (abs(y - x) > 1 or abs(w - z) > 1) and min(x, z, y, w) >= 0:
	print('YES')
else:
	print('NO')


st = input()
ab1 = st.find('AB')
ba1 = st.find('BA')
ab2 = st.rfind('AB')
ba2 = st.rfind('BA')
if ab1 == -1 or ba1 == -1:
	print('NO')
elif ab1 == ab2 and ba1 == ba2 and (abs(ba1 - ab1) < 2):
	print('NO')
elif ab1 + 2 == ab2 and ba1 == ba2:
	print('NO')
elif ba1 + 2 == ba2 and ab1 == ab2:
	print('NO')
else:
	print('YES')


t = input()
ab = t.count('AB')
ba = t.count('BA')
if ab == 0 or ba == 0:
	print('NO')
elif ab > 1 or ba > 1:
	if ba == 2 and ab == 1:
		if t.count('BABA') == 1:
			print('NO')
		else:
			print('YES')
	elif ab == 2 and ba == 1:
		if t.count('ABAB') == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')
elif abs(t.index('AB') - t.index('BA')) == 1:
	print('NO')
elif t.count('ABA') == 1 or t.count('BAB') == 1:
	print('NO')
else:
	print('YES')


s = input()
l = len(s)
idx = -1
for i in range(l - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		idx = i + 1
		break
flag = 0
if idx != -1:
	for i in range(idx + 1, l - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			flag = 1
			break
if flag == 1:
	print('YES')
else:
	idx = -1
	for i in range(l - 1):
		if s[i] == 'B' and s[i + 1] == 'A':
			idx = i + 1
			break
	flag = 0
	if idx != -1:
		for i in range(idx + 1, l - 1):
			if s[i] == 'A' and s[i + 1] == 'B':
				flag = 1
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')


s = input()
L = len(s)
AB = 0
BA = 0
ABA = 0
BAB = 0
i = 0
while i < L - 1:
	if s[i] == 'A':
		if s[i + 1] == 'B':
			if i + 2 < L and s[i + 2] == 'A':
				ABA += 1
				i += 3
			else:
				AB += 1
				i += 2
		else:
			i += 1
	elif s[i] == 'B':
		if s[i + 1] == 'A':
			if i + 2 < L and s[i + 2] == 'B':
				BAB += 1
				i += 3
			else:
				BA += 1
				i += 2
		else:
			i += 1
	else:
		i += 1
if AB >= 1 and BA >= 1:
	print('YES')
elif ABA > 0 and BA > 0:
	print('YES')
elif ABA > 0 and AB > 0:
	print('YES')
elif ABA > 0 and BAB > 0:
	print('YES')
elif BAB > 0 and BA > 0:
	print('YES')
elif BAB > 0 and AB > 0:
	print('YES')
else:
	print('NO')


def is_ab(prev, current):
	return prev == 'A' and current == 'B'

def is_ba(prev, current):
	return prev == 'B' and current == 'A'

def is_matched(prev, current):
	return is_ab(prev, current) or is_ba(prev, current)

def main():
	s = input()
	i = 0
	total_ab = 0
	total_ba = 0
	total_confused = 0
	current_len = 0
	prev = ''
	while i < len(s):
		current = s[i]
		if current_len != 0:
			if is_matched(prev, current):
				current_len += 1
			else:
				if current_len == 2:
					if is_ab(s[i - 2], s[i - 1]):
						total_ab += 1
					elif is_ba(s[i - 2], s[i - 1]):
						total_ba += 1
				elif current_len == 3:
					total_confused += 1
				elif current_len == 4:
					total_confused += 1
				elif current_len > 4:
					total_confused += 2
				if current == 'A' or current == 'B':
					current_len = 1
				else:
					current_len = 0
		elif current == 'A' or current == 'B':
			current_len = 1
		prev = current
		i += 1
	if len(s) >= 2 and current_len >= 2:
		current = s[len(s) - 1]
		prev = s[len(s) - 2]
		if current_len == 2:
			if is_ab(prev, current):
				total_ab += 1
			elif is_ba(prev, current):
				total_ba += 1
		elif current_len == 3:
			total_confused += 1
		elif current_len == 4:
			total_confused += 1
		elif current_len > 4:
			total_confused += 2
	if total_ba >= 1 and total_ab >= 1:
		print('YES')
	elif total_confused >= 2:
		print('YES')
	elif (total_ab >= 1 or total_ba >= 1) and total_confused >= 1:
		print('YES')
	else:
		print('NO')

def __starting_point():
	main()
__starting_point()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	a = inp()
	cnt1 = 0
	cnt2 = 0
	cnt3 = 0
	n = len(a)
	prev = -1
	for i in range(1, n):
		if i <= n - 1 and (a[i - 1:i + 2] == 'ABA' or a[i - 1:i + 2] == 'BAB') and (i > prev + 1):
			prev = i
			cnt3 += 1
		elif a[i - 1:i + 1] == 'AB' and a[i - 2] != 'B':
			cnt1 += 1
		elif a[i - 1:i + 1] == 'BA' and a[i - 2] != 'A':
			cnt2 += 1
	if cnt1 > 0:
		if cnt2 > 0:
			print('YES')
		elif cnt3 > 0:
			print('YES')
		else:
			print('NO')
	elif cnt2 > 0:
		if cnt3 > 0:
			print('YES')
		else:
			print('NO')
	elif cnt3 > 1:
		print('YES')
	else:
		print('NO')
testcase(1)


a = input()
b = a[:]
counter = 0
if 'AB' in a:
	res = a.find('AB')
	a = a[:res] + '**' + a[res + 2:]
	counter += 1
if 'BA' in a:
	res = a.find('BA')
	a = a[:res] + '**' + a[res + 2:]
	counter += 1
if counter == 2:
	print('YES')
else:
	counter = 0
	if 'BA' in b:
		res = b.find('BA')
		b = b[:res] + '**' + b[res + 2:]
		counter += 1
	if 'AB' in b:
		res = b.find('AB')
		b = b[:res] + '**' + b[res + 2:]
		counter += 1
	if counter == 2:
		print('YES')
	else:
		print('NO')


import sys
inputStr = input()
if 'AB' in inputStr:
	i = inputStr.index('AB')
	if 'BA' in inputStr[:i] or 'BA' in inputStr[i + 2:]:
		print('YES')
		sys.exit()
if 'BA' in inputStr:
	i = inputStr.index('BA')
	if 'AB' in inputStr[:i] or 'AB' in inputStr[i + 2:]:
		print('YES')
		sys.exit()
print('NO')


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		l = list(input())
		flag = [0, 0]
		count = 0
		i = 0
		ansa = []
		ansb = []
		n = len(l)
		for i in range(1, n):
			if l[i] == 'A' and l[i - 1] == 'B':
				ansa.append([i - 1, i])
			elif l[i] == 'B' and l[i - 1] == 'A':
				ansb.append([i - 1, i])
		if len(ansb) == 0 or len(ansa) == 0:
			no()
		else:
			flag = 0
			for x in range(len(ansa)):
				for y in range(len(ansb)):
					if ansa[x][1] != ansb[y][0] and ansa[x][0] != ansb[y][1]:
						flag = 1
						break
			if flag:
				yes()
			else:
				no()
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


import itertools
s = input()
a1 = s.find('AB')
b1 = s.find('BA')
a2 = -1 if a1 == -1 else s.find('AB', a1 + 1)
b2 = -1 if b1 == -1 else s.find('BA', b1 + 1)
a3 = -1 if a2 == -1 else s.find('AB', a2 + 1)
b3 = -1 if b2 == -1 else s.find('BA', b2 + 1)
for (a, b) in itertools.product((a1, a2, a3), (b1, b2, b3)):
	if a != -1 and b != -1 and (abs(a - b) >= 2):
		print('YES')
		break
else:
	print('NO')


s = input()
ch = 1
m = str(s)
n = len(s)
ch1 = 0
ch2 = 0
for i in range(n - 1):
	if s[i] == 'B' and s[i + 1] == 'A' and (ch1 == 0):
		s = s[:i] + '11' + s[i + 2:]
		ch1 = 1
	if s[i] == 'A' and s[i + 1] == 'B' and (ch2 == 0) and (ch1 == 1):
		s = s[:i] + '11' + s[i + 2:]
		ch2 = 1
if ch1 == 1 and ch2 == 1:
	ch = 1
else:
	ch = 0
s = str(m)
n = len(s)
ch1 = 0
ch2 = 0
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'B' and (ch1 == 0):
		s = s[:i] + '11' + s[i + 2:]
		ch1 = 1
	if s[i] == 'B' and s[i + 1] == 'A' and (ch2 == 0) and (ch1 == 1):
		s = s[:i] + '11' + s[i + 2:]
		ch2 = 1
if ch1 == 1 and ch2 == 1:
	ch = 1
else:
	ch = ch
if ch == 1:
	print('YES')
else:
	print('NO')


def func(n):
	if 'AB' not in n or 'BA' not in n:
		print('NO')
		return
	a = n.index('AB')
	b = n.index('BA')
	for i in range(a + 2, len(n) - 1):
		if n[i] + n[i + 1] == 'BA':
			print('YES')
			return
	for i in range(b + 2, len(n) - 1):
		if n[i] + n[i + 1] == 'AB':
			print('YES')
			return
	print('NO')
n = input()
func(n)


st = input()
(ab, ba) = ([], [])
for i in range(len(st) - 1):
	if st[i:i + 2] == 'AB':
		ab.append(i)
	elif st[i:i + 2] == 'BA':
		ba.append(i)
if ab == [] or ba == []:
	print('NO')
	exit(0)
for i in ab:
	for j in ba:
		if abs(i - j) > 1:
			print('YES')
			exit(0)
print('NO')


s = str(input())
ab_ba = 0
ba_ab = 0
i = 0
n = len(s)
while i < n - 1:
	if s[i] + s[i + 1] == 'AB':
		if ab_ba == 0:
			ab_ba = 1
			i += 2
			continue
	if s[i] + s[i + 1] == 'BA':
		if ab_ba == 1:
			ab_ba = 2
			i += 2
			continue
	i += 1
i = 0
while i < n - 1:
	if s[i] + s[i + 1] == 'BA':
		if ba_ab == 0:
			ba_ab = 1
			i += 2
			continue
	if s[i] + s[i + 1] == 'AB':
		if ba_ab == 1:
			ba_ab = 2
			i += 2
			continue
	i += 1
if ab_ba == 2 or ba_ab == 2:
	print('YES')
else:
	print('NO')


import sys
w = str(input().strip())
c = w.find('AB')
while c != -1:
	c2 = w.find('BA', 0, c)
	if c2 == -1:
		c2 = w.find('BA', c + 2)
	else:
		print('YES')
		sys.exit()
	if c2 == -1:
		c = w.find('AB', c + 2)
	else:
		print('YES')
		sys.exit()
print('NO')


s = input()
if s.count('AB') > 0 and s.count('BA') > 0:
	if s.find('ABA') <= s.find('AB') and s.find('ABA') <= s.find('BA') and (s.find('ABA') != -1):
		if s.find('AB', s.find('ABA') + 3, len(s)) != -1:
			print('YES')
		elif s.find('BA', s.find('ABA') + 3, len(s)) != -1:
			print('YES')
		else:
			print('NO')
	elif s.find('BAB') <= s.find('AB') and s.find('BAB') <= s.find('BA') and (s.find('BAB') != -1):
		if s.find('AB', s.find('BAB') + 3, len(s)) != -1:
			print('YES')
		elif s.find('BA', s.find('BAB') + 3, len(s)) != -1:
			print('YES')
		else:
			print('NO')
	elif s.find('AB') < s.find('BA'):
		if s.find('BA', s.find('AB') + 2, len(s)) != -1:
			print('YES')
		else:
			print('NO')
	elif s.find('BA') < s.find('AB'):
		if s.find('AB', s.find('BA') + 2, len(s)) != -1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase

def main():
	s = input()
	n = len(s)
	ab = 0
	ba = 0
	x = 0
	while x < n:
		if x + 1 < n and s[x] == 'A' and (s[x + 1] == 'B') and (ab == 0):
			ab = 1
			x += 1
		elif x + 1 < n and s[x] == 'B' and (s[x + 1] == 'A') and (ba == 0) and (ab == 1):
			ba = 1
			x += 1
		x += 1
	x = 0
	abb = 0
	baa = 0
	while x < n:
		if x + 1 < n and s[x] == 'B' and (s[x + 1] == 'A') and (baa == 0):
			baa = 1
			x += 1
		elif x + 1 < n and s[x] == 'A' and (s[x + 1] == 'B') and (abb == 0) and (baa == 1):
			abb = 1
			x += 1
		x += 1
	if ab == 1 and ba == 1 or (abb == 1 and baa == 1):
		print('YES')
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


st = input()
a = st.find('AB')
b = st.find('BA')
print('NYOE S'[a >= 0 and st[a + 2:].find('BA') >= 0 or (b >= 0 and st[b + 2:].find('AB') >= 0)::2])


str = input()
str += 'NNNNNNNN'
k_ab = 0
k_ba = 0
k_aba = 0
ans = 'NO'
i = 0
while i < len(str) - 6:
	if str[i] == 'A':
		if str[i + 1] == 'B':
			if str[i + 2] == 'A':
				if str[i + 3] == 'B':
					if str[i + 4] == 'A':
						ans = 'YES'
						i += 5
					else:
						k_aba += 1
						i += 4
				else:
					k_aba += 1
					i += 3
			else:
				k_ab += 1
				i += 2
		else:
			i += 1
	elif str[i] == 'B':
		if str[i + 1] == 'A':
			if str[i + 2] == 'B':
				if str[i + 3] == 'A':
					if str[i + 4] == 'B':
						ans = 'YES'
						i += 5
					else:
						k_aba += 1
						i += 4
				else:
					k_aba += 1
					i += 3
			else:
				k_ba += 1
				i += 2
		else:
			i += 1
	else:
		i += 1
if k_ab > 0 and (k_ba > 0 or k_aba > 0):
	ans = 'YES'
elif k_ba > 0 and (k_ab > 0 or k_aba > 0):
	ans = 'YES'
elif ans == 'YES':
	ans = 'YES'
else:
	ans = 'NO'
print(ans)


s = list(input())
z = []
z += s
l = 0
for n in range(len(s) - 1):
	if s[n] + s[n + 1] == 'AB':
		l = 1
		s[n] = s[n + 1] = 'D'
		break
if l == 0:
	l = 0
else:
	for n in range(len(s) - 1):
		if s[n] + s[n + 1] == 'BA':
			l = 2
			s[n] = s[n + 1] = 'D'
			break
	if l == 1:
		l = 0
	elif l == 2:
		print('YES')
if l == 0:
	for n in range(len(z) - 1):
		if z[n] + z[n + 1] == 'BA':
			z[n] = z[n + 1] = 'D'
			l = 1
			break
	if l == 0:
		l = 0
	else:
		for n in range(len(z) - 1):
			if z[n] + z[n + 1] == 'AB':
				l = 2
				break
		if l == 1:
			print('NO')
		else:
			print('YES')
	if l == 0:
		print('NO')


n = input()
clis = []
dlis = []
for i in range(0, len(n) - 1):
	if n[i] + n[i + 1] == 'AB':
		clis.append(i)
	if n[i] + n[i + 1] == 'BA':
		dlis.append(i)

def judge(clis, dlis):
	for i in clis:
		for j in dlis:
			if i != j and abs(i - j) > 1:
				return 'YES'
	return 'NO'
print(judge(clis, dlis))


s = input()
(c, c1, c2) = (0, 0, 0)
i = 0
while i < len(s) - 1:
	if s[i] == 'A' and c1 != 1:
		if s[i + 1] == 'B':
			if i + 2 < len(s) and s[i + 2] == 'A':
				c += 1
				i += 1
			else:
				c1 += 1
			i += 1
	elif s[i] == 'B' and c2 != 1:
		if s[i + 1] == 'A':
			if i + 2 < len(s) and s[i + 2] == 'B':
				c += 1
				i += 1
			else:
				c2 += 1
			i += 1
	if c1 + c2 + c >= 2:
		print('YES')
		exit(0)
	i += 1
print('NO')


s = input().strip()
n = len(s)

def has():
	for i in range(n - 1):
		if s[i:i + 2] == 'AB':
			for j in range(i + 2, n - 1):
				if s[j:j + 2] == 'BA':
					return True
			break
	for i in range(n - 1):
		if s[i:i + 2] == 'BA':
			for j in range(i + 2, n - 1):
				if s[j:j + 2] == 'AB':
					return True
			break
	return False
print('YES' if has() else 'NO')


import sys
s = sys.stdin.readline()
n = len(s)
ret = False
a = s.find('AB')
if a != -1 and s.find('BA', a + 2) != -1:
	ret = True
if not ret:
	a = s.find('BA')
	if a != -1 and s.find('AB', a + 2) != -1:
		ret = True
sys.stdout.write('YES\n' if ret else 'NO\n')


s = input()
ans = False
ans_2 = False
i = 0
l = len(s)
while i < l:
	if not ans and s[i] == 'A' and (i + 1 < l) and (s[i + 1] == 'B'):
		ans = True
		i += 2
	elif ans and s[i] == 'B' and (i + 1 < l) and (s[i + 1] == 'A'):
		ans_2 = True
		break
	else:
		i += 1
if ans * ans_2:
	print('YES')
	exit()
ans = False
ans_2 = False
i = 0
while i < l:
	if not ans_2 and s[i] == 'B' and (i + 1 < l) and (s[i + 1] == 'A'):
		ans_2 = True
		i += 2
	elif ans_2 and s[i] == 'A' and (i + 1 < l) and (s[i + 1] == 'B'):
		ans = True
		break
	else:
		i += 1
if ans * ans_2:
	print('YES')
else:
	print('NO')


s = input()
ind = s.find('AB')
flag = 0
if ind > -1 and 'BA' in s[ind + 2:]:
	flag = 1
ind = s.find('BA')
if ind > -1 and 'AB' in s[ind + 2:]:
	flag = 1
if flag:
	print('YES')
else:
	print('NO')


s = input()
s1 = s
if 'BA' in s:
	s = s.replace('BA', '//', 1)
else:
	s = s.replace('AB', '//')
if 'AB' in s:
	t = True
else:
	t = False
s = s1
if 'AB' in s:
	s = s.replace('AB', '//', 1)
else:
	s = s.replace('BA', '//')
if 'BA' in s:
	t1 = True
else:
	t1 = False
if t or t1:
	print('YES')
else:
	print('NO')


inp = input().strip()
if len(inp) < 4:
	print('NO')
elif inp.count('AB') == 1 and inp.count('BA') == 1:
	if inp.count('ABA') + inp.count('BAB') >= 1:
		print('NO')
	else:
		print('YES')
elif inp.count('AB') < 1 or inp.count('BA') < 1:
	print('NO')
elif inp.count('AB') + inp.count('BA') == 3 and inp.count('ABAB') + inp.count('BABA') >= 1:
	print('NO')
else:
	print('YES')


s = input()
i = 0
b_ab = False
b = False
while i < len(s) - 1:
	if not b_ab:
		if s[i] == 'A' and s[i + 1] == 'B':
			b_ab = True
			i += 1
	elif s[i] == 'B' and s[i + 1] == 'A':
		b = True
		break
	i += 1
i = 0
b_ba = False
b1 = False
while i < len(s) - 1:
	if not b_ba:
		if s[i] == 'B' and s[i + 1] == 'A':
			b_ba = True
			i += 1
	elif s[i] == 'A' and s[i + 1] == 'B':
		b1 = True
		break
	i += 1
if b or b1:
	print('YES')
else:
	print('NO')


a = input()
f = False
for i in range(len(a) - 1):
	if a[i] + a[i + 1] == 'AB':
		if a[i + 2:].rfind('BA') != -1:
			f = True
	if a[i] + a[i + 1] == 'BA':
		if a[i + 2:].rfind('AB') != -1:
			f = True
if f:
	print('YES')
else:
	print('NO')


S = input()
A = 0
B = 0
for i in range(len(S) - 1):
	if S[i] == 'A' and S[i + 1] == 'B':
		A += 1
	if S[i] == 'B' and S[i + 1] == 'A':
		B += 1
if A * B == 0:
	print('NO')
elif A == B == 1:
	if 'ABA' in S or 'BAB' in S:
		print('NO')
	else:
		print('YES')
elif A == 1 and B == 2 or (A == 2 and B == 1):
	if 'ABAB' in S or 'BABA' in S:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


s = input()
s1 = s
try:
	i = s.index('AB')
	s = s.replace('AB', '..', 1)
	j = s.index('BA')
	print('YES')
except:
	try:
		i = s1.index('BA')
		s1 = s1.replace('BA', '..', 1)
		j = s1.index('AB')
		print('YES')
	except:
		print('NO')


s = input()
ABL = s.find('AB')
ABR = s.rfind('AB')
BAL = s.find('BA')
BAR = s.rfind('BA')
if (abs(ABL - BAR) > 1 or abs(BAL - ABR) > 1) and ABL != -1 and (BAL != -1):
	print('YES')
else:
	print('NO')


string = input()
flag1 = 0
flag2 = 0
flag3 = 0
flag4 = 0
if 'AB' in string:
	flag1 = 1
	pos1 = string.find('AB')
	if 'BA' in string[:pos1] or 'BA' in string[pos1 + 2:]:
		flag2 = 1
if 'BA' in string:
	flag3 = 1
	pos1 = string.find('BA')
	if 'AB' in string[:pos1] or 'AB' in string[pos1 + 2:]:
		flag4 = 1
if flag1 == 1 and flag2 == 1 or (flag3 == 1 and flag4 == 1):
	print('YES')
else:
	print('NO')


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	S = Scanner.string()

	def solve():
		if 'AB' in S:
			p = S.index('AB')
			if 'BA' in S[p + 2:]:
				return True
		if 'BA' in S:
			p = S.index('BA')
			if 'AB' in S[p + 2:]:
				return True
		return False
	print('NYOE S'[solve()::2])
main()


s = input()
n = len(s)
temp = ''
tent = ''
flag = 0
i = 0
a = []
b = []
while i < n - 1:
	if s[i:i + 2] == 'AB':
		a.append(i)
	elif s[i:i + 2] == 'BA':
		b.append(i)
	i += 1
i = 0
while i < len(a):
	for j in range(len(b)):
		if a[i] != b[j] + 1 and a[i] != b[j] - 1:
			print('YES')
			flag = 1
			break
	if flag != 1:
		i += 1
	else:
		break
if flag == 0:
	print('NO')


s = input().strip()
if s.find('AB') != -1:
	x = s.find('AB')
	t = s[x + 2:]
	if t.find('BA') != -1:
		print('YES')
		exit(0)
if s.find('BA') != -1:
	x = s.find('BA')
	t = s[x + 2:]
	if t.find('AB') != -1:
		print('YES')
		exit(0)
print('NO')


s = input()
(x, y) = (s, s)
var = 0
if 'AB' in x:
	l = x.index('AB')
	if 'BA' in x[:l] or 'BA' in x[l + 2:]:
		var = 1
if var == 1:
	print('YES')
else:
	if 'BA' in y:
		l = y.index('BA')
		if 'AB' in y[:l] or 'AB' in y[l + 2:]:
			var = 1
	if var == 1:
		print('YES')
	else:
		print('NO')


def main():
	x = input()
	found = False
	if 'AB' in x:
		y = x.split('AB', 1)
		for i in y:
			if 'BA' in i:
				found = True
				print('YES')
				return
	if 'BA' in x:
		y = x.split('BA', 1)
		for i in y:
			if 'AB' in i:
				found = True
				print('YES')
				return
	if not found:
		print('NO')
main()


n = input()
if 'AB' not in n or 'BA' not in n:
	print('NO')
	exit()
fi = []
se = []
x = len(n)
for i in range(x - 1):
	if n[i] + n[i + 1] == 'AB':
		fi.append(i)
	elif n[i] + n[i + 1] == 'BA':
		se.append(i)
x = len(se)
for i in fi:
	if se.count(i + 1) + se.count(i - 1) != x:
		print('YES')
		exit()
print('NO')


__author__ = 'victormion'
leftAB = None
leftBA = None
rightAB = None
rightBA = None
s = input()

def function():
	if leftAB == None or leftBA == None:
		return False
	else:
		if rightAB - leftBA > 1:
			return True
		if rightBA - leftAB > 1:
			return True
	return False
for i in range(0, len(s) - 1):
	if 'AB' == s[i:i + 2]:
		if leftAB == None:
			leftAB = i
		rightAB = i
	if 'BA' == s[i:i + 2]:
		if leftBA == None:
			leftBA = i
		rightBA = i
if function():
	print('YES')
else:
	print('NO')


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	s = sin()
	flag = 0
	for i in range(len(s) - 2):
		if s[i] == 'A' and s[i + 1] == 'B':
			if 'BA' in s[i + 2:]:
				flag = 1
				break
		elif s[i] == 'B' and s[i + 1] == 'A':
			if 'AB' in s[i + 2:]:
				flag = 1
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


inputstr = input()
strlen = len(inputstr)
ab = []
ba = []
import re
for m in re.finditer('AB', inputstr):
	ab.append([m.start(), m.end() - 1])
for m in re.finditer('BA', inputstr):
	ba.append([m.start(), m.end() - 1])
found = False
for i in range(len(ab)):
	for j in range(len(ba)):
		if ab[i][0] != ba[j][0] and ab[i][0] != ba[j][1] and (ab[i][1] != ba[j][0]) and (ab[i][1] != ba[j][1]):
			found = True
			break
	if found:
		break
if found:
	print('YES')
else:
	print('NO')


word = input()
(ab1, ab2) = (word.find('AB'), word.rfind('AB'))
(ba1, ba2) = (word.find('BA'), word.rfind('BA'))
if ab1 != -1 and ba1 != -1:
	if ab2 - ba1 > 1 or ba2 - ab1 > 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
idx = s.find('AB')
if idx != -1 and s.find('BA', idx + 2) != -1:
	print('YES')
else:
	idx = s.find('BA')
	if idx != -1 and s.find('AB', idx + 2) != -1:
		print('YES')
	else:
		print('NO')


import re
s = input()
s1 = 'AB'
s2 = 'BA'
if 'AB' not in s:
	print('NO')
else:
	m1 = re.finditer(s1, s)
	m2 = re.finditer(s2, s)
	l1 = [match.start() for match in m1]
	l2 = [match.start() for match in m2]
	for i in l1:
		for j in l2:
			if abs(i - j) >= 2:
				print('YES')
				exit(0)
	print('NO')


from math import *
from itertools import *
from collections import *
from bisect import *
s = input()
a = []
b = []
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		a.append(i)
	elif s[i:i + 2] == 'BA':
		b.append(i)
for i in a:
	for j in b:
		if abs(i - j) > 1:
			print('YES')
			exit(0)
print('NO')


string = input()
al = string.find('AB')
ar = string.rfind('AB')
bl = string.find('BA')
br = string.rfind('BA')
if al >= 0 and bl >= 0 and (br - al > 1 or ar - bl > 1):
	print('YES')
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase

def solution(s):
	n = len(s)
	if n <= 3:
		write('NO')
		return
	loc_a = None
	for i in range(n - 1):
		if s[i:i + 2] == 'AB':
			loc_a = (i, i + 1)
			break
	loc_b = None
	for i in range(n - 1):
		if s[i:i + 2] == 'BA':
			loc_b = (i, i + 1)
			break
	if loc_a:
		for i in range(n - 1):
			if s[i:i + 2] == 'BA':
				if i + 1 < loc_a[0]:
					write('YES')
					return
				if i > loc_a[1]:
					write('YES')
					return
	if loc_b:
		for i in range(n - 1):
			if s[i:i + 2] == 'AB':
				if i + 1 < loc_b[0]:
					write('YES')
					return
				if i > loc_b[1]:
					write('YES')
					return
	write('NO')

def main():
	s = input()
	solution(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


s = input()
one = -1
two = -1
for i in range(0, len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B' and (one == -1):
		one = i
	if s[i] == 'B' and s[i + 1] == 'A' and (two == -1):
		two = i
isTrue = False
for i in range(len(s) - 1, 1, -1):
	if s[i - 1] == 'A' and s[i] == 'B' and (two != -1) and (i > two + 2):
		isTrue = True
		break
	if s[i - 1] == 'B' and s[i] == 'A' and (one != -1) and (i > one + 2):
		isTrue = True
		break
if isTrue:
	print('YES')
else:
	print('NO')


_str = input()
a = 'AB'
b = 'BA'
_str1 = _str.replace(a, '__', 1).replace(b, '__', 1)
_str2 = _str.replace(b, '__', 1).replace(a, '__', 1)
if _str1.count('_') == 4 or _str2.count('_') == 4:
	print('YES')
else:
	print('NO')


s = input()
ab = s.find('AB')
ba = s.find('BA')

def lookForMyVariable(s):
	result = str
	if ab != -1 and s.find('BA', ab + 2) != -1 or (ba != -1 and s.find('AB', ba + 2) != -1):
		result = 'YES'
	else:
		result = 'NO'
	return result
print(lookForMyVariable(s))


s = input()
pA = -10
pB = -10
al = []
bl = []
for i in range(len(s)):
	if s[i] == 'A' and pA == -10:
		pA = i
	if s[i] == 'B' and pB == -10:
		pB = i
	if s[i] == 'A':
		if i - pB == 1:
			bl.append(i)
		pA = i
	if s[i] == 'B':
		if i - pA == 1:
			al.append(i)
		pB = i
br = False
for i in bl:
	if br:
		break
	tS = set(al[:])
	if i - 1 in tS:
		tS.remove(i - 1)
	if i + 1 in tS:
		tS.remove(i + 1)
	if len(tS) > 0:
		br = True
		break
if br:
	print('YES')
else:
	print('NO')


t = 1
for __ in range(t):
	s = input()
	s1 = 'AB'
	s2 = 'BA'
	(f, se) = (0, 0)
	n = len(s)
	i = 0
	while i < n - 1:
		if f == 1:
			if s2 == s[i:i + 2]:
				se = 1
				i += 1
		if s1 == s[i:i + 2] and f == 0:
			f = 1
			i += 1
		i += 1
	if f == 1 and se == 1:
		print('YES')
	else:
		(f, se) = (0, 0)
		i = 0
		i = 0
		while i < n - 1:
			if se == 1:
				if s1 == s[i:i + 2]:
					f = 1
					i += 1
			if s2 == s[i:i + 2] and se == 0:
				se = 1
				i += 1
			i += 1
		if f == se == 1:
			print('YES')
		else:
			print('NO')


import re
mystr = input()
r1 = mystr.find('AB')
r2 = mystr.rfind('BA')
if r1 != -1 and r2 != -1 and (r1 != r2 - 1) and (r2 != r1 - 1):
	print('YES')
else:
	r1 = mystr.find('BA')
	r2 = mystr.rfind('AB')
	if r1 != -1 and r2 != -1 and (r1 != r2 - 1) and (r2 != r1 - 1):
		print('YES')
	else:
		print('NO')


a = input()
n = len(a)
b = [False] * n
c = [False] * n
i = 1
ok = False
while i < n:
	b[i] = b[i - 1]
	c[i] = c[i - 1]
	if a[i - 1:i + 1] == 'AB':
		b[i] = 1
		if i > 1 and c[i - 2]:
			ok = 1
	if a[i - 1:i + 1] == 'BA':
		c[i] = 1
		if i > 1 and b[i - 2]:
			ok = 1
	i += 1
if ok:
	print('YES')
else:
	print('NO')


s = input()
s += '...'
ab = 'AB'
ba = 'BA'
i = s.find(ab)
if i == -1:
	print('NO')
else:
	a = s.find(ba)
	if a == -1:
		print('NO')
	elif a == i - 1:
		if s[i + 2:].find(ba) == -1:
			if s[i + 1:].find(ab) == -1:
				print('NO')
			else:
				print('YES')
		else:
			print('YES')
	elif a == i + 1:
		if s[i + 2:].find(ba) == -1:
			if s[i + 3:].find(ab) == -1:
				print('NO')
			else:
				print('YES')
		else:
			print('YES')
	else:
		print('YES')


s = input()
s2 = s
i = s.find('AB')
nfound = 1
if i != -1:
	s = s[:i] + 'F' + s[i + 2:]
	if s.find('BA') != -1:
		print('YES')
		exit()
i = s2.find('BA')
if i != -1:
	s2 = s2[:i] + 'f' + s2[i + 2:]
	if s2.find('AB') != -1:
		print('YES')
		exit()
if nfound:
	print('NO')


s = str(input())
i = 0
ab = []
ba = []
while i < len(s):
	if s[i:i + 2] == 'AB':
		ab.append(i)
	elif s[i:i + 2] == 'BA':
		ba.append(i)
	i += 1
if len(ab) == 0 or len(ba) == 0:
	print('NO')
else:
	for i in ab:
		for j in ba:
			if i - 1 != j and i + 1 != j:
				print('YES')
				quit()
	print('NO')


s = str(input())
ok1 = False
ok2 = False
ok = False
i = 0
s = s + 'ah'
while i < len(s) - 1:
	if s[i] == 'A' or s[i] == 'B':
		if ok1 == False:
			if s[i] == 'A' and s[i + 1] == 'B':
				ok1 = True
				i += 2
				continue
			elif s[i + 1] == 'A' and s[i + 2] == 'B':
				ok1 = True
				i += 3
				continue
		if s[i] == 'B' and s[i + 1] == 'A' and (ok2 == False):
			ok2 = True
			i += 1
	i += 1
i = 0
if ok1 and ok2:
	ok = True
ok1 = False
ok2 = False
while i < len(s) - 1:
	if s[i] == 'A' or s[i] == 'B':
		if ok2 == False:
			if s[i] == 'B' and s[i + 1] == 'A':
				ok2 = True
				i += 2
				continue
			elif s[i + 1] == 'B' and s[i + 2] == 'A':
				ok2 = True
				i += 3
				continue
		if s[i] == 'A' and s[i + 1] == 'B' and (ok1 == False):
			ok1 = True
			i += 1
	i += 1
if ok or (ok1 and ok2):
	print('YES')
else:
	print('NO')


def finder(input_str):
	idx = input_str.find('AB')
	if idx != -1:
		if input_str[idx + 2:].find('BA') != -1:
			return True
	idx = input_str.find('BA')
	if idx != -1:
		return input_str[idx + 2:].find('AB') != -1
print('YES' if finder(input()) else 'NO')


import sys
import math
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

def inputt():
	return sys.stdin.readline().strip()

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // gcd(a, b)

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True

def maxpower(n, x):
	B_max = int(math.log(n, x)) + 1
	return B_max
t = 1
for _ in range(t):
	s = inputt()
	if s.count('AB') + s.count('BA') - s.count('ABA') - s.count('BAB') >= 2 and s.count('AB') and (s.count('BA') > 0):
		printt('YES')
	else:
		printt('NO')


s = input()
ab_r = s.rfind('AB')
ab_l = s.find('AB')
ba_r = s.rfind('BA')
ba_l = s.find('BA')
if ab_l == -1 or ba_l == -1:
	print('NO')
	exit()
if abs(ab_r - ba_l) > 1 or abs(ab_l - ba_r) > 1:
	print('YES')
else:
	print('NO')


s = input()
y = 'YES'
if s.find('AB', s.find('BA') + 2) > 0 and s.find('BA') >= 0:
	print(y)
elif s.find('BA', s.find('AB') + 2) > 0 and s.find('AB') >= 0:
	print(y)
else:
	print('NO')


import sys
s = sys.stdin.readline()
i = s.find('AB')
j = s.find('BA')
if i != -1 and s.find('BA', i + 2) != -1:
	sys.stdout.write('YES\n')
elif j != -1 and s.find('AB', j + 2) != -1:
	sys.stdout.write('YES\n')
else:
	sys.stdout.write('NO\n')


a = str(input())
n = len(a)
p = 0
r = 'NO'
i = 0
while i < n - 1:
	if a[i] == 'B' and a[i + 1] == 'A' and (p == 1):
		r = 'YES'
	if a[i] == 'A' and a[i + 1] == 'B' and (p == 0):
		p = 1
		i = i + 1
	i = i + 1
p = 0
i = 0
while i < n - 1:
	if a[i] == 'A' and a[i + 1] == 'B' and (p == 1):
		r = 'YES'
	if a[i] == 'B' and a[i + 1] == 'A' and (p == 0):
		p = 1
		i = i + 1
	i = i + 1
print(r)


S = input()
N = len(S)
BA = 0
AB = 0
fla = 0
for i in range(1, N):
	if S[i] == 'A':
		if S[i - 1] == 'B':
			if AB == 0:
				BA += 1
			elif AB == 1 and S[i - 2] == 'A':
				BA += 1
				continue
			else:
				fla = 1
				break
	elif S[i] == 'B':
		if S[i - 1] == 'A':
			if BA == 0:
				AB += 1
			elif BA == 1 and S[i - 2] == 'B':
				AB += 1
				continue
			else:
				fla = 1
				break
if fla:
	print('YES')
else:
	print('NO')


s = input()
m = []
n = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		m.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		n.append(i)
if min(len(m), len(n)) == 0:
	print('NO')
elif max(len(m), len(n)) > 2:
	print('YES')
elif len(m) == 2 and len(n) == 2:
	print('YES')
elif len(m) == 1 and len(n) == 2:
	if max(m[0] - n[0], n[0] - m[0]) > 1 or max(m[0] - n[1], n[1] - m[0]) > 1:
		print('YES')
	else:
		print('NO')
elif len(n) == 1 and len(m) == 2:
	if max(n[0] - m[0], m[0] - n[0]) > 1 or max(n[0] - m[1], -n[0] + m[1]) > 1:
		print('YES')
	else:
		print('NO')
elif m[0] - n[0] > 1 or n[0] - m[0] > 1:
	print('YES')
else:
	print('NO')


s = input()
(a, a1, b, b1) = (s.count('AB'), s.count('BA'), s.count('ABA'), s.count('BAB'))
if a > 0 and a1 > 0 and (a + a1 - (b + b1) >= 2):
	print('YES')
else:
	print('NO')


s = input()
s = s.replace('C', 'Z')
s = s.replace('D', 'Z')
s2 = s
s = s.replace('AB', 'C', 1)
s = s.replace('BA', 'D', 1)
s2 = s2.replace('BA', 'C', 1)
s2 = s2.replace('AB', 'D', 1)
ans = s.find('C') != -1 and s.find('D') != -1 or (s2.find('C') != -1 and s2.find('D') != -1)
print('YES' * ans + 'NO' * (1 - ans))


string = input()
string1 = string[:]

def unsc(string):
	ab = string.find('AB')
	if ab == -1:
		return False
	else:
		string = string.replace('AB', ',', 1)
		ba = string.find('BA')
		if ba == -1:
			return False
		else:
			return True

def unsc1(string1):
	ba = string1.find('BA')
	if ba == -1:
		return False
	else:
		string1 = string1.replace('BA', ',', 1)
		ab = string1.find('AB')
		if ab == -1:
			return False
		else:
			return True
if unsc(string) == False and unsc1(string1) == False:
	print('NO')
else:
	print('YES')


s = input()
ans = False
a = s.find('AB')
if a != -1:
	if s[a + 2:].find('BA') != -1:
		ans = True
if not ans:
	a = s.find('BA')
	if a != -1:
		if s[a + 2:].find('AB') != -1:
			ans = True
print('YES' if ans else 'NO')


s = input()
n = len(s)
i = 0
f1 = 0
f2 = 0
while i < n - 1:
	if s[i] == 'A' and s[i + 1] == 'B':
		i += 2
		break
	i += 1
while i < n - 1:
	if s[i] == 'B' and s[i + 1] == 'A':
		f1 = 1
		break
	i += 1
i = 0
while i < n - 1:
	if s[i] == 'B' and s[i + 1] == 'A':
		i += 2
		break
	i += 1
while i < n - 1:
	if s[i] == 'A' and s[i + 1] == 'B':
		f2 = 1
		break
	i += 1
if f1 == 1 or f2 == 1:
	print('YES')
else:
	print('NO')


s = input()
(cA, cB, cABA, cBAB) = (0, 0, 0, 0)
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		cA += 1
	if s[i] == 'B' and s[i + 1] == 'A':
		cB += 1
for i in range(len(s) - 2):
	if s[i] == 'A' and s[i + 1] == 'B' and (s[i + 2] == 'A'):
		cABA += 1
	if s[i] == 'B' and s[i + 1] == 'A' and (s[i + 2] == 'B'):
		cBAB += 1
if cA * cB > 2 and cA - cABA - cBAB + cB >= 0 or (cA * cB > 0 and (cA - cABA - cBAB > 0 or cB - cABA - cBAB > 0)):
	print('YES')
else:
	print('NO')


s = input()
n = s.find('AB')
m = s.find('BA')
j = s.find('ABA')
k = s.find('BAB')
if m >= 0 or n >= 0 or j >= 0 or (k >= 0):
	if j >= 0 or k >= 0:
		if 'ABA' in s[0:j + 3] and ('AB' in s[j + 3:] or 'BA' in s[j + 3:]) or ('BAB' in s[0:k + 3] and ('AB' in s[k + 3:] or 'BA' in s[k + 3:])):
			print('YES')
		else:
			print('NO')
	elif m > n:
		if 'AB' in s[0:n + 2] and 'BA' in s[n + 2:]:
			print('YES')
		else:
			print('NO')
	elif n > m:
		if 'BA' in s[0:m + 2] and 'AB' in s[m + 2:]:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


s = input()
(c, ct) = (0, 0)
st = s
k = s.find('AB')
if k >= 0:
	s = s[:k] + 'XX' + s[k + 2:]
	ct = 1
k = s.find('BA')
if k >= 0:
	s = s[:k] + 'XX' + s[k + 2:]
	c = 1
(p, pt) = (0, 0)
k = st.find('BA')
if k >= 0:
	st = st[:k] + 'XX' + st[k + 2:]
	pt = 1
k = st.find('AB')
if k >= 0:
	st = st[:k] + 'XX' + st[k + 2:]
	p = 1
if ct == 1 and c == 1 or (pt == 1 and p == 1):
	print('YES')
else:
	print('NO')


s = input()
for i in range(len(s)):
	if i + 1 < len(s) and s[i:i + 2] == 'AB':
		for j in range(i + 2, len(s), 1):
			if s[j:j + 2] == 'BA':
				print('YES')
				exit()
		break
for i in range(len(s)):
	if i + 1 < len(s) and s[i:i + 2] == 'BA':
		for j in range(i + 2, len(s), 1):
			if s[j:j + 2] == 'AB':
				print('YES')
				exit()
		break
print('NO')


def ham(a, b):
	if a[1] == b[0] or b[1] == a[0]:
		return 0
	return 1
a = input()
ab = []
ba = []
for i in range(len(a) - 1):
	if a[i:i + 2] == 'AB':
		ab.append([i, i + 1])
	if a[i:i + 2] == 'BA':
		ba.append([i, i + 1])
s = 0
for i in range(len(ab)):
	for l in range(len(ba)):
		if ham(ab[i], ba[l]):
			print('YES')
			s = 1
			break
	if s == 1:
		break
if s == 0:
	print('NO')


s = input()
flag = 0
if s.find('AB') >= 0:
	temp = s.find('AB')
	if s.find('BA', temp + 2) >= 0:
		flag = 1
if s.find('BA') >= 0:
	temp = s.find('BA')
	if s.find('AB', temp + 2) >= 0:
		flag = 1
if flag == 1:
	print('YES')
else:
	print('NO')


s = input()
try:
	indAB = s.index('AB')
except:
	indAB = len(s)
try:
	indBA = s.index('BA')
except:
	indBA = len(s)
if 'BA' in s[indAB + 2:] or 'AB' in s[indBA + 2:]:
	print('YES')
else:
	print('NO')


import sys
r = input()
s = r[:]
f = 0
a = 'AB'
b = 'BA'
if s.find(a) != -1:
	j = s.find(a)
	t = s[j + 2:]
	if t.find(b) != -1:
		print('YES')
		sys.exit()
if s.find(b) != -1:
	j = s.find(b)
	t = s[j + 2:]
	if t.find(a) != -1:
		print('YES')
		sys.exit()
print('NO')


s = input()
a = -1
a1 = -1
b = -1
b1 = -1
for i in range(len(s) - 1):
	s1 = s[i:i + 2]
	if s1 == 'AB':
		if a == -1:
			a = i
		a1 = i
	elif s1 == 'BA':
		if b == -1:
			b = i
		b1 = i
if a == -1 or b == -1 or (abs(b1 - a) == 1 and abs(a1 - b) == 1):
	print('NO')
else:
	print('YES')


s = input()
(abH, abT) = (s.find('AB'), s.rfind('AB'))
(baH, baT) = (s.find('BA'), s.rfind('BA'))
flag = abH >= 0 and baT >= 0 and (baT - abH > 1) or (abT >= 0 and baH >= 0 and (abT - baH > 1))
print('YES' if flag else 'NO')


s = input()
ans = False
res = False
n = len(s)
i = 0
while i < n - 1:
	if s[i] == 'A':
		if s[i + 1] == 'B':
			ans = True
	if ans:
		i += 2
		while i < n - 1:
			if s[i] == 'B':
				if s[i + 1] == 'A':
					res = True
			i += 1
	if res:
		break
	i += 1
if res:
	print('YES')
else:
	ans = False
	i = 0
	while i < n - 1:
		if s[i] == 'B':
			if s[i + 1] == 'A':
				ans = True
		if ans:
			i += 2
			while i < n - 1:
				if s[i] == 'A':
					if s[i + 1] == 'B':
						res = True
				i += 1
		if res:
			break
		i += 1
	if res:
		print('YES')
	else:
		print('NO')


s = input()
a = s.count('AB')
b = s.count('BA')
if a * b == 0:
	print('NO')
elif a > 2 or b > 2:
	print('YES')
elif a == 2 and b == 2:
	print('YES')
elif a == 2 and b == 1:
	if s.count('ABAB') == 0:
		print('YES')
	else:
		print('NO')
elif a == 1 and b == 2:
	if s.count('BABA') == 0:
		print('YES')
	else:
		print('NO')
elif a == 1 and b == 1:
	if s.count('ABA') == 0 and s.count('BAB') == 0:
		print('YES')
	else:
		print('NO')


s = ''

def hasCombination(s):
	pos_first_AB = s.find('AB')
	pos_first_BA = s.find('BA')
	if pos_first_AB == -1 or pos_first_BA == -1:
		return False
	pos_last_AB = s.rfind('AB')
	pos_last_BA = s.rfind('BA')
	return abs(pos_first_AB - pos_first_BA) > 1 or abs(pos_first_AB - pos_last_BA) > 1 or abs(pos_last_AB - pos_first_BA) > 1
s = input()
if hasCombination(s):
	print('YES')
else:
	print('NO')


def check(string):
	if 'AB' in string and 'BA' in string.replace('AB', 'X', 1):
		return 'YES'
	if 'BA' in string and 'AB' in string.replace('BA', 'X', 1):
		return 'YES'
	return 'NO'
print(check(input()))


import sys
input = sys.stdin.readline
s = input()
ab = False
ba = False
for i in range(len(s) - 1):
	cur = s[i] + s[i + 1]
	if cur == 'AB' and ab is False:
		ab = True
		for j in range(i + 2, len(s) - 1):
			if s[j] + s[j + 1] == 'BA':
				print('YES')
				exit()
	elif cur == 'BA' and ba is False:
		ba = True
		for j in range(i + 2, len(s) - 1):
			if s[j] + s[j + 1] == 'AB':
				print('YES')
				exit()
print('NO')


s = input()
(a1, a2) = (s.find('AB'), s.rfind('AB'))
(b1, b2) = (s.find('BA'), s.rfind('BA'))
if abs(a1 - b1) < 2 and abs(a1 - b2) < 2 and (abs(a2 - b1) < 2) or min(a1, b1) == -1:
	print('NO')
else:
	print('YES')


s = input()
d = 'AB'
if not 'AB' in s or not 'BA' in s:
	print('NO')
else:
	g = s[s.index(d) + 2:]
	d = d[1] + d[0]
	if d in g:
		print('YES')
	else:
		g = s[s.index(d) + 2:]
		d = d[1] + d[0]
		if d in g:
			print('YES')
		else:
			print('NO')


s = input()
first_AB_index = -1
first_BA_index = -1
last_AB_index = -1
last_BA_index = -1
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AB':
		first_AB_index = i
		break
for i in range(len(s) - 1):
	if s[i:i + 2] == 'BA':
		first_BA_index = i
		break
for i in range(len(s) - 1, -1, -1):
	if s[i:i + 2] == 'AB':
		last_AB_index = i
		break
for i in range(len(s) - 1, -1, -1):
	if s[i:i + 2] == 'BA':
		last_BA_index = i
		break
if first_AB_index == -1 or first_BA_index == -1:
	print('NO')
elif first_AB_index + 2 <= last_BA_index or first_BA_index + 2 <= last_AB_index:
	print('YES')
else:
	print('NO')


s = input()
result = False
ab = s.find('AB')
ba = -1
if ab != -1:
	ba = s.find('BA', ab + 2)
	if ba != -1:
		result = True
if not result:
	ba = s.find('BA')
	if ba != -1:
		ab = s.find('AB', ba + 2)
		if ab != -1:
			result = True
if result:
	print('YES')
else:
	print('NO')


def find_str(a):
	temp = a
	count = a.count('AB')
	a = a.replace('AB', ' ', 1)
	count *= a.count('BA')
	if count:
		return 'YES' if count else 'NO'
	else:
		count = temp.count('BA')
		temp = temp.replace('BA', ' ', 1)
		count *= temp.count('AB')
		return 'YES' if count else 'NO'
a = input()
print(find_str(a))


def nonoverlapping(mystr):
	if mystr is None:
		return 'NO'
	(x1, x2) = (0, 0)
	x1 = mystr.find('AB')
	x2 = mystr.find('BA', x1 + 2)
	y1 = mystr.find('BA')
	y2 = mystr.find('AB', y1 + 2)
	if x1 != -1 and x2 != -1 or (y1 != -1 and y2 != -1):
		return 'YES'
	else:
		return 'NO'
my = str(input().strip())
print(nonoverlapping(my))


s = input()
i = 0
flag = 0
while i < len(s):
	if s[i:i + 2] == 'AB':
		if 'BA' in s[i + 2:]:
			print('YES')
			flag = 1
			break
	elif s[i:i + 2] == 'BA':
		if 'AB' in s[i + 2:]:
			print('YES')
			flag = 1
			break
	i += 1
if flag == 0:
	print('NO')


s = str(input())
a = []
b = []
for _ in range(len(s) - 1):
	if s[_:_ + 2] == 'AB':
		a.append(_)
	elif s[_:_ + 2] == 'BA':
		b.append(_)
if len(a) == 0 or len(b) == 0 or (abs(a[0] - b[-1]) < 2 and abs(b[0] - a[-1]) < 2):
	print('NO')
else:
	print('YES')


s = input()
l = [s[i:i + 2] for i in range(len(s) - 1)]
AB = [i for (i, x) in enumerate(l) if x == 'AB']
BA = [i for (i, x) in enumerate(l) if x == 'BA']
flag = 1
if len(AB) != 0 and len(BA) != 0:
	for i in AB:
		for j in BA:
			a = abs(i - j)
			if a <= 1:
				flag = 1
			else:
				flag = 0
				break
		if flag == 0:
			break
if flag == 0:
	print('YES')
else:
	print('NO')


s = input()
ab = []
ba = []
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'B':
		ab.append(i)
	if s[i] == 'B' and s[i + 1] == 'A':
		ba.append(i)
	if len(ab) > 0 and len(ba) > 0 and (abs(ab[0] - ba[-1]) > 1 or abs(ab[-1] - ba[0]) > 1):
		print('YES')
		exit()
print('NO')


import copy
si = list(input())
s = copy.deepcopy(si)
c1 = 0
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == ['A', 'B']:
		s[i] = '.'
		s[i + 1] = '.'
		c1 = 1
		break
	i += 1
c2 = 0
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == ['B', 'A']:
		s[i] = '.'
		s[i + 1] = '.'
		c2 = 1
		break
	i += 1
if c1 and c2:
	c3 = 1
else:
	c3 = 0
s = copy.deepcopy(si)
c2 = 0
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == ['B', 'A']:
		s[i] = '.'
		s[i + 1] = '.'
		c2 = 1
		break
	i += 1
c1 = 0
i = 0
while i < len(s) - 1:
	if s[i:i + 2] == ['A', 'B']:
		s[i] = '.'
		s[i + 1] = '.'
		c1 = 1
		break
	i += 1
if c1 and c2 or c3:
	print('YES')
else:
	print('NO')


s = input()
ab = 0
pre = -2
while ab != -1:
	ab = s.find('AB', pre + 2, len(s))
	pre = ab
	if ab == -1:
		pass
	else:
		ba = s.find('BA', 0, ab)
		if ba == -1:
			ba = s.find('BA', ab + 2, len(s))
			if ba == -1:
				pass
			else:
				print('YES')
				exit(0)
		else:
			print('YES')
			exit(0)
print('NO')


a = input()
f = False
q = False
p = -2
for i in range(len(a)):
	if i < len(a) - 1 and (not f) and (a[i] == 'A') and (a[i + 1] == 'B'):
		f = True
		p = i
	elif i < len(a) - 1 and f and (a[i] == 'B') and (a[i + 1] == 'A') and (p != i - 1):
		q = True
f1 = False
q1 = False
p1 = -2
for i in range(len(a)):
	if i < len(a) - 1 and (not f1) and (a[i] == 'B') and (a[i + 1] == 'A'):
		f1 = True
		p1 = i
	elif i < len(a) - 1 and f1 and (a[i] == 'A') and (a[i + 1] == 'B') and (p1 != i - 1):
		q1 = True
if q or q1:
	print('YES')
else:
	print('NO')


s = input()
da = {}
db = {}
for i in range(len(s) - 1):
	if s[i] + s[i + 1] == 'AB':
		da[i] = 1
	if s[i] + s[i + 1] == 'BA':
		db[i] = 1
if len(da) == len(db) == 1:
	for x in da:
		for y in db:
			if abs(x - y) > 1:
				print('YES')
			else:
				print('NO')
elif len(da) == 0 or len(db) == 0:
	print('NO')
elif len(da) == 1 and len(db) == 2:
	for x in da:
		for y in db:
			if abs(x - y) > 1:
				print('YES')
				break
		else:
			print('NO')
elif len(da) == 2 and len(db) == 1:
	for x in db:
		for y in da:
			if abs(x - y) > 1:
				print('YES')
				break
		else:
			print('NO')
else:
	print('YES')