#include #include #include #include int main() { int n; scanf("%d\n", &n); char newStep; int numOfValleys = 0; int prevLevel = 0, nextLevel = 0; for (int i = 1; i <= n; i++) { scanf("%c", &newStep); switch (newStep) { case 'U': nextLevel++; break; case 'D': nextLevel--; break; } if (prevLevel == 0 && nextLevel < 0){ numOfValleys++; } prevLevel = nextLevel; } printf("%d", numOfValleys); /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; }