#!/usr/bin/env python3 """User summary tool. Reads a JSON array of user records, filters out inactive users, sorts them by registration date (oldest first), and prints a summary. Expected output order: chronologically by actual registration instant, earliest first. Two users who registered at the same UTC moment should appear in their original input order (stable sort). There is exactly one bug. It is not a syntax error. The program runs without crashing on the sample input. The bug causes WRONG output: the sort order is incorrect for some users. Find it. Explain the root cause. Propose a one-line fix. """ import json import sys from datetime import datetime def load_users(path): with open(path) as f: return json.load(f) def is_active(user): return user.get("active", False) def parse_date(user): return datetime.fromisoformat(user["registered_at"]) def summarize(users): active = [u for u in users if is_active(u)] active.sort(key=lambda u: u["registered_at"]) lines = [] for u in active: lines.append(f"{u['name']} (registered {u['registered_at']})") return "\n".join(lines) def main(): if len(sys.argv) != 2: print("usage: program.py ", file=sys.stderr) sys.exit(1) users = load_users(sys.argv[1]) print(summarize(users)) if __name__ == "__main__": main()