#include #include #include #include int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n,valleys=0,mountains=0,position=0; scanf("%d",&n); char steps[n]; scanf("%s",steps); for(int i = 0; i < n; i++){ if(steps[i] == 'U'){ position++; if(position == 0){ valleys++; } } else if(steps[i] == 'D'){ position--; if(position == 0){ mountains++; } } //printf("%d\n", position); } printf("%d", valleys); return 0; }