S=gets.chomp def swapit(str) (str.length-1).times do |i| next if (str.length-1) == i if str[i] == 'B' && str[i+1] == 'A' str[i] = 'A' str[i+1] = 'B' return str end end return nil end t = 0 while true s1 = swapit(S) if s1 t = t + 1 else break end end puts t