func water h[] .
   n = len h[]
   len left[] n
   len right[] n
   for i = 1 to n
      max = higher max h[i]
      left[i] = max
   .
   max = 0
   for i = n downto 1
      max = higher max h[i]
      right[i] = max
   .
   for i = 1 to n
      sum += lower left[i] right[i] - h[i]
   .
   return sum
.
repeat
   s$ = input
   until s$ = ""
   print water number strsplit s$ " "
.
# 
input_data
1 5 3 7 2
5 3 7 2 6 4 5 9 1 2
2 6 3 5 2 8 1 4 2 2 5 3 5 7 4 1
5 5 5 5
5 6 7 8
8 7 7 6
6 7 10 7 6
