let numberOfValues = Int(readLine()!)! let values = readLine()!.characters.map { String($0) } var currentElevation = 0 var valleyCount = 0 for i in (0...numberOfValues-1) { let currentStep = values[i] if (currentStep == "U") { currentElevation += 1 } else { currentElevation -= 1 } if (currentElevation == -1 && currentStep == "D") { valleyCount += 1 } } print(valleyCount)