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() a = s.count("AB") b = s.count("BA") c = s.count("ABA") d = s.count("BAB") print(["NO", "YES"][(a + b) * (a != 0 and b != 0) - c - d > 1])
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 EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER 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".
ss = input() flag = flag2 = 0 s = ss if "AB" in s: s = s.replace("AB", "X", 1) flag = 1 if "BA" in s: s = s.replace("BA", "X", 1) flag2 = 1 if flag == 0 or flag2 == 0: flag = flag2 = 0 s = ss if "BA" in s: s = s.replace("BA", "X", 1) flag2 = 1 if "AB" in s: s = s.replace("AB", "X", 1) flag = 1 if flag == 1 and flag2 == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN 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".
s = input() l = [s[i : i + 2] for i in range(len(s) - 1)] AB = [i for i, x in enumerate(l) if x == "AB"] BA = [i for i, x in enumerate(l) if x == "BA"] flag = 1 if len(AB) != 0 and len(BA) != 0: for i in AB: for j in BA: a = abs(i - j) if a <= 1: flag = 1 else: flag = 0 break if flag == 0: break if flag == 0: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF 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 not "AB" in s: print("NO") elif not "BA" in s.replace("AB", " ", 1): if "BA" in s: if not "AB" in s.replace("BA", " ", 1): print("NO") else: print("YES") else: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR STRING IF STRING FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR IF STRING FUNC_CALL VAR STRING STRING 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() print( "YNEOS"[ not ("AB" in s and "BA" in s.replace("AB", "X", 1)) and not ("BA" in s and "AB" in s.replace("BA", "X", 1)) :: 2 ] )
ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING STRING VAR STRING FUNC_CALL VAR STRING STRING NUMBER STRING VAR STRING FUNC_CALL VAR STRING 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() ans1 = [] ans2 = [] if len(s) < 2: print("NO") else: for i in range(1, len(s)): if s[i - 1] == "A" and s[i] == "B": ans1.append("AB") i += 2 break for e in range(i, len(s)): if s[e - 1] == "B" and s[e] == "A": ans1.append("BA") i += 2 break for i in range(1, len(s)): if s[i - 1] == "B" and s[i] == "A": ans2.append("BA") i += 2 break for e in range(i, len(s)): if s[e - 1] == "A" and s[e] == "B": ans2.append("AB") i += 2 break if ( ans1.count("AB") == 1 and ans1.count("BA") == 1 or ans2.count("AB") == 1 and ans2.count("BA") == 1 ): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING 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".
s = input() y = "YES" if s.find("AB", s.find("BA") + 2) > 0 and s.find("BA") >= 0: print(y) elif s.find("BA", s.find("AB") + 2) > 0 and s.find("AB") >= 0: print(y) else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING IF FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER FUNC_CALL VAR STRING 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".
s = input() a = None b = None for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": if a is None: a = i if b is not None and abs(i - b) > 1: print("YES") exit(0) if s[i] == "B" and s[i + 1] == "A": if b is None: b = i if a is not None and abs(a - i) > 1: print("YES") exit(0) print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NONE ASSIGN VAR VAR IF VAR NONE FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NONE ASSIGN VAR VAR IF VAR NONE 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".
s = input() ABfirst = s.find("AB") BAfirst = s.find("BA") if ABfirst == -1 or BAfirst == -1: print("NO") elif abs(ABfirst - BAfirst) > 1: print("YES") else: next_pos = min(ABfirst, BAfirst) + 3 if s.find("AB", next_pos) >= 0 or s.find("BA", next_pos) >= 0: print("YES") else: print("NO")
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 FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR STRING VAR NUMBER FUNC_CALL VAR STRING 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 = "a" + input() + "a" cab, cba = [], [] for i in range(1, len(s) - 1): if s[i : i + 2] == "AB": cab.append(i) for j in cba: if j != i - 1 and j != i + 1: print("YES") exit() elif s[i : i + 2] == "BA": cba.append(i) for j in cab: if j != i - 1 and j != i + 1: print("YES") exit() print("NO")
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP 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() sc = s y = len(s) s = s.replace("AB", ";);", 1) s = s.replace("BA", ";);", 1) sc = sc.replace("BA", ";);", 1) sc = sc.replace("AB", ";);", 1) print("YES" if y + 2 in (len(s), len(sc)) else "NO")
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 NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR 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".
check = 0 s = input() t = s if "AB" in s: s = s.replace("AB", "*", 1) if "BA" in s: check += 1 if "BA" in t: t = t.replace("BA", "*", 1) if "AB" in t: check += 1 print("YES" if check > 0 else "NO")
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR 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".
string = input() AB = [] BA = [] for i in range(len(string) - 1): current = string[i : i + 2] if current == "AB": AB.append(i) elif current == "BA": BA.append(i) result = "NO" for item1 in AB: for item2 in BA: if abs(item1 - item2) > 1: result = "YES" break print(result)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR 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() i, j = 0, len(s) - 1 lab, lba, rab, rba = -999999, -999999, -999999, -999999 while i <= len(s) - 2 and j >= 1: if (s[i] == "A" and s[i + 1] == "B") and lab == -999999: lab = i if (s[i] == "B" and s[i + 1] == "A") and lba == -999999: lba = i if (s[j - 1] == "B" and s[j] == "A") and rba == -999999: rba = j - 1 if (s[j - 1] == "A" and s[j] == "B") and rab == -999999: rab = j - 1 if lab != -999999 and lba != -999999 and rab != -999999 and rba != -999999: break i += 1 j -= 1 m = max(lab, rba) - min(lab, rba) n = max(lba, rab) - min(lba, rab) if m >= 2 and m <= 100000 or n >= 2 and n <= 100000: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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".
import sys inputStr = input() if "AB" in inputStr: i = inputStr.index("AB") if "BA" in inputStr[:i] or "BA" in inputStr[i + 2 :]: print("YES") sys.exit() if "BA" in inputStr: i = inputStr.index("BA") if "AB" in inputStr[:i] or "AB" in inputStr[i + 2 :]: print("YES") sys.exit() print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR BIN_OP 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".
str = input() condition = False i = 0 for i in range(0, len(str)): if str[i : i + 2] == "AB": break j = i + 2 for i in range(j, len(str)): if str[i : i + 2] == "BA": condition = True break if condition == True: print("YES") else: for i in range(0, len(str)): if str[i : i + 2] == "BA": break j = i + 2 for i in range(j, len(str)): if str[i : i + 2] == "AB": condition = True break if condition == True: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN 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".
a = input() f = False q = False p = -2 for i in range(len(a)): if i < len(a) - 1 and not f and a[i] == "A" and a[i + 1] == "B": f = True p = i elif i < len(a) - 1 and f and a[i] == "B" and a[i + 1] == "A" and p != i - 1: q = True f1 = False q1 = False p1 = -2 for i in range(len(a)): if i < len(a) - 1 and not f1 and a[i] == "B" and a[i + 1] == "A": f1 = True p1 = i elif i < len(a) - 1 and f1 and a[i] == "A" and a[i + 1] == "B" and p1 != i - 1: q1 = True if q or q1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP 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() i = 0 ans = False if ( min(s.count("AB"), s.count("BA")) >= 1 and s.count("AB") + s.count("BA") - int("BAB" in s) - int("ABA" in s) >= 2 ): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING 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".
str2 = input() def test(str1): if str1.count("AB") >= 1: str1 = str1.replace("AB", "Z", 1) if str1.count("BA") >= 1: return True else: return False else: return False def test1(str1): if str1.count("BA") >= 1: str1 = str1.replace("BA", "Z", 1) if str1.count("AB") >= 1: return True else: return False else: return False if test(str2) or test1(str2): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR 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() a = list(s) pos1 = [] pos2 = [] for i in range(len(s) - 1): if s[i] == "A" and a[i + 1] == "B": pos1.append([i, i + 1]) for i in range(len(s) - 1): if s[i] == "B" and s[i + 1] == "A": pos2.append([i, i + 1]) if len(pos1) == 0 or len(pos2) == 0: print("NO") elif len(pos1) == 0: print("NO") elif len(pos2) == 0: print("NO") else: i = 0 m = len(pos2) - 1 ans = False while i < len(pos1): j = m while j >= 0: if ( pos1[i][0] != pos2[j][0] and pos1[i][0] != pos2[j][1] and pos1[i][1] != pos2[j][0] and pos1[i][1] != pos2[j][1] ): ans = True break j = j - 1 if ans: break if ans: break i += 1 if ans == True: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 LIST VAR BIN_OP VAR NUMBER 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 FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR IF 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".
def solution(): s = input() current_a = -2 current_b = -2 ab = [] ba = [] for i in range(len(s)): if s[i] == "A": current_a = i if s[i] == "B" and current_a == i - 1: ab.append((i - 1, i)) for j in range(len(s)): if s[j] == "B": current_b = j if s[j] == "A" and current_b == j - 1: ba.append((j - 1, j)) for k in range(len(ab)): for l in range(len(ba)): if not ab[k][0] == ba[l][1] and not ab[k][1] == ba[l][0]: print("YES") return print("NO") solution()
FUNC_DEF 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 ASSIGN VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN 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 = str(input()) i = 0 arr1 = [] arr2 = [] while i < len(s) - 1: if s[i] == "A" and s[i + 1] == "B": arr1.append(i) if s[i] == "B" and s[i + 1] == "A": arr2.append(i) i += 1 if len(arr1) == 0 or len(arr2) == 0: print("NO") elif max(len(arr1), len(arr2)) > 2 and min(len(arr1), len(arr2)) >= 1: print("YES") elif len(arr1) == 2 and len(arr2) == 2: print("YES") elif len(arr1) == 2 and len(arr2) == 1: if arr1[0] + 1 == arr2[0] and arr1[1] == arr2[0] + 1: print("NO") else: print("YES") elif len(arr1) == 1 and len(arr2) == 2: if arr2[0] + 1 == arr1[0] and arr2[1] == arr1[0] + 1: print("NO") else: print("YES") elif arr1[0] + 1 == arr2[0] or arr2[0] + 1 == arr1[0]: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE 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 VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF 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".
def substrings(s): a = s.count("AB") b = s.count("BA") c = s.count("ABA") d = s.count("BAB") if (a != 0 and b != 0) and a + b - c - d > 1: return "YES" else: return "NO" s = input() print(substrings(s))
FUNC_DEF 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 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 = input() for i in range(len(s)): if i + 1 < len(s) and s[i : i + 2] == "AB": for j in range(i + 2, len(s), 1): if s[j : j + 2] == "BA": print("YES") exit() break for i in range(len(s)): if i + 1 < len(s) and s[i : i + 2] == "BA": for j in range(i + 2, len(s), 1): if s[j : j + 2] == "AB": print("YES") exit() break print("NO")
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR 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".
def solve(): a = s.find("AB") b = s.rfind("AB") c = s.find("BA") d = s.rfind("BA") found = (abs(a - d) > 1 or abs(b - c) > 1) and min(a, b, c, d) >= 0 return "NO YES".split()[found] def main(): global s s = input() print(solve()) main()
FUNC_DEF 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 BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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".
s = input() ab = 0 pre = -2 while ab != -1: ab = s.find("AB", pre + 2, len(s)) pre = ab if ab == -1: pass else: ba = s.find("BA", 0, ab) if ba == -1: ba = s.find("BA", ab + 2, len(s)) if ba == -1: pass else: print("YES") exit(0) else: print("YES") exit(0) print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL 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".
s = input() def helper(s, seq): for x in range(len(s) - 1): if s[x] == seq[0] and s[x + 1] == seq[1]: return True return False def f(s): if len(s) < 4: return False else: count = 0 for x in range(len(s) - 1): if s[x] == "B" and s[x + 1] == "A": count += 1 if helper(s[x + 2 :], "AB"): return True elif count == 2: return False if s[x] == "A" and s[x + 1] == "B": count += 1 if helper(s[x + 2 :], "BA"): return True elif count == 2: return False return False if not f(s): print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN 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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING RETURN NUMBER IF VAR 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".
l = input() a = 0 b = 0 for i in range(len(l) - 2): if l[i] == "A" and l[i + 1] == "B" and l[i + 2] != "A": a = 1 if l[i] == "B" and l[i + 1] == "A" and l[i + 2] != "B": b = 1 if l[len(l) - 3 :] != "BAB" and l[len(l) - 2 :] == "AB": a = 1 if l[len(l) - 3 :] != "ABA" and l[len(l) - 2 :] == "BA": b = 1 c = 0 d = 0 k = 0 j = 0 for i in range(len(l) - 1): if l[i] == "A" and l[i + 1] == "B" and c == 0: c = 1 k = i + 1 if l[i] == "B" and l[i + 1] == "A" and c == 1 and i != k: a = 1 b = 1 if l[i] == "B" and l[i + 1] == "A" and d == 0: d = 1 j = i + 1 if l[i] == "A" and l[i + 1] == "B" and d == 1 and j != i: a = 1 b = 1 if a + b == 2: print("YES") else: print("NO")
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 BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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".
def search_podstroki(s, t): t1 = t + "$" + s p = [-1] * len(t1) prefix(t1, p) c1 = 0 for i in range(1, len(t1)): if p[i] == len(t) - 1: c1 = -1 return i - len(t) - 1 if c1 != -1: return False def prefix(t, p): k = 0 for i in range(1, len(t)): k = p[i - 1] while k >= 0 and t[k + 1] != t[i]: k = p[k] if t[k + 1] == t[i]: k = k + 1 p[i] = k s = input() s1 = "AB" s2 = "BA" r = search_podstroki(s, s1) if r == False: print("NO") else: s3 = s[r + 1 :] e = search_podstroki(s3, s2) if e == False: r = search_podstroki(s, s2) if r == False: print("NO") else: s3 = s[r + 1 :] e = search_podstroki(s3, s1) if e == False: print("NO") else: print("YES") else: print("YES")
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR 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".
string = list(input()) n = len(string) i = 0 checkAB = [] checkBA = [] while i < n - 1: if string[i] == "A" and string[i + 1] == "B": checkAB.append([i, i + 1]) elif string[i] == "B" and string[i + 1] == "A": checkBA.append([i, i + 1]) i += 1 check = False for x in checkAB: for y in checkBA: if x[0] not in y and x[1] not in y: check = True break if check: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE 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 IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR 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".
a = input() if "AB" in a: if "BA" in a[a.index("AB") + 2 :]: exit(print("YES")) if "BA" in a: if "AB" in a[a.index("BA") + 2 :]: exit(print("YES")) print("NO")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR IF STRING VAR BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF STRING VAR IF STRING VAR BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR 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 exit def func(): s = input().strip() AIDX = [] BIDX = [] for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": AIDX.append(i) if s[i] == "B" and s[i + 1] == "A": BIDX.append(i) if len(AIDX) == 0 or len(BIDX) == 0: print("NO") return if ( abs(min(AIDX) - min(BIDX)) > 1 or abs(max(AIDX) - min(BIDX)) > 1 or abs(max(BIDX) - min(AIDX)) > 1 ): print("YES") else: print("NO") func()
FUNC_DEF ASSIGN VAR FUNC_CALL 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 RETURN 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 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
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) abl, abr = s.find("AB"), s.rfind("AB") bal, bar = s.find("BA"), s.rfind("BA") if abl >= 0 and bar >= 0 and abs(abl - bar) > 1: print("YES") elif bal >= 0 and abr >= 0 and abs(bal - abr) > 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER FUNC_CALL 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() check1 = 0 check2 = 0 word1 = [] word2 = [] for i in range(len(s)): word1.append(s[i]) word2.append(s[i]) if len(word1) <= 3: print("NO") else: for i in range(len(word1) - 1): if word1[i] == "A" and word1[i + 1] == "B" and check1 == 0: check1 += 1 word1[i] = 0 word1[i + 1] = 0 elif word1[i] == "B" and word1[i + 1] == "A" and check1 > 0: check2 += 1 word1[i] = 0 word1[i + 1] = 0 if check1 > 0 and check2 > 0: print("YES") else: check1 = check2 = 0 for i in range(len(word2) - 1): if word2[i] == "B" and word2[i + 1] == "A" and check1 == 0: check1 += 1 word2[i] = 0 word2[i + 1] = 0 elif word2[i] == "A" and word2[i + 1] == "B" and check1 > 0: check2 += 1 word2[i] = 0 word2[i + 1] = 0 if check1 > 0 and check2 > 0: print("YES") else: print("NO")
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 EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN 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 VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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".
a = input() ab = 0 ba = 0 all = 0 i = 1 while i < len(a): if a[i - 1] + a[i] == "AB": c = "B" i1 = i - 1 while i < len(a) and a[i] == c: i += 1 if c == "B": c = "A" else: c = "B" ln = i - i1 if ln == 2: ab += 1 elif ln == 3 or ln == 4: all += 1 else: all += 2 break elif a[i - 1] + a[i] == "BA": c = "A" i1 = i - 1 while i < len(a) and a[i] == c: i += 1 if c == "B": c = "A" else: c = "B" ln = i - i1 if ln == 2: ba += 1 elif ln == 3 or ln == 4: all += 1 else: all += 2 break i += 1 if bool(ab) and bool(ba) or bool(all) and (bool(ab) or bool(ba)) or all > 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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".
s = input().strip() acnt, bcnt = 0, 0 MaxA, MaxB, MinA, MinB = -1, -1, 9999999999999, 9999999999999 for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": acnt += 1 if i < MinA: MinA = i if i > MaxA: MaxA = i if s[i] == "B" and s[i + 1] == "A": bcnt += 1 if i < MinB: MinB = i if i > MaxB: MaxB = i if (acnt >= 1 and bcnt >= 1) and (MaxB - MinA > 1 or MaxA - MinB > 1): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER 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 ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER 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".
string = str(input()) flag = False for i in range(len(string) - 1): if string[i] + string[i + 1] == "AB": if "BA" in string[:i]: flag = True if "BA" in string[i + 2 :]: flag = True if flag: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 IF STRING VAR VAR ASSIGN VAR NUMBER IF STRING VAR BIN_OP 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 = [i for i in input()] n = len(s) fx = False fy = False i = 0 while i < n: if s[i] == "A": if i + 1 < n and fx is False: if s[i + 1] == "B": fx = True i += 2 break i += 1 while i < n: if s[i] == "B": if i + 1 < n and fy is False: if s[i + 1] == "A": fy = True i += 2 break i += 1 if fx and fy: print("YES") else: fx = False fy = False i = 0 while i < n: if s[i] == "B": if i + 1 < n and fx is False: if s[i + 1] == "A": fx = True i += 2 break i += 1 while i < n: if s[i] == "A": if i + 1 < n and fy is False: if s[i + 1] == "B": fy = True i += 2 break i += 1 if fx and fy: print("YES") else: print("NO")
ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER 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".
s = input() l = len(s) idx = -1 for i in range(l - 1): if s[i] == "A" and s[i + 1] == "B": idx = i + 1 break flag = 0 if idx != -1: for i in range(idx + 1, l - 1): if s[i] == "B" and s[i + 1] == "A": flag = 1 break if flag == 1: print("YES") else: idx = -1 for i in range(l - 1): if s[i] == "B" and s[i + 1] == "A": idx = i + 1 break flag = 0 if idx != -1: for i in range(idx + 1, l - 1): if s[i] == "A" and s[i + 1] == "B": flag = 1 break if flag == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN 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 ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN 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 ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN 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".
def work(): for i in a: for j in b: if abs(i - j) >= 2: return True return False s = input() l = len(s) a = [] b = [] for i in range(l - 1): if s[i] + s[i + 1] == "AB": a.append(i) elif s[i] + s[i + 1] == "BA": b.append(i) if a and b: if work(): print("YES") else: print("NO") else: print("NO")
FUNC_DEF FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST 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 IF VAR VAR IF FUNC_CALL 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".
a = input() k = len(a) ab = 0 ba = 0 aba = 0 bab = 0 m = 0 for i in range(0, k - 2): if a[i] == "A" and a[i + 1] == "B" and a[i + 2] == "A" and i + 2 < k: aba = aba + 1 break elif a[i] == "A" and a[i + 1] == "B" and i + 1 < k: ab = ab + 1 break elif a[i] == "B" and a[i + 1] == "A" and a[i + 2] == "B" and i + 2 < k: bab = bab + 1 break elif a[i] == "B" and a[i + 1] == "A" and i + 1 < k: ba = ba + 1 break if aba > 0: for j in range(i + 3, k - 1): if a[j] == "A" and a[j + 1] == "B": ab = ab + 1 break elif a[j] == "B" and a[j + 1] == "A": ba = ba + 1 break if ab > 0 or ba > 0: m = 1 print("YES") elif ab > 0: for j in range(i + 2, k - 1): if a[j] == "B" and a[j + 1] == "A": ba = ba + 1 break if ba > 0: m = 1 print("YES") elif bab > 0: for j in range(i + 3, k - 1): if a[j] == "A" and a[j + 1] == "B": ab = ab + 1 break elif a[j] == "B" and a[j + 1] == "A": ba = ba + 1 break if ab > 0 or ba > 0: m = 1 print("YES") elif ba > 0: for j in range(i + 2, k - 1): if a[j] == "A" and a[j + 1] == "B": ab = ab + 1 break if ab > 0: m = 1 print("YES") if m == 0: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN 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 VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER 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() ab = s.find("AB") ba = s.find("BA") def lookForMyVariable(s): result = str if ( ab != -1 and s.find("BA", ab + 2) != -1 or ba != -1 and s.find("AB", ba + 2) != -1 ): result = "YES" else: result = "NO" return result print(lookForMyVariable(s))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR IF VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING RETURN 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 = input() n = len(s) s1 = s[::-1] count = 0 if "AB" in s and "AB" in s1: if s.index("BA") < n - 1 - s1.index("BA"): if s.index("BA") + 1 != n - 1 - s1.index("BA") - 1: count += 2 else: count -= 1 if s.index("AB") < n - 1 - s1.index("AB"): if s.index("AB") + 1 != n - 1 - s1.index("AB") - 1: count += 2 else: count -= 1 if count <= 0: print("NO") else: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR STRING VAR IF FUNC_CALL VAR STRING BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR NUMBER 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".
n = input() res = "NO" mylist = ["BABAB", "BAAAB", "ABABA", "ABBBA"] if "ABA" not in n and "BAB" not in n: if "AB" in n and "BA" in n: res = "YES" else: for i in mylist: if i in n: res = "YES" if "ABA" in n: n = n.replace("ABA", "", 1) if "AB" in n or "BA" in n: res = "YES" elif "BAB" in n: n = n.replace("BAB", "", 1) if "AB" in n or "BA" in n: res = "YES" print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST STRING STRING STRING STRING IF STRING VAR STRING VAR IF STRING VAR STRING VAR ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR STRING VAR ASSIGN VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR STRING VAR 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".
sequence = str(input()) variant_first = sequence.replace("AB", "5", 1).replace("BA", "9", 1) variant_two = sequence.replace("BA", "4", 1).replace("AB", "2", 1) if ( "5" in variant_first and "9" in variant_first or "2" in variant_two and "4" in variant_two ): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER STRING STRING NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER STRING STRING NUMBER IF STRING VAR STRING VAR STRING VAR 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() N = len(S) BA = 0 AB = 0 fla = 0 for i in range(1, N): if S[i] == "A": if S[i - 1] == "B": if AB == 0: BA += 1 elif AB == 1 and S[i - 2] == "A": BA += 1 continue else: fla = 1 break elif S[i] == "B": if S[i - 1] == "A": if BA == 0: AB += 1 elif BA == 1 and S[i - 2] == "B": AB += 1 continue else: fla = 1 break if fla: print("YES") else: print("NO")
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 VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING 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".
arr = input() n = len(arr) ab = 0 ba = 0 ab2 = 0 ba2 = 0 check = 0 mark = [(0) for _ in range(n)] mark2 = [(0) for _ in range(n)] for i in range(n - 1): if arr[i] == "A" and arr[i + 1] == "B" and ab == 0: if mark[i] == 0 and mark[i + 1] == 0: ab += 1 mark[i] = 1 mark[i + 1] = 1 elif arr[i] == "B" and arr[i + 1] == "A" and ba == 0: if mark[i] == 0 and mark[i + 1] == 0: ba += 1 mark[i] = 1 mark[i + 1] = 1 if arr[n - 2 - i] == "A" and arr[n - 1 - i] == "B" and ab2 == 0: if mark2[n - 2 - i] == 0 and mark2[n - 1 - i] == 0: ab2 += 1 mark2[n - 2 - i] = 1 mark2[n - 1 - i] = 1 elif arr[n - 2 - i] == "B" and arr[n - 1 - i] == "A" and ba2 == 0: if mark2[n - 2 - i] == 0 and mark2[n - 1 - i] == 0: ba2 += 1 mark2[n - 2 - i] = 1 mark2[n - 1 - i] = 1 if ab == ba == 1 or ab2 == ba2 == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER 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() first_AB_index = -1 first_BA_index = -1 last_AB_index = -1 last_BA_index = -1 for i in range(len(s) - 1): if s[i : i + 2] == "AB": first_AB_index = i break for i in range(len(s) - 1): if s[i : i + 2] == "BA": first_BA_index = i break for i in range(len(s) - 1, -1, -1): if s[i : i + 2] == "AB": last_AB_index = i break for i in range(len(s) - 1, -1, -1): if s[i : i + 2] == "BA": last_BA_index = i break if first_AB_index == -1 or first_BA_index == -1: print("NO") elif first_AB_index + 2 <= last_BA_index or first_BA_index + 2 <= last_AB_index: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR 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 BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR 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".
s = input() pos = -1 pos1 = -1 for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": pos = i break for i in range(len(s) - 1, 0, -1): if s[i] == "A" and s[i - 1] == "B": pos1 = i - 1 break pos2 = -1 pos3 = -1 for i in range(len(s) - 1): if s[i] == "B" and s[i + 1] == "A": pos2 = i break for i in range(len(s) - 1, 0, -1): if s[i] == "B" and s[i - 1] == "A": pos3 = i - 1 break if pos == -1 or pos1 == -1: flag = False elif abs(pos - pos1) > 1: flag = True else: flag = False if flag: print("YES") elif pos2 == -1 or pos3 == -1: print("NO") elif abs(pos2 - pos3) > 1: print("YES") else: print("NO")
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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR 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 BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR 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 ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL 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".
def containsNonOverlappingABandBA(string): ABmatches = matchingPositions(string, "AB") BAmatches = matchingPositions(string, "BA") return contains(ABmatches, BAmatches) and not overlap(ABmatches, BAmatches) def matchingPositions(string, substring): return set(i for i in range(len(string) - 1) if match(string, i, substring)) def match(string, i, substring): return string[i : i + len(substring)] == substring def contains(ABmatches, BAmatches): return len(ABmatches) != 0 and len(BAmatches) != 0 def overlap(ABmatches, BAmatches): return ( len(ABmatches) < 3 and len(BAmatches) < 3 and all(abs(ABpos - BApos) < 2 for ABpos in ABmatches for BApos in BAmatches) ) print("YES" if containsNonOverlappingABandBA(input()) else "NO")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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() abfound = bafound = -1 for i in range(len(s) - 1): if abfound == -1 and s[i] == "A" and s[i + 1] == "B": abfound = i elif bafound == -1 and s[i] == "B" and s[i + 1] == "A": bafound = i if abfound != -1 and bafound != -1: break if abfound == -1 or bafound == -1: print("NO") exit(0) if abfound == bafound + 1 or bafound == abfound + 1: for i in range(max(bafound + 2, abfound + 2), len(s) - 1): if s[i] == "A" and s[i + 1] == "B": newabfound = True print("YES") exit(0) elif s[i] == "B" and s[i + 1] == "A": newbafound = True print("YES") exit(0) else: print("YES") exit(0) print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL 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".
import sys ab = [] ba = [] def search(txt): prev = txt[0] global ab global ba for i in range(1, len(txt)): cur = txt[i] if prev == "A" and cur == "B": ab.append(i - 1) if prev == "B" and cur == "A": ba.append(i - 1) prev = cur txt = input() search(txt) for item in ab: for item2 in ba: if item2 != item + 1 and item2 != item - 1: print("YES") sys.exit() print("NO")
IMPORT ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP 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".
string = input() index1 = [] index2 = [] judge = False if "AB" not in string or "BA" not in string: print("NO") else: for i in range(len(string) - 1): if string[i] == "A" and string[i + 1] == "B": index1.append(i) elif string[i] == "B" and string[i + 1] == "A": index2.append(i) for i in index1: for j in index2: if abs(i - j) != 1: judge = True break if judge == True: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING 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 VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN 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 = list(input()) def test_target(self, target, p): for i in target: if p - i > 1: return True self.append(p) return False AB_list = list() BA_list = list() for i in range(1, len(S)): if S[i - 1] == "A" and S[i] == "B": if test_target(AB_list, BA_list, i): print("YES") break if S[i - 1] == "B" and S[i] == "A": if test_target(BA_list, AB_list, i): print("YES") break else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING IF FUNC_CALL VAR 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".
s = input() n = s.find("AB") m = s.find("BA") j = s.find("ABA") k = s.find("BAB") if m >= 0 or n >= 0 or j >= 0 or k >= 0: if j >= 0 or k >= 0: if ( "ABA" in s[0 : j + 3] and ("AB" in s[j + 3 :] or "BA" in s[j + 3 :]) or "BAB" in s[0 : k + 3] and ("AB" in s[k + 3 :] or "BA" in s[k + 3 :]) ): print("YES") else: print("NO") elif m > n: if "AB" in s[0 : n + 2] and "BA" in s[n + 2 :]: print("YES") else: print("NO") elif n > m: if "BA" in s[0 : m + 2] and "AB" in s[m + 2 :]: print("YES") else: print("NO") else: print("NO")
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 VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP 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".
from sys import stdin, stdout s = stdin.readline().strip() lAB = s.find("AB") rAB = s.rfind("AB") lBA = s.find("BA") rBA = s.rfind("BA") if lAB == -1 or lBA == -1: stdout.write("NO") elif lAB + 1 < rBA: stdout.write("YES") elif lBA + 1 < rAB: stdout.write("YES") else: stdout.write("NO") stdout.write("\n")
ASSIGN VAR FUNC_CALL 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 IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER 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 w = str(input().strip()) c = w.find("AB") while c != -1: c2 = w.find("BA", 0, c) if c2 == -1: c2 = w.find("BA", c + 2) else: print("YES") sys.exit() if c2 == -1: c = w.find("AB", c + 2) else: print("YES") sys.exit() print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP 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".
string = input() output = False if "AB" in string and not output: string2 = string.replace("AB", "*", 1) if "BA" in string2: print("YES") output = True if "BA" in string and not output: string2 = string.replace("BA", "*", 1) if "AB" in string2: print("YES") output = True if not output: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR 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() fl = False t = s.find("BA") if t != -1: x = s[t + 2 :] if x.find("AB") != -1: fl = True t = s.find("AB") if t != -1: x = s[t + 2 :] if x.find("BA") != -1: fl = True if fl: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING 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 find(d, t1, t2): for i in range(len(d)): if i + 1 < len(d) and d[i] == t1 and d[i + 1] == t2: return True return False def solve(d): found = False ind = 0 n = len(d) f = True l = True while ind < n: if f and d[ind] == "A" and ind + 1 < n and d[ind + 1] == "B": found = find(d[ind + 2 :], "B", "A") f = False elif l and d[ind] == "B" and ind + 1 < n and d[ind + 1] == "A": found = find(d[ind + 2 :], "A", "B") l = False ind += 1 if found: return "YES" return "NO" def main(): d = input() ans = solve(d) print(ans) main()
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR NUMBER IF VAR VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR 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".
def checkSubString(s, sub): foundAB = False foundBA = False found = False i = 0 while i < len(s) - 1: if not found: if s[i] == sub[0] and s[i + 1] == sub[1]: found = True if i + 2 < len(s): i += 2 else: i += 1 elif s[i] == sub[1] and s[i + 1] == sub[0]: print("YES") return True else: i += 1 return False s = input() if not checkSubString(s, "AB"): if not checkSubString(s, "BA"): print("NO")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR 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() l1 = [] l2 = [] c1, c2 = 0, 0 n = len(s) for i in range(n - 1): if s[i : i + 2] == "AB": l1.append(i) c1 += 1 elif s[i : i + 2] == "BA": l2.append(i) c2 += 1 if c1 == 0 or c2 == 0: print("NO") elif abs(l1[c1 - 1] - l2[0]) >= 2 or abs(l1[0] - l2[c2 - 1]) >= 2: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR 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() ab_count = s.count("AB") ba_count = s.count("BA") if ab_count == 0 or ba_count == 0: print("NO") elif ab_count == 1: s = s.replace("AB", "--") print("YES" if "BA" in s else "NO") elif ba_count == 1: s = s.replace("BA", "--") print("YES" if "AB" in s else "NO") else: print("YES")
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 ASSIGN VAR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING VAR STRING STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING VAR 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() succ = False x = s.find("AB") if x != -1: z = s[:x].find("BA") y = s[x + 2 :].find("BA") if z != -1 or y != -1: succ = True x = s.find("BA") if x != -1: z = s[:x].find("AB") y = s[x + 2 :].find("AB") if z != -1 or y != -1: succ = True print(["NO", "YES"][succ])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING 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() cnt_a = 0 cnt_b = 0 cnt_c = 0 cnt_d = 0 a = "AB" b = "BA" c = "ABA" d = "BAB" cnt_a = s.count(a) cnt_b = s.count(b) cnt_c = s.count(c) cnt_d = s.count(d) if cnt_a != 0 and cnt_b != 0: if cnt_a + cnt_b - (cnt_c + cnt_d) > 1: print("YES") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP 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".
k = input() j = k j = j.replace("AB", "*", 1) j = j.replace("BA", "^", 1) if "*" in j and "^" in j: print("YES") exit(0) j = k j = j.replace("BA", "*", 1) j = j.replace("AB", "^", 1) if "*" in j and "^" in j: print("YES") exit(0) print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR STRING VAR 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".
s = input().strip() n = len(s) def has(): for i in range(n - 1): if s[i : i + 2] == "AB": for j in range(i + 2, n - 1): if s[j : j + 2] == "BA": return True break for i in range(n - 1): if s[i : i + 2] == "BA": for j in range(i + 2, n - 1): if s[j : j + 2] == "AB": return True break return False print("YES" if has() else "NO")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL 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() abc = [0, 0, 0] n = len(s) i = 0 while i < n: ch = s[i] if ch == "A": if i < n - 1 and s[i + 1] == "B": if i < n - 2 and s[i + 2] == "A": abc[2] += 1 i += 3 else: abc[0] = 1 i += 2 else: i += 1 elif ch == "B": if i < n - 1 and s[i + 1] == "A": if i < n - 2 and s[i + 2] == "B": abc[2] += 1 i += 3 else: abc[1] = 1 i += 2 else: i += 1 else: i += 1 if abc[0] == 1 and abc[1] == 1: print("YES") elif abc[2] != 0 and max(abc[0], abc[1]) != 0: print("YES") elif abc[0] == 0 and abc[1] == 0 and abc[2] >= 2: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER 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".
st = input() ab1 = st.find("AB") ba1 = st.find("BA") ab2 = st.rfind("AB") ba2 = st.rfind("BA") if ab1 == -1 or ba1 == -1: print("NO") elif ab1 == ab2 and ba1 == ba2 and abs(ba1 - ab1) < 2: print("NO") elif ab1 + 2 == ab2 and ba1 == ba2: print("NO") elif ba1 + 2 == ba2 and ab1 == ab2: print("NO") else: print("YES")
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 IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER 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".
s = input() a = [] b = [] if "AB" in s and "BA" in s: for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": a.append(i) if s[i] == "B" and s[i + 1] == "A": b.append(i) if abs(min(a) - max(b)) <= 1 and abs(min(b) - max(a)) <= 1: print("NO") else: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF STRING VAR STRING VAR 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 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" not in s or "BA" not in s: print("NO") else: ab = s.index("AB") bar = s.rindex("BA") abr = s.rindex("AB") ba = s.index("BA") if bar - ab >= 2 or abr - ba >= 2: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR 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 BIN_OP VAR VAR NUMBER 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() t = False if ( s.find("AB") >= 0 and s.replace("AB", "Z", 1).find("BA") >= 0 or s.find("BA") >= 0 and s.replace("BA", "Z", 1).find("AB") >= 0 ): t = True print("YES" if t else "NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER STRING 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".
s = input() n = len(s) l = [[0, 0] for i in range(n + 1)] flag = 0 for i in range(len(s) - 1): l[i + 2][0] = l[i + 1][0] l[i + 2][1] = l[i + 1][1] if s[i : i + 2] == "AB": l[i + 2][0] = l[i + 2][0] + 1 if l[i][1] >= 1: flag = 1 break elif s[i : i + 2] == "BA": l[i + 2][1] = l[i + 2][1] + 1 if l[i][0] >= 1: flag = 1 break print("YES" if flag == 1 else "NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR 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 = input() x = 1 while x < len(s): if s[x - 1] == "A" and s[x] == "B": if "BA" in s[x + 1 :]: print("YES") break elif s[x - 1] == "B" and s[x] == "A": if "AB" in s[x + 1 :]: print("YES") break x += 1 else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING 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() n = len(s) abmishe = False bamishe = False abmisherev = False bamisherev = False cnt = 0 while cnt < n - 1: if not abmishe and s[cnt : cnt + 2] == "AB": abmishe = True cnt += 1 elif not bamishe and s[cnt : cnt + 2] == "BA": bamishe = True cnt += 1 cnt += 1 cnt2 = n - 1 while cnt2 > 0: if not bamisherev and s[cnt2 - 1 : cnt2 + 1] == "BA": bamisherev = True cnt2 -= 1 elif not abmisherev and s[cnt2 - 1 : cnt2 + 1] == "AB": abmisherev = True cnt2 -= 1 cnt2 -= 1 if abmishe and bamishe or abmisherev and bamisherev: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR 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".
string = input() ab_indexes = [] ba_indexes = [] for k in range(len(string) - 1): part = string[k] + string[k + 1] if part == "AB": ab_indexes.append(k) if part == "BA": ba_indexes.append(k) def exists(): for k in ab_indexes: for i in ba_indexes: if abs(i - k) > 1: return True return False if exists(): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF 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 main(): s = input() a = s.find("AB") b = s.find("BA") if a == -1 or b == -1: print("NO") return if s[a + 2 :].find("BA") != -1 or s[b + 2 :].find("AB") != -1: print("YES") return print("NO") return main()
FUNC_DEF 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 RETURN IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN 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().rstrip() n = int(len(s)) if n <= 3: print("NO") else: d = [0] * n for i in range(n - 1): if s[i] == "A" and s[i + 1] == "B": d[i] = 1 ans = "NO" for i in range(1, n): d[i] += d[i - 1] for i in range(n - 1): if s[i] == "B" and s[i + 1] == "A": if i - 2 >= 0: if d[i - 2] >= 1 or d[-1] - d[i + 1] >= 1: ans = "YES" break elif i + 2 < n: if d[-1] - d[i + 1] >= 1: ans = "YES" break print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR 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 STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR BIN_OP 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".
s = input() a, b = list(), list() for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": a.append(i) if s[i] == "B" and s[i + 1] == "A": b.append(i) if len(a) == 0 or len(b) == 0: print("NO") else: f = 0 for i in a: for j in b: if i - 1 != j and i + 1 != j: f = 1 break if f == 1: break if f == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF 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".
def main(): a = input() c = 0 d = 0 for i in range(1, len(a)): if a[i] == "A" and a[i - 1] == "B": d = 1 if i == len(a) - 1: break elif a[i + 1] != "B": break elif a[i] == "B" and a[i - 1] == "A": c = 1 if i == len(a) - 1: break if a[i + 1] != "A": break if c == 1 and d == 1: break if c == 1 and i < len(a) - 2: for j in range(i + 2, len(a)): if a[j] == "A" and a[j - 1] == "B": c = 2 break if d == 1 and i < len(a) - 2: for j in range(i + 2, len(a)): if a[j] == "B" and a[j - 1] == "A": d = 2 break if c == 2 or d == 2: print("YES") else: print("NO") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER 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".
import sys input = sys.stdin.readline s = input() ab = False ba = False for i in range(len(s) - 1): cur = s[i] + s[i + 1] if cur == "AB" and ab is False: ab = True for j in range(i + 2, len(s) - 1): if s[j] + s[j + 1] == "BA": print("YES") exit() elif cur == "BA" and ba is False: ba = True for j in range(i + 2, len(s) - 1): if s[j] + s[j + 1] == "AB": print("YES") exit() print("NO")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR 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".
def f(inp, ab, ba): i = inp.find(ab) return i != -1 and inp.find(ba, i + 2) != -1 inp = input() if f(inp, "AB", "BA") or f(inp, "BA", "AB"): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR 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
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 = y = input() s1, s2 = x.count("AB"), x.count("BA") x = x.replace("AB", "11").replace("BA", "11") y = y.replace("BA", "11").replace("AB", "11") if s1 > 0 and s2 > 0 and x.count("1") >= 4 and y.count("1") >= 4: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING IF VAR NUMBER 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".
a = input() f = False for i in range(len(a) - 1): if a[i] + a[i + 1] == "AB": if a[i + 2 :].rfind("BA") != -1: f = True if a[i] + a[i + 1] == "BA": if a[i + 2 :].rfind("AB") != -1: f = True if f: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL 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 IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING 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() L = len(s) AB = 0 BA = 0 ABA = 0 BAB = 0 i = 0 while i < L - 1: if s[i] == "A": if s[i + 1] == "B": if i + 2 < L and s[i + 2] == "A": ABA += 1 i += 3 else: AB += 1 i += 2 else: i += 1 elif s[i] == "B": if s[i + 1] == "A": if i + 2 < L and s[i + 2] == "B": BAB += 1 i += 3 else: BA += 1 i += 2 else: i += 1 else: i += 1 if AB >= 1 and BA >= 1: print("YES") elif ABA > 0 and BA > 0: print("YES") elif ABA > 0 and AB > 0: print("YES") elif ABA > 0 and BAB > 0: print("YES") elif BAB > 0 and BA > 0: print("YES") elif BAB > 0 and AB > 0: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER 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 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 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"): tmp = s.replace("AB", " ", 1) if tmp.count("BA"): print("YES") elif s.count("BA"): tmp = s.replace("BA", " ", 1) if tmp.count("AB"): print("YES") else: print("NO") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF FUNC_CALL VAR STRING 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() a = 0 b = 0 c = 0 d = 0 j = 0 A = [] a2 = 0 b2 = 0 for i in s: A.append(i) while j < len(A) - 1: if A[j] == "A" and A[j + 1] == "B" and c != 1: c = 1 a = j j = j + 1 elif A[j] == "B" and A[j + 1] == "A" and d != 1: d = 1 b = j j = j + 1 elif A[j] == "A" and A[j + 1] == "B" and c == 1: a2 = j elif A[j] == "B" and A[j + 1] == "A" and d == 1: b2 = j j = j + 1 if c == 1 and d == 1: print("YES") elif c == 0 and d == 0: print("NO") elif c == 1 and d == 0 and a2 != 0: x = 0 while x < a2 - 1: if A[x] == "B" and A[x + 1] == "A": d = 1 break x = x + 1 if c == 1 and d == 1: print("YES") else: print("NO") elif c == 0 and d == 1 and b2 != 0: y = 0 while y < b2 - 1: if A[y] == "A" and A[y + 1] == "B": c = 1 break y = y + 1 if c == 1 and d == 1: print("YES") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP 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 VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR 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 = 0 b = 0 AB = [] BA = [] flag = True for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": AB.append([i, i + 1]) elif s[i] == "B" and s[i + 1] == "A": BA.append([i, i + 1]) for i in AB: for j in BA: flag = True if i[1] != j[0] and i[0] != j[1]: flag = False print("YES") break if not flag: break if flag: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST 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 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 ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR 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".
def isabba(s): n = len(s) i, ab, ba = 0, 0, 0 while i < n - 1: if s[i] == "A" and s[i + 1] == "B": ab = 1 i += 2 break i += 1 if ab == 0: return False while i < n - 1: if s[i] == "B" and s[i + 1] == "A": ba = 1 break i += 1 if ba: return True return False def isbaab(s): n = len(s) i, ab, ba = 0, 0, 0 while i < n - 1: if s[i] == "B" and s[i + 1] == "A": ab = 1 i += 2 break i += 1 if ab == 0: return False while i < n - 1: if s[i] == "A" and s[i + 1] == "B": ba = 1 break i += 1 if ba: return True return False s = input() if isabba(s) or isbaab(s): print("YES", end="") else: print("NO", end="")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL 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()) n = len(s) A = [] B = [] for i in range(n - 1): if s[i : i + 2] == "AB": A += [i] if s[i : i + 2] == "BA": B += [i] ok = 0 for a in A: for b in B: if abs(a - b) > 1: print("YES") ok = 1 break if ok: break if ok == 0: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR LIST VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR 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".
def printFunc(string): ab = [] ba = [] if len(string) <= 3: print("NO") else: for i in range(len(string) - 1): if string[i : i + 2] == "AB": ab.append(i) if string[i : i + 2] == "BA": ba.append(i) try: if ba[-1] - ab[0] > 1: print("YES") return if ab[-1] - ba[0] > 1: print("YES") return print("NO") except: print("NO") string = input() printFunc(string)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING 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 BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR 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".
import sys s = input() t = 0 f = len(s) - 2 i = 0 while i < f: if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "A": s = s[:i] + s[i + 3 :] t += 1 elif s[i] == "B" and s[i + 1] == "A" and s[i + 2] == "B": s = s[:i] + s[i + 3 :] t += 1 f = len(s) - 2 i += 1 if t >= 2: print("YES") sys.exit() t2 = 0 t1 = 0 for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": t2 = 1 elif s[i] == "B" and s[i + 1] == "A": t1 = 1 if t2 * t1 == 1: print("YES") elif t == 1: if t1 == 1 or t2 == 1: print("YES") else: print("NO") else: print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR 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 ASSIGN VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR 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() abx = s.replace("AB", "X", 1) bax = s.replace("BA", "X", 1) print( "YES" if len(abx) != len(s) and abx.count("BA") or len(bax) != len(s) and bax.count("AB") else "NO" )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING 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() f = False if "AB" in s: a = s.index("AB") if "BA" in s[a + 2 :]: f = True if "BA" in s: a = s.index("BA") if "AB" in s[a + 2 :]: f = True print("YES" if f else "NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR BIN_OP VAR 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 has_non_overlapping_substrings(string): index = string.find("AB") if index >= 0 and string.find("BA", index + 2) > 0: return True index = string.find("BA") if index >= 0 and string.find("AB", index + 2) > 0: return True return False def run_alg(): result = has_non_overlapping_substrings(input()) print("YES" if result else "NO") run_alg()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL 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: indAB = s.index("AB") except: indAB = len(s) try: indBA = s.index("BA") except: indBA = len(s) if "BA" in s[indAB + 2 :] or "AB" in s[indBA + 2 :]: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR BIN_OP VAR NUMBER STRING 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".
a = input() c = int(0) d = int(0) e = int(0) f = int(0) for i in range(len(a) - 1): if a[i] + a[i + 1] == "AB": c = i + 1 break for i in range(len(a) - 2, -1, -1): if a[i] + a[i + 1] == "BA": d = i + 1 break for i in range(len(a) - 2, -1, -1): if a[i] + a[i + 1] == "AB": e = i + 1 break for i in range(len(a) - 1): if a[i] + a[i + 1] == "BA": f = i + 1 break if max(abs(c - d), max(abs(c - f), max(abs(e - d), abs(e - f)))) > 1 and ( c > 0 and d > 0 ): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP 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 BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR 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".
s = input() L1 = [] L2 = [] for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": L1.append(i) elif s[i] == "B" and s[i + 1] == "A": L2.append(i) flag = True i = 0 while i < len(L1) and flag: j = 0 while j < len(L2) and flag: if abs(L2[j] - L1[i]) > 1: flag = False j = j + 1 i = i + 1 if flag == False: print("YES") else: print("NO")
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP 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() p = list(s) q = list(s) o = 0 e = 0 mark1 = 0 mark2 = 0 for i in range(len(p) - 1): if mark1 == 0: if p[i] == "A" and p[i + 1] == "B": o += 1 p[i] = 0 p[i + 1] = 0 mark1 += 1 if mark1 != 0 and mark2 == 0: if p[i] == "B" and p[i + 1] == "A": o += 1 p[i] = 0 p[i + 1] = 0 mark2 += 1 mark1 = 0 mark2 = 0 for i in range(len(q) - 1): if mark1 == 0: if q[i] == "B" and q[i + 1] == "A": e += 1 q[i] = 0 q[i + 1] = 0 mark1 += 1 if mark1 != 0 and mark2 == 0: if q[i] == "A" and q[i + 1] == "B": e += 1 q[i] = 0 q[i + 1] = 0 mark2 += 1 if e == 2 or o == 2: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER 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".
import sys s = list(sys.stdin.readline()) d = 0 e = 0 for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B" and d == 0: d = i + 2 elif s[i] == "B" and s[i + 1] == "A" and e == 0: e = i + 2 a = "".join(s[d:]) b = "".join(s[e:]) if d != 0 and "BA" in a: print("YES") elif e != 0 and "AB" in b: print("YES") else: print("NO")
IMPORT ASSIGN VAR FUNC_CALL 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 ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR IF VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING