import java.util.ArrayList; import java.util.Objects; import java.util.Scanner; class Direction { ArrayList Direction = new ArrayList<>(); String nowDirection; public Direction(String nowDir) { this.nowDirection = nowDir; Direction.add("E"); Direction.add("W"); Direction.add("S"); Direction.add("N"); } String getNow() { return nowDirection; } String getNext() { return Direction.get(Direction.indexOf(nowDirection)+1%4); } void goNext() { this.nowDirection = Direction.get((Direction.indexOf(nowDirection)+1)%4); } } public class Rotating_Golem_1806 { public static void log(Object obj) { System.out.println(obj.toString()); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); String b = sc.next(); Direction dir = new Direction(a); int cnt = 0; while(!b.equals(dir.getNow())) { dir.goNext(); cnt+=1; } log(cnt); } }