a = gets.chomp.split("")
max = a.length - 2
count = 0
max.downto(0) do |i|
    0.step(i) do |j|
        if a[j] > a[j + 1]
            tmp = a[j + 1]
            a[j + 1] = a[j]
            a[j] = tmp
            count += 1
        end
    end
end
puts count