During today's meeting of the Council of Rainban, your advisors warned you about the growing traffic problems in your fair country. It seems that the Daring Ostrich Society has shut down the Rainban Access Motorway due to the annual migration of ostriches across the highway. This is rather unfortunate, as many cars are now trapped on the highway. Construction crews have begun to build an emergency exit so that the trapped cars can exit, but there will be chaos without rules on when cars can exit. To promote friendly driving, you decide to enforce the following rules:
As an example, suppose that there are five cars in the highway, as pictured below (with the front of the lane located on the left):
- A car may not exit if there is a car in front of it in its lane.
- A car may not exit if a car in a lower numbered lane is about to exit.
- Once a car has reached the front of its lane, it must (if possible) yield exactly once to a car from a higher numbered lane. This means that the car will allow a car from a higher numbered lane to exit (if one exists).
- If a car has fulfilled all of the above requirements, it may exit the highway. The next car in that lane (if there is one) then moves to the front of the lane.
0 A B
1 C D
Car A has not yet yielded, so it must yield. The same happens for car C. Car E cannot yield (as there are no cars in higher lanes), and so it exits. Now car A fulfills the exiting rules (having yielded to car E), and it can exit. Car B moves up to the front, but has not yet yielded, and thus must yield to car C. Car B then can exit, followed by car D.
You will be given currentLanes. The i-th element of currentLanes corresponds to the cars currently located in lane i. The 0-th character in each element corresponds to the car at the front of the lane. No car in currentLanes has yielded yet. The car represented by the character 'D' is a diplomat from a far-off country. You want to know how many cars exit in front of this diplomat (so that you know whether you have time to take a bath before his arrival), and return this number.