#include #include #include #include #include using namespace std; int main() { int elevation = 0; int valleys = 0; int n; std::cin >> n; char step; while (n--) { std::cin >> step; int old_elevation = elevation; elevation += (step == 'U' ? 1 : -1); if (elevation == -1 && old_elevation == 0) { ++valleys; } } std::cout << valleys << std::endl; return 0; }