#include #include #include #include #include using namespace std; int main() { int n; scanf("%d\n", &n); int level = 0; bool valley = false; int res = 0; for (int i = 0; i < n; i++) { char c; scanf("%c", &c); if (c == 'U') level++; else level--; if (level < 0) valley = true; else { // level >= 0 if (valley) { res++; valley = false; } } } printf("%d\n", res); return 0; }