public static int trap(int[] A) {
		int all=0, blc=0, l=0, n=A.length, r=n-1, c=0;
		while (l<=r) {
			int h=Math.min(A[l],A[r]);
			if (h>c) {
				all+=(h-c)*(r-l+1);
				c=h;
			}
			if (A[l]<=A[r]) {
				blc+=A[l++];
			} else {
				blc+=A[r--];
			}
		}
		return all-blc;
	}