gets l,i=0,0 a=gets.chomp.chars.map{|x| x == 'U' ? 1 : -1}.each{|x|i+= 1 if (l == 0 && x == -1); l += x} p i