#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; string steps; cin >> n; cin >> steps; int i, valley = 0,status = 0, avail = 1; for (i = 0; i < n; i++) { if (steps[i] == 'U') { status++; if (status == 0) avail = 1; } else { status--; if(status < 0 && avail) { valley++; avail = 0; } } } cout << valley << endl; return 0; }