```python
def search(arr, n):
    """
    Finds the element that appears only once in a sorted array where all
    other elements appear twice.
    
    Args:
        arr: A sorted list of integers.
        n: The number of elements in the list.
        
    Returns:
        The integer that appears only once.
    """
    low = 0
    high = n - 1

    # Perform a binary search. The search space is shrunk until low and high
    # converge on the index of the single element.
    while low < high:
        mid = low + (high - low) // 2

        # Ensure mid is an even index so we can check pairs.
        # A pair should start at an even index (0, 2, 4, ...).
        if mid % 2 == 1:
            mid -= 1

        # If the elements at mid and mid + 1 are a pair, it means the
        # single element is not in the left part of the array (including
        # this pair). So, we search in the right part.
        if arr[mid] == arr[mid + 1]:
            low = mid + 2
        # If they are not a pair, the single element must be in the left
        # part of the array (including the element at mid).
        else:
            high = mid

    # When the loop ends, low and high will point to the single element.
    return arr[low]

```