#include using namespace std; int main() { int n; cin >> n; bool inMountain = true; int altitude = 0, numValleys = 0; char x; for (int i = 0; i < n; i++) { cin >> x; altitude += x == 'U' ? 1 : -1; if (!altitude) { cerr << "finished valley/mountain: " << (!inMountain ? 1 : 0) << endl; numValleys += inMountain ? 0 : 1; } else if (altitude == -1 || altitude == 1) inMountain = altitude == 1; } cout << numValleys << endl; }