LearnPy Hub
← Lists problems
Hard

Trapped Rain Water

Read bar heights. After rain, water collects between taller bars: above each bar the water level is the smaller of the tallest bar to its left and the tallest to its right. Print the total units of water trapped.

Input

Integers ≥ 0 separated by spaces.

Output

One integer.

Sample 1

Input
0 1 0 2 1 0 1 3 2 1 2 1
Output
6

Sample 2

Input
4 2 0 3 2 5
Output
9
solution.py
Output appears here
Trapped Rain Water · Python practice problem · LearnPy Hub