Given a list of user activity events events, where each event is a pair [user_id, timestamp], and two integers window_size and max_events, write a function that returns all user_id values that are anomalous. A user is anomalous if they perform more than max_events events within any inclusive time window of length window_size. Return the flagged user IDs in sorted order.
def detect_anomalies(events, window_size, max_events):