# Enter your code here. Read input from STDIN. Print output to STDOUT gets arr = gets.chomp.chars level = 0 valleys = 0 for c in arr if c == 'U' level += 1 if level == 0 valleys += 1 end else level -= 1 end end puts valleys