ior = io.read local str = ior() local left = {} local right = {} left[0] = 0 local n = #str local cur = 0 for i = 1, n do if(str:sub(i, i) == "A") then cur = cur + 1 else cur = cur - 1 end if(left[cur] == nil) then left[cur] = i else right[cur] = i end end local max = 0 for k, v in pairs(left) do if(right[k] ~= nil) then max = math.max(right[k] - v, max) end end print(max)