// https://www.hackerrank.com/contests/rookierank/challenges/counting-valleys #include int main() { int n, valley=0, pos=0; char c; bool flag=false; scanf("%d", &n); getchar(); while(n--) { scanf("%c", &c); if(c=='D') { if(pos==0) flag=true; pos--; if(flag) { valley++; flag=false; } } else if(c=='U') pos++; } printf("%d\n", valley); return 0; }