def ascan; gets.split.map(&:to_i);end str = gets.chomp n = str.size r = 0 while str.chars.sort != str.chars 1.upto(n-1){|i| if str[i-1]>str[i] r += 1 str[i-1],str[i] = str[i],str[i-1] end } end p r