n = gets.chomp.to_i a = gets.chomp.split(" ").map(&:to_i) tmp = [] 0.upto(n-2) do |j| if a[j] < a[j+1] if tmp == [] tmp << j tmp << j + 1 elsif a[j-1] < a[j] tmp << j + 1 elsif a[j-1] > a[j] if tmp[-1] == j-1 tmp << j + 1 elsif tmp[-1] == j tmp << j + 1 else tmp << j tmp << j + 1 end end else if tmp == [] tmp << j elsif a[j-1] < a[j] if tmp[-1] == j - 1 tmp << j + 1 elsif tmp[-1] != j tmp << j end elsif a[j-1] > a[j] if tmp[-1] == j - 1 tmp << j + 1 elsif tmp[-1] != j tmp << j end end end end puts tmp.count # arr = [] # tmp.each do |k| # arr << a[k] # end # p arr