let inpt = readLine()!.map{ $0 } var aCount = [0] var bCount = [0] if inpt.first! == "A" { aCount[0] = 1 } else { bCount[0] = 1 } for i in(1.. i { let len = j - i + 1 if(len <= ans) { break } var aCnt = aCount[j] var bCnt = bCount[j] if(i>0) { aCnt -= aCount[i-1] bCnt -= bCount[i-1] } if aCnt == bCnt { ans = max(ans, len) break } var sub = abs(aCnt - bCnt) j -= len - sub } } print(ans)