import re from typing import Set def parse_logs(logs: str) -> Set[str]: current_users = set() join_pattern = r'(?<=:)([^:()]*)(?=\()(?=.*\bAuthenticated\b)' leave_pattern = r'(?<=:)([^:()]*)(?=\()(?=.*\bConnection closed\b)' for line in logs.splitlines(): line = line.strip() join_match = re.search(join_pattern, line) if join_match: username = join_match.group(1) current_users.add(username) leave_match = re.search(leave_pattern, line) if leave_match: username = leave_match.group(1) current_users.discard(username) return current_users