description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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".
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])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR NUMBER VAR LIST VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR NUMBER VAR LIST VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING
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".
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())
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF STRING VAR STRING VAR IF STRING FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR STRING IF STRING FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
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".
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()
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
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".
_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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER VAR STRING NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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))
FUNC_DEF IF VAR NONE RETURN STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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".
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())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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 ] )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER NUMBER
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".
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)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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".
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())
ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING STRING STRING FUNC_CALL VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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" )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER STRING STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER IF STRING VAR VAR NUMBER IF STRING VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER IF STRING VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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))
FUNC_DEF IF FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING VAR STRING VAR LIST VAR IF VAR STRING VAR STRING VAR LIST VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR IF STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING
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".
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")
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
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".
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")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER RETURN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR STRING STRING FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
import sys 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") sys.exit(0)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
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".
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])
ASSIGN VAR DICT NUMBER NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR STRING VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING VAR BIN_OP VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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))
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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".
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")
ASSIGN VAR VAR VAR FUNC_CALL VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR LIST VAR LIST EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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 ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF NONE FUNC_DEF WHILE VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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".
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))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR FUNC_DEF FOR VAR VAR STRING FOR VAR VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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 ] )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER NUMBER
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
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".
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()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER STRING STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
from sys import exit 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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING
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".
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])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER VAR NUMBER IF STRING VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER VAR NUMBER IF STRING VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR NUMBER
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".
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")
ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR STRING FOR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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".
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")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING