#include #include #include #include int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n,countBelow = 0, countAbove = 0,countV = 0,sea = 0,sea1 = 0; scanf("%i\n",&n); char* hike = malloc(sizeof(char) * n); scanf("%s\n",hike); for (int i = 0; i < n;i++) { //printf("s%i\n",sea); if (hike[i] == 'D') { if (sea == 0) { sea -= 1; //printf("s%i\n",sea); countBelow += 1; for (int j = 1; j < (n - i);j++) { if (hike[j + i] == 'U') { countAbove += 1; sea += 1; } else if (hike[j + i] == 'D') { countBelow += 1; sea -= 1; } //printf("r%i rr%i ss%i r%i\n",countBelow,j+i,sea,countAbove); if (countAbove == countBelow ) { countV += 1; countAbove = 0; countBelow = 0; i = j+i; break; } } countAbove = 0; countBelow = 0; } else { sea -= 1; } } else { sea += 1; } } printf("%i",countV); return 0; }