Scanner sc = new Scanner(System.in) int n = sc.nextInt() String s = sc.next() int countV = 0 int previousLevel = 0 int level = 0 for(char c : s.toCharArray()){ previousLevel = level if(c == ((char)'U')){ level++; } else { level--; } if(previousLevel >= 0 && level < 0){ countV++ } } println countV