# Enter your code here. Read input from STDIN. Print output to STDOUT dist = gets path = gets position = 0 valleys = 0 path.chars.each_with_index do |x, i| if i == 0 if x == 'D' valleys += 1 end else if x == 'D' if position == 0 valleys += 1 end end end x == 'D' ? position -= 1 : position += 1 end p valleys