Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in range(len(s)):
	c += s[j].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[k][-1] == "A":
        a += 1
for l in range(len(s)):
	if s[l][0] == "B":
        b += 1
print(c+min(a,b))


Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in range(len(s)):
	c += s[j].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[k][-1] == "A":
        a += 1
for l in range(len(s)):
	if s[l][0] == "B":
        b += 1
print(c+min(a,b))


Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in range(len(s)):
	c += s[i].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[i][-1] == "A":
        a += 1
for l in range(len(s)):
	if s[i][0] == "B":
        b += 1
print(c+min(a,b))


Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in range(len(s)):
	c += s[i].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[i][-1] == "A":
        a += 1
for l in range(len(s)):
	if s[i][0] == "B":
        b += 1
print(c+Math.min(a,b))


Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in len(s):
	c += s[i].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[i][-1] == "A":
    	a += 1
for l in range(len(s)):
	if s[i][0] == "B":
    	b += 1
print(c+Math.min(a,b))


Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in len(s):
	c += s[i].count("AB")
a = 0
b = 0
for k in len(s):
	if s[i][-1] == "A":
    	a += 1
for l in len(s):
	if s[i][0] == "B":
    	b += 1
print(c+Math.min(a,b))

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
l = list(itertools.combinations(s,len(s))
m = []
for j in range(N):
	new_s = "".join(s[i])
    num = new_s.count("AB")
    m.append(num)
print(max(m))

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
	s.append(input())
l = list(itertools.combinations(s,len(s))
m = []
for j in range(N):
	new_s = "".join(s[i])
    num = new_s.count("AB")
    m.append(num)
print(max(m))

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)