public int solution(int[] A) {
        int intersectionsAmt = 0;

        int[] ranges = new int[A.length];
        for (int i = 1; i < A.length; i++)
            ranges[i] = i - A[i];

        for (int i = 0; i < A.length; i++) {
            long iRangeMax = i + (long) A[i];
            for (int j = i + 1; j < A.length; j++)
                if (iRangeMax >= ranges[j])
                    ++intersectionsAmt;
        }

        return intersectionsAmt > MAX_AMT ? -1 : intersectionsAmt;
    }