```
class Solution:
# @param A, a list of integers
# @return an integer
def trap(self, A):
water=0
for i in range(1,len(A)-2):
leftmax,rightmax=0,0
for p in A[:i]:
if p>leftmax:
leftmax=p
for q in A[i:]:
if q>rightmax:
rightmax=q
if leftmax>A[i] and rightmax>A[i]:
water=water+min(leftmax,rightmax)-A[i]
return water
```