h=Hash[["E","S","W","N"].zip([0,1,2,3])] a=h[gets.chomp] b=h[gets.chomp] if a<=b then puts b-a else puts 4-a+b end