Implement the function count_average_elements that counts the number of average elements in a given sequence of integers. An element ( a_k ) is considered an average element if there exist two distinct indices ( i ) and ( j ) such that ( a_k = \frac{(a_i + a_j)}{2} ).
Functionality Requirements:
The function should accept a single parameter:
sequence (list of int): A list of integers that needs to be analyzed.
The function should return:
An integer representing the number of average elements in the input sequence.
Input/Output Requirements:
Input: A list of integers. The list may contain duplicate values and can be empty.
Output: An integer that counts how many elements in the list are average elements.
Implementation Guidelines:
The implementation must be efficient and should utilize sorting to help find average elements.
Ensure that your solution avoids counting the same average element multiple times.
File Structure
Save your implementation in a file named /app/solution.py.