public static int findMaxEntirelyInLeftRight(int[] A, int left, int right) {
        int tempsum = 0;
        int max = Integer.MIN_VALUE;
        for (int i = left; i <= right; ++i) {
            tempsum += A[i];
            if (tempsum > max) max = tempsum;
            if (tempsum < 0) {
                tempsum = 0;
            }
        }
        return max;
    }