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()
def isPresent(s, t):
k = s.find(t)
if k == -1:
return False
if s[:k].find(t[::-1]) == -1 and s[k + 2 :].find(t[::-1]) == -1:
return False
return True
if isPresent(s, "AB") or isPresent(s, "BA"):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR STRING FUNC_CALL VAR 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()
s_len = len(s)
result = "NO"
ab = None
ba = None
ab2 = None
ba2 = None
for i in range(s_len - 1):
if s[i] == "A" and s[i + 1] == "B" and ab is None:
ab = i + i + 1
if s[i] == "B" and s[i + 1] == "A":
ba = i + i + 1
if ab and abs(ab - ba) >= 4:
result = "YES"
break
if s[i] == "B" and s[i + 1] == "A" and ba2 is None:
ba2 = i + i + 1
if s[i] == "A" and s[i + 1] == "B":
ab2 = i + i + 1
if ba2 and abs(ab2 - ba2) >= 4:
result = "YES"
break
print(result) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NONE ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NONE ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR 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()
u = s.find("AB")
v = s.find("BA")
if u + 1 and s.find("BA", u + 2) != -1:
print("YES")
elif v + 1 and s.find("AB", v + 2) != -1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR STRING 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". | from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):
s = input()
n = len(s)
if s.count("A") <= 1 or s.count("B") <= 1:
print("NO")
continue
aba = bab = ab = ba = 0
p = 0
while p < n:
if p + 2 < n and s[p : p + 3] == "ABA":
aba += 1
p += 3
if p + 2 < n and s[p : p + 3] == "BAB":
bab += 1
p += 3
elif p + 1 < n and s[p : p + 2] == "AB":
ab += 1
p += 2
elif p + 1 < n and s[p : p + 2] == "BA":
ba += 1
p += 2
else:
p += 1
z = 0
for v in [ab, ba, aba, bab]:
if v == 0:
z += 1
print("YES" if z < 3 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR LIST VAR VAR VAR VAR IF VAR NUMBER 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". | prevc = ""
firstab = firstba = i = 0
for c in input():
i += 1
if prevc == "A" and c == "B":
if firstab == 0:
firstab = i
if firstba and i - firstba > 1:
print("YES")
exit()
elif prevc == "B" and c == "A":
if firstba == 0:
firstba = i
if firstab and i - firstab > 1:
print("YES")
exit()
prevc = c
print("NO") | ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING IF VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR STRING VAR STRING IF VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN 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 = str(input())
ab_ba = 0
ba_ab = 0
i = 0
n = len(s)
while i < n - 1:
if s[i] + s[i + 1] == "AB":
if ab_ba == 0:
ab_ba = 1
i += 2
continue
if s[i] + s[i + 1] == "BA":
if ab_ba == 1:
ab_ba = 2
i += 2
continue
i += 1
i = 0
while i < n - 1:
if s[i] + s[i + 1] == "BA":
if ba_ab == 0:
ba_ab = 1
i += 2
continue
if s[i] + s[i + 1] == "AB":
if ba_ab == 1:
ba_ab = 2
i += 2
continue
i += 1
if ab_ba == 2 or ba_ab == 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR 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". | S = input()
k1 = 0
k2 = 0
n = len(S)
c = 0
p = 0
for i in range(n - 2):
if S[i] == "A" and S[i + 1] == "B" and S[i + 2] != "A":
k1 = 1
p = i + 2
break
if S[i] == "B" and S[i + 1] == "A" and S[i + 2] != "B":
k2 = 1
p = i + 2
break
if S[i] == "B" and S[i + 1] == "A" and S[i + 2] == "B":
k1 = 1
k2 = 1
p = i + 3
c = 1
break
if S[i] == "A" and S[i + 1] == "B" and S[i + 2] == "A":
k1 = 1
k2 = 1
p = i + 3
c = 1
break
for i in range(p, n - 2):
if S[i] == "A" and S[i + 1] == "B" and S[i + 2] != "A":
k1 = k1 + 1
if S[i] == "B" and S[i + 1] == "A" and S[i + 2] != "B":
k2 = 1 + 1
if S[i] == "B" and S[i + 1] == "A" and S[i + 2] == "B":
k1 = k1 + 1
k2 = k2 + 1
if S[i] == "A" and S[i + 1] == "B" and S[i + 2] == "A":
k1 = k1 + 1
k2 = k2 + 1
if n >= 3 and p < n - 1:
if S[n - 2] == "A" and S[n - 1] == "B" and S[n - 3] != "B":
k1 = k1 + 1
if S[n - 2] == "B" and S[n - 1] == "A" and S[n - 3] != "A":
k2 = k2 + 1
if S[n - 2] == "A" and S[n - 1] == "B" and S[n - 3] == "B":
k1 = k1 + 1
k2 = k2 + 1
c = 1
if S[n - 2] == "B" and S[n - 1] == "A" and S[n - 3] == "A":
k1 = k1 + 1
k2 = k2 + 1
c = 1
if k1 >= 1 and k2 >= 2 and c == 1 or k1 >= 2 and k2 >= 1 and c == 1:
print("YES")
if c == 0 and k1 >= 1 and k2 >= 1:
print("YES")
if c == 0 and k1 < 1 or k2 < 1 and c == 0:
print("NO")
if c == 1 and k1 <= 1 and k2 < 2 or k2 <= 1 and c == 1 and k1 < 2:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING |
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 stdout
def main():
from sys import stdout
s = input() + "X"
pure_AB = 0
pure_BA = 0
mixed = 0
i = 0
while i < len(s) - 1:
substring = s[i - 1] + s[i]
if substring == "AB":
if s[i + 1] == "A":
mixed += 1
i += 3
else:
pure_AB += 1
i += 2
elif substring == "BA":
if s[i + 1] == "B":
mixed += 1
i += 3
else:
pure_BA += 1
i += 2
else:
i += 1
if pure_AB > 0 and pure_BA > 0:
stdout.write("YES")
elif mixed > 0 and (pure_AB > 0 or pure_BA > 0):
stdout.write("YES")
elif mixed >= 2:
stdout.write("YES")
else:
stdout.write("NO")
main() | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING IF VAR BIN_OP VAR NUMBER STRING 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 VAR NUMBER EXPR FUNC_CALL VAR STRING IF 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()
flag1 = False
flag2 = False
s2 = ""
i = 0
while i < len(s):
if i + 1 < len(s) and s[i] == "A" and s[i + 1] == "B" and flag1 == False:
flag1 = True
i += 1
s2 = s2 + ".."
else:
s2 = s2 + s[i]
i += 1
if flag1:
if "BA" in s2:
flag2 = True
if flag1 and flag2:
print("YES")
else:
i = 0
s2 = ""
flag1 = False
flag2 = False
while i < len(s):
if i + 1 < len(s) and s[i] == "B" and s[i + 1] == "A" and flag1 == False:
flag1 = True
i += 1
s2 = s2 + ".."
else:
s2 = s2 + s[i]
i += 1
if flag1:
if "AB" in s2:
flag2 = True
if flag1 and flag2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR IF STRING VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR IF STRING VAR 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". | def fun(s):
x = s.find("AB")
y = s.find("BA")
if x == -1 or y == -1:
return "NO"
if x > 1 and s[0 : x - 1].find("BA") != -1 or s[x + 2 :].find("BA") != -1:
return "YES"
if y > 1 and s[0 : y - 1].find("AB") != -1 or s[y + 2 :].find("AB") != -1:
return "YES"
return "NO"
s = input()
print(fun(s)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER RETURN STRING IF VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING 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()
n = len(s)
a = s.find("AB")
b = s.find("BA")
c = s.rfind("AB")
d = s.rfind("BA")
if a == -1 or b == -1:
print("NO")
elif abs(a - b) >= 2 or abs(a - d) >= 2 or abs(b - c) >= 2 or abs(c - d) >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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):
if "AB" not in s or "BA" not in s:
return "NO"
x = s.replace("AB", "X", 1)
if "BA" in x:
return "YES"
y = s.replace("BA", "X", 1)
if "AB" in y:
return "YES"
return "NO"
s = input()
print(substrings(s)) | FUNC_DEF IF STRING VAR STRING VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR 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". | i = input()
t = 0
for j in range(len(i) - 1):
if i[j] + i[j + 1] == "AB":
if j + 2 < len(i):
if "BA" in i[j + 2 :]:
print("YES")
t = 1
break
if t == 0:
for j in range(len(i) - 1):
if i[j] + i[j + 1] == "BA":
if j + 2 < len(i):
if "AB" in i[j + 2 :]:
t = 1
print("YES")
break
if t == 0:
print("NO") | 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF STRING VAR BIN_OP 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". | def solve(s, s1, s2):
pos = s.find(s1)
if pos == -1:
return False
pos = s.find(s2, pos + 2)
if pos == -1:
return False
else:
return True
s = input()
if solve(s, "AB", "BA") or solve(s, "BA", "AB"):
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN 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". | s = input()
iab = -1
iba = -1
for i in range(len(s) - 1):
if s[i : i + 2] == "AB":
if iab == -1:
iab = i
if iba != -1 and abs(i - iba) > 1:
print("YES")
break
elif s[i : i + 2] == "BA":
if iba == -1:
iba = i
if iab != -1 and abs(i - iab) > 1:
print("YES")
break
else:
print("NO") | 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 BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR VAR IF 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()
n = len(s)
ab, ba, anyp = False, False, 0
i = 0
while i < n:
if i + 2 < n and (s[i : i + 3] == "ABA" or s[i : i + 3] == "BAB"):
anyp += 1
i += 3
elif i + 1 < n and s[i : i + 2] == "AB":
ab = True
i += 2
elif i + 1 < n and s[i : i + 2] == "BA":
ba = True
i += 2
else:
i += 1
print("YES" if anyp > 1 or anyp > 0 and ab or anyp > 0 and ba or ab and ba else "NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR 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". | c = str(input())
n = len(c)
x = [i for i in range(n - 1) if c[i : i + 2] == "AB"]
y = [i for i in range(n - 1) if c[i : i + 2] == "BA"]
if x and y and (x[0] < y[-1] - 1 or y[0] < x[-1] - 1):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | st = input()
s1 = st.replace("AB", "0", 1)
s1 = s1.replace("BA", "1", 1)
s2 = st.replace("BA", "1", 1)
s2 = s2.replace("AB", "0", 1)
if "0" in s1 and "1" in s1 or "0" in s2 and "1" in s2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL 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 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()
yes = False
if "AB" in s:
i = s.index("AB")
n = s[:i] + " " + s[i + 2 :]
if n.count("BA") > 0:
yes = True
if "BA" in s:
i = s.index("BA")
n = s[:i] + " " + s[i + 2 :]
if n.count("AB") > 0:
yes = True
if yes:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER 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". | s = input()
yes = False
try:
ab = s.index("AB")
ba = s.rindex("BA")
if ba - ab > 1:
yes = True
ab = s.index("BA")
ba = s.rindex("AB")
if ba - ab > 1:
yes = True
except ValueError:
pass
print("YES" if yes else "NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR 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()
r1 = s.find("AB")
r2 = s.rfind("BA")
r3 = s.find("BA")
r4 = s.rfind("AB")
if r1 == -1 and r4 == -1 or r2 == -1 and r3 == -1:
print("NO")
elif abs(r4 - r3) > 1 or abs(r1 - r2) > 1:
print("YES")
else:
print("NO") | 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 EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 = []
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
ab += [i]
n = len(ab)
if n > 0:
for i in range(len(s) - 1):
if s[i] == "B" and s[i + 1] == "A":
if n == 1 and abs(ab[0] - i) == 1:
continue
elif n == 2 and abs(ab[0] - ab[1]) == 2 and i - ab[0] == 1:
continue
if i - 1 not in ab or i - 1 in ab and n > 1:
print("YES")
exit()
print("NO") | ASSIGN VAR FUNC_CALL VAR 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 VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a = []
b = []
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
a.append(i)
if s[i] == "B" and s[i + 1] == "A":
b.append(i)
if a and b and len(a) + len(b) >= 4:
print("YES")
elif a and b and len(a) + len(b) == 3:
if "ABAB" in s:
print("NO")
elif "BABA" in s:
print("NO")
else:
print("YES")
elif a and b and len(a) + len(b) == 2:
if abs(a[0] - b[0]) >= 2:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | def isValid(i):
c1 = s[i]
c2 = s[i - 1]
c3 = s[i - 2]
dp_AB[i] = dp_AB[i - 1]
dp_BA[i] = dp_BA[i - 1]
if c1 == "A":
if c2 == "B":
if c3 == "A":
if dp_AB[i - 3] or dp_BA[i - 3]:
return True
else:
dp_AB[i], dp_BA[i] = True, True
elif dp_AB[i - 2]:
return True
else:
dp_BA[i] = True
elif c1 == "B":
if c2 == "A":
if c3 == "B":
if dp_AB[i - 3] or dp_BA[i - 3]:
return True
else:
dp_AB[i], dp_BA[i] = True, True
elif dp_BA[i - 2]:
return True
else:
dp_AB[i] = True
return False
s = input()
if len(s) < 4:
print("NO")
elif len(s) == 4:
if s == "ABBA" or s == "BAAB":
print("YES")
else:
print("NO")
else:
dp_AB = [False] * len(s)
dp_BA = [False] * len(s)
for i in range(1, 4):
dp_AB[i] = "AB" in s[: i + 1]
dp_BA[i] = "BA" in s[: i + 1]
for i in range(4, len(s)):
if isValid(i):
print("YES")
break
else:
print("NO") | FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING IF VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING IF VAR STRING IF VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | def check(string):
string = string.upper()
if (
"AB" in string
and "BA" in string.replace("AB", "-", 1)
or "BA" in string
and "AB" in string.replace("BA", "-", 1)
):
return "YES"
else:
return "NO"
print(check(input())) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING FUNC_CALL VAR STRING STRING NUMBER STRING VAR STRING FUNC_CALL VAR STRING STRING NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = str(input())
n = len(s)
ab = []
ba = []
for i in range(n - 1):
if s[i : i + 2] == "AB":
ab.append(i)
if s[i : i + 2] == "BA":
ba.append(i)
if len(ab) > 0 and len(ba) > 0:
check1 = 0
check2 = 0
i = ab[0]
j = ba[0]
for x in ba:
if x > i + 1:
check1 = 1
break
for x in ab:
if x > j + 1:
check2 = 1
break
if check2 + check1 > 0:
print("YES")
else:
print("NO")
else:
print("NO") | 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 EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF 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". | string = input()
s = -1
ans = "NO"
if len(string) < 2:
print("NO")
else:
for i in range(len(string) - 1):
if string[i : i + 2] == "AB":
break
for j in range(i + 2, len(string) - 1):
if string[j : j + 2] == "BA":
ans = "YES"
for i in range(len(string) - 1):
if string[i : i + 2] == "BA":
break
for j in range(i + 2, len(string) - 1):
if string[j : j + 2] == "AB":
ans = "YES"
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING 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". | import sys
sys.setrecursionlimit(10**5)
readline = sys.stdin.readline
def process():
s = readline().strip()
a = s.find("AB")
if a != -1 and s[a + 2 :].find("BA") != -1:
print("YES")
return
a = s.find("BA")
if a != -1 and s[a + 2 :].find("AB") != -1:
print("YES")
return
print("NO")
process() | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING 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 = input()
l = len(s)
lba = []
lab = []
for i in range(l - 1):
if s[i : i + 2] == "BA":
lba.append(i)
if s[i : i + 2] == "AB":
lab.append(i)
if len(lab) == 0 or len(lba) == 0:
print("NO")
elif (
abs(lba[0] - lab[-1]) >= 2
or abs(lba[0] - lab[0]) >= 2
or abs(lba[-1] - lab[0]) >= 2
):
print("YES")
else:
print("NO") | 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 VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a1 = s.find("AB")
a2 = s.find("BA")
a3 = s[a1 + 2 :].find("BA")
a4 = s[a2 + 2 :].find("AB")
if a1 >= 0 and a3 >= 0 or a2 >= 0 and a4 >= 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING 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". | def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
def solve():
S = getStr()
AB, BA = [], []
for j in range(len(S) - 1):
tmp = S[j] + S[j + 1]
if tmp == "AB":
AB.append(j)
elif tmp == "BA":
BA.append(j)
LA, LB = len(AB), len(BA)
if min(LA, LB) == 0:
return "NO"
if LA > 1 and LB > 1:
return "YES"
if LA == 1 and LB == 1:
if abs(AB[0] - BA[0]) > 1:
return "YES"
return "NO"
if LA == 1:
ind = AB[0]
for index in BA:
if abs(index - ind) > 1:
return "YES"
if LB == 1:
ind = BA[0]
for index in AB:
if abs(index - ind) > 1:
return "YES"
return "NO"
ans = solve()
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST 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 ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN STRING RETURN STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN STRING RETURN 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". | s = input()
flag = 0
if s.find("AB") >= 0:
temp = s.find("AB")
if s.find("BA", temp + 2) >= 0:
flag = 1
if s.find("BA") >= 0:
temp = s.find("BA")
if s.find("AB", temp + 2) >= 0:
flag = 1
if flag == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER 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 = input()
i = 0
flag = 0
while i < len(s):
if s[i : i + 2] == "AB":
if "BA" in s[i + 2 :]:
print("YES")
flag = 1
break
elif s[i : i + 2] == "BA":
if "AB" in s[i + 2 :]:
print("YES")
flag = 1
break
i += 1
if flag == 0:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | __author__ = "Bian"
st = input()
ab1 = st.find("AB")
ba1 = st.find("BA", ab1 + 2)
ba2 = st.find("BA")
ab2 = st.find("AB", ba2 + 2)
if ab1 != -1 and ba1 != -1 or ab2 != -1 and ba2 != -1:
print("YES")
else:
print("NO") | ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER 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") == 0 or S.count("BA") == 0:
print("NO")
elif S[S.index("AB") + 2 :].count("BA") > 0 or S[S.index("BA") + 2 :].count("AB") > 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER STRING NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER 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 = list(input())
found1 = False
found2 = False
ABA = False
for i in range(len(s) - 2):
if (
s[i] == "A"
and s[i + 2] == "A"
and s[i + 1] == "B"
or s[i] == "B"
and s[i + 2] == "B"
and s[i + 1] == "A"
):
ABA = True
s.pop(i)
s.pop(i)
s.pop(i)
break
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
s.pop(i)
s.pop(i)
found1 = True
break
for i in range(len(s) - 1):
if found1 or ABA:
if s[i] == "B" and s[i + 1] == "A":
found2 = True
break
else:
break
if found1 and found2 or found1 and ABA or found2 and ABA:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR 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 = str(input())
ab = len(s)
ba = 0
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
ab = i
break
for i in range(len(s) - 2, -1, -1):
if s[i] == "B" and s[i + 1] == "A":
ba = i
break
if ba > ab + 1:
print("YES")
exit()
ab = 0
ba = len(s)
for i in range(len(s) - 1):
if s[i] == "B" and s[i + 1] == "A":
ba = i
break
for i in range(len(s) - 2, -1, -1):
if s[i] == "A" and s[i + 1] == "B":
ab = i
break
if ab > ba + 1:
print("YES")
exit()
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR 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 VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 VAR IF 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()
lastone = ""
a = []
b = []
conse = "a"
for i in range(len(string) - 1):
if string[i] + string[i + 1] == "AB":
a.append(i)
elif string[i] + string[i + 1] == "BA":
b.append(i)
if not a or not b:
print("NO")
elif abs(max(a) - min(b)) >= 2 or abs(max(b) - min(a)) >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 comprobar(cadena, tam):
if tam <= 3:
return "NO"
k = 0
for i in range(tam - 2):
if cadena[i] == "A" and cadena[i + 1] == "B":
k = i + 2
break
if k != 0:
for j in range(k, tam - 1):
if cadena[j] == "B" and cadena[j + 1] == "A":
return "YES"
k = 0
for i in range(tam - 2):
if cadena[i] == "B" and cadena[i + 1] == "A":
k = i + 2
break
if k != 0:
for j in range(k, tam - 1):
if cadena[j] == "A" and cadena[j + 1] == "B":
return "YES"
return "NO"
A = input()
t = len(A)
if t > 100000:
print("NO")
else:
print(comprobar(A, t)) | FUNC_DEF IF VAR NUMBER RETURN 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 IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING RETURN 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 IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | def simplify(seq):
new_seq = []
for i in range(len(seq) - 1):
if seq[i] == "A" or seq[i] == "B":
new_seq.append(seq[i])
elif seq[i + 1] == "A" or seq[i + 1] == "B":
new_seq.append(seq[i])
else:
continue
new_seq.append(seq[-1])
return "".join(new_seq)
def is_valid(seq):
if "AB" in seq and "BA" in seq:
return True
return False
def find_occurrence(seq, depth):
if depth == 2:
for i in range(len(seq)):
if seq[i : i + 2] == "BA":
return True
return False
else:
for i in range(len(seq)):
if seq[i : i + 2] == "AB":
new_seq = seq[:i] + "XX" + seq[i + 2 :]
found = find_occurrence(new_seq, 2)
if found:
return True
your_string = input()
your_string = simplify(your_string)
if is_valid(your_string):
contains_substrings = find_occurrence(your_string, 1)
if contains_substrings:
print("YES")
else:
print("NO")
else:
print("NO") | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL STRING VAR FUNC_DEF IF STRING VAR STRING VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
m = []
n = []
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
m.append(i)
if s[i] == "B" and s[i + 1] == "A":
n.append(i)
if min(len(m), len(n)) == 0:
print("NO")
elif max(len(m), len(n)) > 2:
print("YES")
elif len(m) == 2 and len(n) == 2:
print("YES")
elif len(m) == 1 and len(n) == 2:
if max(m[0] - n[0], n[0] - m[0]) > 1 or max(m[0] - n[1], n[1] - m[0]) > 1:
print("YES")
else:
print("NO")
elif len(n) == 1 and len(m) == 2:
if max(n[0] - m[0], m[0] - n[0]) > 1 or max(n[0] - m[1], -n[0] + m[1]) > 1:
print("YES")
else:
print("NO")
elif m[0] - n[0] > 1 or n[0] - m[0] > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF 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 FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER 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 FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | a = input()
def valid(s, x, y):
try:
s.index(x)
s = s.replace(x, "*", 1)
s.index(y)
s = s.replace(y, "*", 1)
return True
except:
return False
print(("NO", "YES")[valid(a, "AB", "BA") or valid(a, "BA", "AB")]) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR STRING STRING FUNC_CALL VAR VAR STRING STRING 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()
f = 0
n = len(s)
ind = n
for i in range(n - 1):
if s[i] == "A" and s[i + 1] == "B":
ind = i + 2
break
for i in range(ind, n - 1):
if s[i] == "B" and s[i + 1] == "A":
f = 1
break
ind = n
for i in range(n - 1):
if s[i] == "B" and s[i + 1] == "A":
ind = i + 2
break
for i in range(ind, n - 1):
if s[i] == "A" and s[i + 1] == "B":
f = 1
break
if f:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING 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 sol():
s = input().strip()
ab = s.find("AB")
ba = s.find("BA")
if ab < 0 or ba < 0:
return False
if abs(ba - ab) < 2:
first = min(ab, ba)
second = max(ab, ba)
toFind = "BA" if ab == first else "AB"
if s.find(toFind, first + 2) > 0:
return True
toFind = "AB" if toFind == "BA" else "BA"
if s.find(toFind, second + 2) > 0:
return True
return False
return True
def main():
if sol():
print("YES")
else:
print("NO")
main() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR STRING STRING IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR STRING STRING STRING IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
ab, ba = [], []
for i in range(len(s) - 1):
if s[i : i + 2] == "AB":
ab.append(i)
elif s[i : i + 2] == "BA":
ba.append(i)
for u in ab:
for v in ba:
if abs(u - v) > 1:
print("YES")
exit()
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
x = s.count("AB")
y = s.count("BA")
a1 = s.count("ABA")
a2 = s.count("BAB")
a3 = s.count("ABAB")
a4 = s.count("BABA")
f = 0
if a3 > 0:
if x > 2 or y > 1:
print("YES")
exit()
elif a4 > 0:
if y > 2 or x > 1:
print("YES")
exit()
elif a1 > 0 or a2 > 0:
if x > 1 or y > 1:
print("YES")
exit()
elif x > 0 and y > 0:
print("YES")
exit()
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER 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()
L = len(s)
if L > 3:
if "ABABA" in s or "BABAB" in s:
print("YES")
elif "ABA" in s:
b = s.index("ABA")
s = s[0:b] + s[b + 3 :]
if "AB" in s or "BA" in s:
print("YES")
else:
print("NO")
elif "BAB" in s:
b = s.index("BAB")
s = s[0:b] + s[b + 3 :]
if "AB" in s or "BA" in s:
print("YES")
else:
print("NO")
elif "AB" in s:
a = s.index("AB")
s = s[0:a] + s[a + 2 :]
if "BA" in s:
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF STRING VAR 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()
s2 = s
i = s.find("AB")
nfound = 1
if i != -1:
s = s[:i] + "F" + s[i + 2 :]
if s.find("BA") != -1:
print("YES")
exit()
i = s2.find("BA")
if i != -1:
s2 = s2[:i] + "f" + s2[i + 2 :]
if s2.find("AB") != -1:
print("YES")
exit()
if nfound:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL 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". | s = input()
abH, abT = s.find("AB"), s.rfind("AB")
baH, baT = s.find("BA"), s.rfind("BA")
flag = (
abH >= 0 and baT >= 0 and baT - abH > 1 or abT >= 0 and baH >= 0 and abT - baH > 1
)
print("YES" if flag else "NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR 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()
if s.find("AB") == -1 or s.find("BA") == -1:
print("NO")
exit()
def func(a, b):
idx = s.find(a)
if s[idx + 2 :].find(b) != -1:
return True
if func("AB", "BA") or func("BA", "AB"):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR STRING STRING FUNC_CALL 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". | s = input()
x = len(s)
i = 0
t = ""
l = ""
done = 0
a = -1
b = -1
while i < x - 1:
if s[i] == "A":
if s[i + 1] == "B":
if b != i:
if len(l) != 0:
if l[0] == "B" and l[1] == "A":
done = 1
break
if len(t) == 0:
t += "AB"
a = i + 1
elif s[i] == "B":
if s[i + 1] == "A":
if a != i:
if len(t) != 0:
if t[0] == "A" and t[1] == "B":
done = 1
break
if len(l) == 0:
l += "BA"
b = i + 1
i += 1
if done == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING 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 VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
first = s.find("AB")
second = s.find("BA", first + 2)
if first == -1 or second == -1:
first = s.find("BA")
second = s.find("AB", first + 2)
if first == -1 or second == -1:
print("NO")
else:
print("YES")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING 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". | k = input()
a, b, c, i = 0, 0, 0, 0
while i < len(k):
if k[i : i + 3] == "ABA" or k[i : i + 3] == "BAB":
a = a + 1
i = i + 3
elif k[i : i + 2] == "AB":
b = b + 1
i = i + 2
elif k[i : i + 2] == "BA":
c = c + 1
i = i + 2
else:
i = i + 1
if a > 1 or a > 0 and (b > 0 or c > 0) or b > 0 and c > 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | while True:
try:
s = input().strip()
if s == "":
break
idx_AB = []
idx_BA = []
for i in range(len(s)):
if s[i : i + 2] == "AB":
idx_AB.append(i)
if s[i : i + 2] == "BA":
idx_BA.append(i)
flag = False
for i in idx_AB:
for j in idx_BA:
if abs(i - j) >= 2:
flag = True
break
if flag:
print("YES")
else:
print("NO")
except:
break | WHILE NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | def solve(s):
starts_count = 0
for i in range(len(s)):
if i + 1 < len(s) and s[i] == "A" and s[i + 1] == "B":
starts_count += 1
for i in range(len(s)):
kill_count = 0
if i + 1 < len(s) and s[i] == "B" and s[i + 1] == "A":
if i - 1 >= 0 and s[i - 1] == "A":
kill_count += 1
if i + 2 < len(s) and s[i + 2] == "B":
kill_count += 1
if starts_count - kill_count > 0:
return "YES"
return "NO"
print(solve(input())) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | n = input()
if "AB" not in n or "BA" not in n:
print("NO")
elif n.count("AB") + n.count("BA") - n.count("BAB") - n.count("ABA") > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING 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 = str(input())
if "AB" in s and "BA" in s:
s1 = s.replace("AB", "__", 1)
if "BA" in s1:
ans1 = 1
else:
ans1 = 0
s2 = s.replace("BA", "__", 1)
if "AB" in s2:
ans2 = 1
else:
ans2 = 0
if ans1 == 1 or ans2 == 1:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN 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". | def f(s):
ab, ba = 0, 0
last_ab, last_ba = -1, -1
n = len(s)
for i in range(n):
if s[i] == "B" and (i > 0 and s[i - 1] == "A"):
j = i - 1
ab += 1
if ba > 1 or last_ba >= 0 and last_ba != j - 1:
return "YES"
last_ab = j
if s[i] == "B" and (i + 1 < n and s[i + 1] == "A"):
ba += 1
if ab > 1 or last_ab >= 0 and last_ab != i - 1:
return "YES"
last_ba = i
return "NO"
assert f("BAB") == "NO"
assert f("ABABAB") == "YES"
assert f("BABABA") == "YES"
assert f("ABA") == "NO"
assert f("BACFAB") == "YES"
assert f("AXBYBXA") == "NO"
assert f("ABAXXXAB") == "YES"
s = input()
ans = f(s)
print(ans) | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR VAR IF VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR VAR RETURN STRING FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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". | str = input()
pos = str.find("AB")
flag = False
if pos != -1:
if pos != 0:
mystr = str[0 : pos - 1 : 1] + str[pos + 2 : len(str) : 1]
else:
mystr = str[pos + 2 : len(str) : 1]
pos = mystr.find("BA")
if pos != -1:
flag = True
else:
flag = False
else:
flag = False
if flag:
print("YES")
else:
pos = str.find("BA")
if pos != -1:
if pos != 0:
mystr = str[0 : pos - 1 : 1] + str[pos + 2 : len(str) : 1]
else:
mystr = str[pos + 2 : len(str) : 1]
pos = mystr.find("AB")
if pos != -1:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
x, y = s, s
var = 0
if "AB" in x:
l = x.index("AB")
if "BA" in x[:l] or "BA" in x[l + 2 :]:
var = 1
if var == 1:
print("YES")
else:
if "BA" in y:
l = y.index("BA")
if "AB" in y[:l] or "AB" in y[l + 2 :]:
var = 1
if var == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR BIN_OP 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". | def ham(a, b):
if a[1] == b[0] or b[1] == a[0]:
return 0
return 1
a = input()
ab = []
ba = []
for i in range(len(a) - 1):
if a[i : i + 2] == "AB":
ab.append([i, i + 1])
if a[i : i + 2] == "BA":
ba.append([i, i + 1])
s = 0
for i in range(len(ab)):
for l in range(len(ba)):
if ham(ab[i], ba[l]):
print("YES")
s = 1
break
if s == 1:
break
if s == 0:
print("NO") | FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a1, a2 = s.find("AB"), s.rfind("AB")
b1, b2 = s.find("BA"), s.rfind("BA")
if abs(a1 - b1) < 2 and abs(a1 - b2) < 2 and abs(a2 - b1) < 2 or min(a1, b1) == -1:
print("NO")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER 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". | a = input()
if (
a.find("AB") >= 0
and a[a.find("AB") + 2 :].find("BA") >= 0
or a.find("BA") >= 0
and a[a.find("BA") + 2 :].find("AB") >= 0
):
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER 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()
x = 0
i = 0
while i < len(s) - 1:
if i < len(s) - 2 and s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "A":
x = 1
break
elif i < len(s) - 2 and s[i] == "B" and s[i + 1] == "A" and s[i + 2] == "B":
x = 1
break
elif s[i] == "A" and s[i + 1] == "B":
x = 2
break
elif s[i] == "B" and s[i + 1] == "A":
x = 3
break
i += 1
if x == 2:
i += 2
while i < len(s) - 1:
if s[i] == "B" and s[i + 1] == "A":
x = 4
break
i += 1
elif x == 3:
i += 2
while i < len(s) - 1:
if s[i] == "A" and s[i + 1] == "B":
x = 4
break
i += 1
elif x == 1:
i += 3
while i < len(s) - 1:
if s[i] == "B" and s[i + 1] == "A":
x = 4
break
elif s[i] == "A" and s[i + 1] == "B":
x = 4
break
i += 1
if x == 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 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 ASSIGN VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE 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 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". | inp = input().strip()
if len(inp) < 4:
print("NO")
elif inp.count("AB") == 1 and inp.count("BA") == 1:
if inp.count("ABA") + inp.count("BAB") >= 1:
print("NO")
else:
print("YES")
elif inp.count("AB") < 1 or inp.count("BA") < 1:
print("NO")
elif (
inp.count("AB") + inp.count("BA") == 3
and inp.count("ABAB") + inp.count("BABA") >= 1
):
print("NO")
else:
print("YES") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER BIN_OP FUNC_CALL VAR STRING 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()
x = s.find("AB")
if x == -1:
print("NO")
else:
k = s.replace("AB", "l", 1)
y = k.find("BA")
if y == -1:
x = s.find("BA")
if x == -1:
print("NO")
else:
k = s.replace("BA", "l", 1)
y = k.find("AB")
if y == -1:
print("NO")
else:
print("YES")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING 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". | a = input()
ind1 = a.find("AB")
ind2 = a.find("BA")
ind3 = a.rfind("BA")
ind4 = a.rfind("AB")
sz = min(ind1 + 2, ind3 + 2) - max(ind1, ind3)
sz2 = min(ind2 + 2, ind4 + 2) - max(ind2, ind4)
if (sz <= 0 or sz2 <= 0) and ind1 != -1 and ind2 != -1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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". | str = input()
ab1 = ab2 = ba1 = ba2 = -1
for i in range(1, len(str)):
if str[i - 1] == "A" and str[i] == "B":
if ab1 == -1:
ab1 = i
ab2 = i
if str[i - 1] == "B" and str[i] == "A":
if ba1 == -1:
ba1 = i
ba2 = i
if ab1 == -1 or ba1 == -1 or not (ba2 - ab1 >= 2 or ab2 - ba1 >= 2):
print("NO")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING IF VAR NUMBER ASSIGN 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". | s = input()
n = len(s)
flag = 0
for i in range(n - 1):
if s[i : i + 2] == "AB":
for j in range(i + 2, n - 1):
if s[j : j + 2] == "BA":
flag = 1
print("YES")
exit()
break
for i in range(n - 1):
if s[i : i + 2] == "BA":
for j in range(i + 2, n - 1):
if s[j : j + 2] == "AB":
flag = 1
print("YES")
exit()
break
print("NO") | 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 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 ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR 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 ASSIGN 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()
one = -1
two = -1
for i in range(0, len(s) - 1):
if s[i] == "A" and s[i + 1] == "B" and one == -1:
one = i
if s[i] == "B" and s[i + 1] == "A" and two == -1:
two = i
isTrue = False
for i in range(len(s) - 1, 1, -1):
if s[i - 1] == "A" and s[i] == "B" and two != -1 and i > two + 2:
isTrue = True
break
if s[i - 1] == "B" and s[i] == "A" and one != -1 and i > one + 2:
isTrue = True
break
if isTrue:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR NUMBER 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 = input()
n = len(s)
i = 0
while i < n - 3:
if s[i] == "A" and s[i + 1] == "B":
i += 2
while i < n - 1:
if s[i] == "B" and s[i + 1] == "A":
print("YES")
exit()
i += 1
i += 1
i = 0
while i < n - 3:
if s[i] == "B" and s[i + 1] == "A":
i += 2
while i < n - 1:
if s[i] == "A" and s[i + 1] == "B":
print("YES")
exit()
i += 1
i += 1
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER 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". | x = input()
y1 = x.find("AB")
y2 = x.find("BA")
flag = 0
if y1 >= 0:
y3 = x.find("BA", y1 + 2)
if y3 >= 0:
flag = 1
if flag == 0 and y2 >= 0:
y4 = x.find("AB", y2 + 2)
if y4 >= 0:
flag = 1
if flag == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF 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 = input().strip()
f = False
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
for j in range(i + 2, len(s) - 1):
if s[j] == "B" and s[j + 1] == "A":
f = True
break
for i in range(len(s) - 1):
if s[i] == "B" and s[i + 1] == "A":
for j in range(i + 2, len(s) - 1):
if s[j] == "A" and s[j + 1] == "B":
f = True
break
if f:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING 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 reverse(a):
return a[::-1]
def find_all(str, sub):
start = 0
a = []
while start < len(str):
d = str.find(sub, start)
if not d == -1:
a.append(d)
start = d + len(sub)
else:
break
if len(a) == 3:
break
return a
def find_rev(str, sub):
start = 0
a = []
str = reverse(str)
while start < len(str):
d = str.find(sub, start)
if not d == -1:
p = len(m) - d - 2
a.append(p)
start = d + len(sub)
else:
break
if len(a) == 0:
break
return a
m = input()
a = []
a = find_all(m, "AB")
b = []
b = find_all(m, "BA")
c = 0
b = reverse(b)
for x in a:
for y in b:
d = abs(x - y)
if d > 1:
c = 1
break
if c == 1:
print("YES")
else:
print("NO") | FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF 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". | fl = lambda a: s.find(a)
fr = lambda a: s.rfind(a)
f = lambda l, r: r - l > 1 and l >= 0 and r >= 0
x, y = "AB", "BA"
s = input()
print("YES" if f(fl(x), fr(y)) or f(fl(y), fr(x)) else "NO") | ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR 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". | s = input()
ans = []
gans = []
for i in range(len(s) - 1):
if s[i] == "A":
if s[i + 1] == "B":
ans.append(i)
if s[i] == "B":
if s[i + 1] == "A":
gans.append(i)
if min(len(ans), len(gans)) == 0:
print("NO")
exit()
if abs(gans[-1] - ans[0]) > 1 or abs(gans[0] - ans[-1]) > 1:
print("YES")
else:
print("NO") | 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 IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
da = {}
db = {}
for i in range(len(s) - 1):
if s[i] + s[i + 1] == "AB":
da[i] = 1
if s[i] + s[i + 1] == "BA":
db[i] = 1
if len(da) == len(db) == 1:
for x in da:
for y in db:
if abs(x - y) > 1:
print("YES")
else:
print("NO")
elif len(da) == 0 or len(db) == 0:
print("NO")
elif len(da) == 1 and len(db) == 2:
for x in da:
for y in db:
if abs(x - y) > 1:
print("YES")
break
else:
print("NO")
elif len(da) == 2 and len(db) == 1:
for x in db:
for y in da:
if abs(x - y) > 1:
print("YES")
break
else:
print("NO")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR 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 FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR 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_str(a):
temp = a
count = a.count("AB")
a = a.replace("AB", " ", 1)
count *= a.count("BA")
if count:
return "YES" if count else "NO"
else:
count = temp.count("BA")
temp = temp.replace("BA", " ", 1)
count *= temp.count("AB")
return "YES" if count else "NO"
a = input()
print(find_str(a)) | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER VAR FUNC_CALL VAR STRING IF VAR RETURN VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER VAR FUNC_CALL VAR STRING RETURN VAR STRING 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()
a = False
b = False
i = 0
while i < len(s) - 1:
if not a and s[i : i + 2] == "AB":
a = True
i += 2
elif not b and s[i : i + 2] == "BA":
b = True
i += 2
else:
i += 1
if a and b:
break
if a and b:
print("YES")
else:
i = 0
a = False
b = False
s = s[::-1]
while i < len(s) - 1:
if not a and s[i : i + 2] == "AB":
a = True
i += 2
elif not b and s[i : i + 2] == "BA":
b = True
i += 2
else:
i += 1
if a and b:
break
if a and b:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR 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 IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR 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 IF VAR VAR 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()
q = 0
t = s.find("AB")
if t != -1 and t <= len(s) - 4 and s.find("BA", t + 2) != -1:
q = 1
t = s.find("BA")
if t != -1 and t <= len(s) - 4 and s.find("AB", t + 2) != -1:
q = 1
if q == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER 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". | def find_by_ab(ab_ba, w1, w2):
a = ab_ba.find(w1)
if a != -1:
ab_ba = ab_ba[a + 2 :]
b = ab_ba.find(w2)
if b != -1:
return "YES"
else:
return "NO"
ab_ba = input()
res = find_by_ab(ab_ba, "AB", "BA")
if res == "YES":
print("YES")
else:
res = find_by_ab(ab_ba, "BA", "AB")
if res == "YES":
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING STRING IF VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING STRING IF 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()
slen = len(s)
if slen <= 3:
print("NO")
else:
abCount = s.count("AB")
baCount = s.count("BA")
flag1 = 0
flag2 = 0
if abCount > 0 and baCount > 0:
f1 = s.find("AB")
x1 = s.count("BA", f1 + 2, slen)
if x1 > 0:
flag1 = 1
f2 = s.find("BA")
x2 = s.count("AB", f2 + 2, slen)
if x2 > 0:
flag2 = 1
if flag1 == 1 or flag2 == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR IF VAR 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". | from itertools import accumulate
def bin_search(x, left, right, num_list):
if right - left <= 1:
if x <= num_list[left]:
return left + 1
else:
return right + 1
else:
middle = (left + right) // 2
if x < num_list[middle]:
return bin_search(x, left, middle, num_list)
elif x > num_list[middle]:
return bin_search(x, middle + 1, right, num_list)
else:
return middle + 1
s = input()
if s.find("AB") >= 0 and s.find("BA") >= 0:
if abs(s.find("AB") - s.rfind("BA")) >= 2 or abs(s.rfind("AB") - s.find("BA")) >= 2:
print("YES")
else:
print("NO")
else:
print("NO") | FUNC_DEF IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
k, x = s, 1
if "AB" in s:
s = s.replace("AB", " ", 1)
if "BA" in s:
x = 0
s = k
if "BA" in s:
s = s.replace("BA", " ", 1)
if "AB" in s:
x = 0
print("YNEOS"[x::2]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER IF STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
if "AB" in s and "BA" in s:
a = s.count("AB")
b = s.count("BA")
x = s.count("ABA")
y = s.count("BAB")
if a == 1 and b == 1 and x + y == 1:
print("NO")
elif a == 1 and b == 2 and s.count("BABA") == 1:
print("NO")
elif a == 2 and b == 1 and s.count("ABAB") == 1:
print("NO")
else:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
if "AB" and "BA" in s:
i = 0
splits = []
while i < len(s) - 1:
if s[i] == "A" and s[i + 1] == "B":
x = s[:i]
y = s[i + 2 :]
if "BA" in x or "BA" in y:
print("YES")
break
i += 1
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR IF STRING STRING VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF STRING VAR STRING VAR EXPR 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". | a = input()
b = a.find("AB")
c = a.find("BA")
flag = 0
if b + 1 and a.find("BA", b + 2) + 1 or c + 1 and a.find("AB", c + 2) + 1:
flag = 1
print("YES" if flag else "NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a = []
for i in s:
a.append(i)
f = 0
if "AB" in s and "BA" in s:
if "ABA" not in s and "BAB" not in s:
f = 1
else:
if "ABA" in s and "BAB" in s:
m = min(s.index("ABA"), s.index("BAB"))
s = s[:m] + s[m + 3 :]
elif "ABA" in s:
s = s[: s.index("ABA")] + s[s.index("ABA") + 3 :]
elif "BAB" in s:
s = s[: s.index("BAB")] + s[s.index("BAB") + 3 :]
if "AB" in s or "BA" in s:
f = 1
if f == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR IF STRING VAR STRING VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF STRING VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF STRING VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF STRING VAR STRING VAR 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". | x = input()
lab = 1000000000.0
rab = -1000000000.0
lba = 1000000000.0
rba = -1000000000.0
for i in range(len(x) - 1):
if x[i : i + 2] == "AB":
lab = min(lab, i)
rab = max(rab, i)
if x[i : i + 2] == "BA":
lba = min(lba, i)
rba = max(rba, i)
if lab < 1000000000.0 and lba < 1000000000.0:
if lab + 1 < rba or lba + 1 < rab:
print("YES")
else:
print("NO")
else:
print("NO") | 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 FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR 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". | s = input()
x = s.find("AB", 0, len(s))
if x == -1:
print("NO")
else:
y = s.find("BA", 0, x)
z = s.find("BA", x + 2, len(s))
if y != -1 or z != -1:
print("YES")
else:
x = s.find("BA", 0, len(s))
if x == -1:
print("NO")
else:
y = s.find("AB", 0, x)
z = s.find("AB", x + 2, len(s))
if y != -1 or z != -1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR 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().strip()
if s.find("AB") != -1:
x = s.find("AB")
t = s[x + 2 :]
if t.find("BA") != -1:
print("YES")
exit(0)
if s.find("BA") != -1:
x = s.find("BA")
t = s[x + 2 :]
if t.find("AB") != -1:
print("YES")
exit(0)
print("NO") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING 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". | a = input()
c = a[:]
k = a.find("BA")
o = 0
oz = 0
if k != -1:
a = a[k + 2 :]
k1 = a.find("AB")
if k1 != -1:
o = 1
kk = c.find("AB")
if kk != -1:
a = c[kk + 2 :]
kk1 = a.find("BA")
if kk1 != -1:
oz = 1
if o == 1 or oz == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR 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". | da_str = input()
ab = ba = concurrence = False
i = 0
while i < len(da_str) - 1:
a = da_str[i]
b = da_str[i + 1]
if a == "A" and b == "B":
if i + 2 < len(da_str) and da_str[i + 2] == "A":
if concurrence == True:
ab = True
concurrence = True
i += 3
else:
ab = True
i += 2
elif a == "B" and b == "A":
if i + 2 < len(da_str) and da_str[i + 2] == "B":
if concurrence == True:
ab = True
concurrence = True
i += 3
else:
ba = True
i += 2
else:
i += 1
if ab == True and ba == True or concurrence == True and (ab == True or ba == True):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | import sys
input = lambda: sys.stdin.readline()
int_arr = lambda: list(map(int, input().split()))
str_arr = lambda: list(map(str, input().split()))
get_str = lambda: map(str, input().split())
get_int = lambda: map(int, input().split())
get_flo = lambda: map(float, input().split())
mod = 1000000007
def solve(s):
ff = 0
if "AB" in s and "BA" in s:
ab = s.find("AB") + 2
if s[ab:].find("BA") != -1:
ff = 1
ba = s.find("BA") + 2
if s[ba:].find("AB") != -1:
ff = 1
if ff:
print("YES")
else:
print("NO")
else:
print("NO")
s = str(input())
solve(s) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL 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". | s = str(input())
temp1, temp2 = [], []
count = 0
for i in range(len(s) - 1):
if s[i] == "A" and s[i + 1] == "B":
temp1.append(i + i + 1)
count += 1
for i in range(len(s) - 1, 0, -1):
if s[i] == "A" and s[i - 1] == "B":
temp2.append(i - 1 + i)
count += 1
if temp1 and temp2:
if count >= 2:
if temp1 == temp2:
print("NO")
elif len(temp1) + len(temp2) == 3:
if sum(temp1) // 2 == sum(temp2) or sum(temp2) // 2 == sum(temp1):
print("NO")
else:
print("YES")
elif len(temp1) + len(temp2) > 3:
print("YES")
elif len(temp1) == 1 and len(temp2) == 1:
if abs(temp1[0] - temp2[0]) == 2:
print("NO")
else:
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST 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 BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP 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 IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR 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 = -1
a1 = -1
b = -1
b1 = -1
for i in range(len(s) - 1):
s1 = s[i : i + 2]
if s1 == "AB":
if a == -1:
a = i
a1 = i
elif s1 == "BA":
if b == -1:
b = i
b1 = i
if a == -1 or b == -1 or abs(b1 - a) == 1 and abs(a1 - b) == 1:
print("NO")
else:
print("YES") | 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 ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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()
crossing = 0
ab = 0
ba = 0
n = len(s)
i = 0
while i < n - 1:
if s[i : i + 2] == "AB":
if s[i + 1 : i + 3] == "BA":
crossing += 1
i += 3
else:
ab += 1
i += 1
elif s[i : i + 2] == "BA":
if s[i + 1 : i + 3] == "AB":
crossing += 1
i += 3
else:
ba += 1
i += 1
else:
i += 1
if (
ab > 0
and ba > 0
or ab > 0
and crossing > 0
or ba > 0
and crossing > 0
or crossing > 1
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
i = 0
AB, BA = 0, 0
ff = True
dd = True
over = 0
while i <= len(s) - 2:
if s[i : i + 3] == "ABA" or s[i : i + 3] == "BAB":
i += 3
over += 1
if s[i : i + 2] == "AB" and ff == True:
i += 2
AB = 1
ff = False
elif s[i : i + 2] == "BA" and dd == True:
BA = 1
i += 2
dd = False
else:
i += 1
if AB == 1 and BA == 1 or AB == 1 and over >= 1 or BA == 1 and over >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = str(input())
a = 99999
b = 99999
i = 0
while i < len(s) - 1:
if a == 99999 or b == 99999:
if s[i : i + 2] == "AB":
a = i
elif s[i : i + 2] == "BA":
b = i
elif s[i : i + 2] == "AB" and not abs(i - b) < 2:
a = i
elif s[i : i + 2] == "BA" and not abs(a - i) < 2:
b = i
if abs(a - b) >= 2 and not a == 99999 and not b == 99999:
break
i += 1
if abs(a - b) >= 2 and not a == 99999 and not b == 99999:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF 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()
if "AB" not in s or "BA" not in s:
print("NO")
exit()
ab = [i for i in range(len(s) - 1) if s[i : i + 2] == "AB"]
ba = [i for i in range(len(s) - 1) if s[i : i + 2] == "BA"]
print(("NO", "YES")[max(max(ab) - min(ba), max(ba) - min(ab)) > 1]) | ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.