# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,re
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding="utf-8")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for u in ["https://cs.uchicago.edu/","https://cs.uchicago.edu/masters","https://cs.uchicago.edu/masters-program","https://cs.uchicago.edu/graduate-programs","https://cs.uchicago.edu/academics"]:
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,context=ctx,timeout=15)
        d=r.read().decode("utf-8","ignore")
        links=re.findall(r'href="([^"]+)"',d)
        rel=sorted({x for x in links if any(k in x for k in ["master","graduate","ms","degree","admiss"]) and "mailto" not in x})
        print("OK",r.status,u,"raw",len(d))
        for x in rel[:25]: print("   ",x)
    except Exception as e:
        print("FAIL",u,repr(e)[:90])
