#P10477. Subway Tour
Subway Tour
Subway Tour
In many major cities, the subway system is designed as a tree, meaning that between any two stations, there is exactly one unique path. Moreover, many of these cities have a unique central station. As a tourist, you decide to explore the subway system by starting at the central station. You randomly choose a subway line and board the car. At each station, you choose one of the subway lines you haven't yet traveled on. If there are no new lines to take from your current station, you backtrack along the subway line by which you arrived. Eventually, you travel along every subway line twice (once in each direction) and return to the central station.
After your trip you only remember whether you moved further away from the central station (recorded as a 0) or back towards it (recorded as a 1) at each step. Thus, your journey can be encoded as a binary string. Given this binary string, your task is to determine the total number of stations in the subway system.
Hint: If the binary string contains k zeros, then there are exactly k+1 stations since each zero represents moving to a new station (except the initial central station).
inputFormat
The input consists of a single line containing a binary string composed of characters '0' and '1'. It is guaranteed that the string represents a valid tour of the subway system as described.
outputFormat
Output a single integer representing the total number of stations in the subway system.
sample
01
2