var n: Int = Int(readLine()!)! var inputs: String = readLine()! var currentPos:Int = 0 var numValleys:Int = 0 var enteringValley:Bool = false for direction in inputs.characters { var deltaPos: Int = (String(direction) == "U" ? +1 : -1) if currentPos == 0 && deltaPos == -1 { enteringValley = true } else if enteringValley == true && (currentPos == -1 && deltaPos == 1) { enteringValley = false numValleys += 1 } currentPos += deltaPos } print(numValleys)