# Enter your code here. Read input from STDIN. Print output to STDOUT class Trail attr_accessor :valleys, :mountains def initialize @path = :sea_level @level = 0 @valleys = 0 @mountains = 0 @steps_taken = 0 end def hike @path = :upwards end def descend @path = :downwards end def walk(steps) steps.each do |step| case step when 'D' @level -= 1 @mountains += 1 if @level == 0 when 'U' @level += 1 @valleys += 1 if @level == 0 end @steps_taken += 1 end end end n_steps = gets.strip.to_i steps = gets.strip.split('') trip = Trail.new trip.walk(steps) puts trip.valleys