@@ -0,0 +1,723 @@
+import java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class Solution %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Scanner sc = new Scanner(System.in);%0A        int N = sc.nextInt();%0A        int counter=0;%0A        int counterNow = 0;%0A        int counterPrev = 0;%0A        int result=0;%0A        String str = sc.next();%0A        for(int i=0;i%3CN;i++)%7B%0A            char c = str.charAt(i);%0A            counterPrev=counterNow;%0A            if(c=='U') counter++;%0A            else counter--;%0A            counterNow=counter;%0A            if(counterPrev==-1 && counterNow==0)%7B%0A                result++;%0A            %7D%0A        %7D%0A        System.out.println(result);%0A    %7D%0A%7D

add CountingValleys.java