#include #include #include #include #include using namespace std; int main() { int n; cin >> n; int h = 0; // height int v = 0; // number of valleys string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 'D') { h -= 1; } else if (s[i] == 'U') { h += 1; if (h == 0) { v++; } } } cout << v; return 0; }