def count_quadruplets_ordered_4_pointers(a: list[int], k1: int, k2: int) -> int:
    """
    Counts quadruplets (i, j, k, l) with i < j < k < l 
    such that a[i] + a[j] > k1 and a[k] + a[l] > k2.
    """
    n = len(a)
    total_quadruplets = 0
    
    # We use j and k as the two inner pointers
    for j in range(1, n - 2):
        for k in range(j + 1, n - 1):
            
            # Pointer i: find the first index where a[i] + a[j] > k1
            # We can use a 3rd pointer starting from 0 up to j-1
            i = 0
            while i < j and a[i] + a[j] <= k1:
                i += 1
            valid_i_count = j - i  # All elements from i to j-1 are valid
            
            # Pointer l: find the first index from the right where a[k] + a[l] <= k2
            # Our 4th pointer 'l' counts how many elements from the end satisfy the condition
            l = n - 1
            while l > k and a[k] + a[l] > k2:
                l -= 1
            valid_l_count = n - 1 - l  # All elements from l+1 to n-1 are valid
            
            total_quadruplets += valid_i_count * valid_l_count
            
    return total_quadruplets
