# -*- coding: utf-8 -*-
"""Round 249: batch add 5 Mathematics PhD (second batch of basic-science PhD sweep)
- Harvard Mathematics PhD (Dec 15, 2026 5pm ET; GRE General NOT accepted; GRE Subject optional; TOEFL/IELTS; PhD only; GSAS standard funding)
- Yale Mathematics PhD (Dec 15, 2026 11:59pm ET; GRE General optional; GRE Math Subject REQUIRED; $105 fee; ETS 3987; 5-year full funding; first year no teaching)
- Caltech Mathematics PhD (Dec 15, 2026; GRE General NOT accepted; GRE Subject not required/not considered; ETS 4034; 5-year guaranteed support; Fall only; graduation by June Year 5)
- Columbia Mathematics PhD (Dec 2, 2026 11:59pm ET; GRE General No; GRE Math Subject REQUIRED with scheduling hardship waiver; TOEFL/IELTS/DET; en route MA+MPhil+PhD; ~60 students; 10-12 enter/year)
- Cornell Mathematics PhD (Dec 15, 2026; GRE Math Subject REQUIRED minimum 600; GRE General NOT considered; $105 fee; PhD only no terminal MS; 5-6 years; first round decisions mid-Feb)
Key finding: Math PhD GRE policy continues to diverge sharply from engineering PhD GRE-free trend.
"""
import os, re

BASE = os.path.dirname(os.path.abspath(__file__))
DET = os.path.join(BASE, "details")
os.makedirs(DET, exist_ok=True)

PROGRAMS = [
    {
        "id": "harvard-math-phd",
        "s": "harvard",
        "n": "数学博士",
        "en": "PhD in Mathematics (Harvard University, Kenneth C. Griffin Graduate School of Arts and Sciences, Department of Mathematics; research across pure and applied mathematics; located in Cambridge, MA; access to Center of Mathematical Sciences and Applications; PhD only; most graduates secure postdoctoral fellowships)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; general exam; thesis advisor; original research; dissertation defense; on-campus residential (Cambridge, MA); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 15, 2026, 5:00 p.m. Eastern Time (ET)**. No rolling admissions. All supporting documents due by deadline.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers (Harvard GSAS minimums); Duolingo also accepted by GSAS; waivers for English-instructed degree",
        "test": {"cls": "GRE GENERAL NOT ACCEPTED (Harvard GSAS Mathematics: 'GRE General: Not Accepted; GRE Subject: Optional.' Submitted General scores will not be reviewed. Subject scores optional. 3 LOR; Statement of Purpose; CV/resume; transcripts; no separate personal statement accepted.)"},
        "tui": "Harvard GSAS guarantees fully-funded PhD support for all admitted students typically for 5 years, including full tuition, stipend, and health insurance, through a combination of Research Assistantships, Teaching Fellowships, and fellowship awards (NSF GRFP, Harvard GSAS Fellowship, etc.).",
        "url": "details/harvard-math-phd.html",
    },
    {
        "id": "yale-math-phd",
        "s": "yale",
        "n": "数学博士",
        "en": "PhD in Mathematics (Yale University, Graduate School of Arts and Sciences, Department of Mathematics; five years of support with competitive stipend; no teaching in first year; research across algebra, analysis, geometry-topology, number theory, probability, applied math, combinatorics; PhD only)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5 (sometimes 6) years; first two years coursework and qualifying exams; research and dissertation; on-campus residential (New Haven, CT); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 15, 2026, 11:59 p.m. Eastern Time (ET)**. Fee $105. Fee waiver request deadline January 2, 2027. No rolling admissions.",
        "lang": "TOEFL iBT / IELTS Academic required for most applicants whose native language is not English (Yale GSAS); exemption for undergraduate degree from English-instructed institution with at least 3 years in residence",
        "test": {"cls": "GRE MATH SUBJECT REQUIRED (Yale GSAS Mathematics: 'GRE is optional. GRE Mathematics Subject Test is required.' General optional; Subject mandatory. ETS institution code 3987 (no department code needed). 3 LOR; SOP; transcripts; TOEFL/IELTS required.)"},
        "tui": "Yale guarantees fully-funded PhD support for all admitted students typically for 5 years: 12-month stipend to cover living expenses, fellowship covering full cost of tuition and student healthcare. No teaching in first year; relatively low teaching in later years.",
        "url": "details/yale-math-phd.html",
    },
    {
        "id": "caltech-math-phd",
        "s": "caltech",
        "n": "数学博士",
        "en": "PhD in Mathematics (California Institute of Technology, Division of Physics, Mathematics and Astronomy, Department of Mathematics; all applications due December; graduation expected by June of 5th year; support guaranteed for 5 years provided satisfactory progress; Fall admission only)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Expected graduation by June of 5th year; financial support not covered for summer after 5th year; on-campus residential (Pasadena, CA); Fall admission only (no rolling)",
        "ddl": "Fall 2027: application is open. **Deadline December 15, 2026** (Caltech Graduate Studies Office deadline for Mathematics option; department page notes applications due by December 10th for the following academic year). Offers typically issued during February. Reply by April 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic / PTE Academic / Duolingo accepted by Caltech Graduate Studies; self-reported scores accepted; all international students evaluated for English proficiency upon arrival (ESL course if needed)",
        "test": {"cls": "GRE GENERAL NOT ACCEPTED, GRE SUBJECT NOT REQUIRED (Caltech Mathematics: 'The GRE general and subject tests are not required and will not be considered in our evaluations.' ETS institution code 4034. Caltech accepts self-reported scores; no minimum GPA; holistic review.)"},
        "tui": "Caltech guarantees financial support for math graduate students for 5 years provided satisfactory academic progress. Support typically includes Graduate Teaching Assistantship (October-June) plus Graduate Research Assistantship or department fellowship (July-September), with full tuition grant and monthly stipend. Support independent of domestic/international status.",
        "url": "details/caltech-math-phd.html",
    },
    {
        "id": "columbia-math-phd",
        "s": "col",
        "n": "数学博士",
        "en": "PhD in Mathematics (Columbia University, Graduate School of Arts and Sciences, Department of Mathematics; intensive PhD program for full-time students; en route earns MA (after Year 1), MPhil (after Year 4), then PhD; 5 years of full fellowship support with 4 years of teaching beginning Year 2; ~60 students, 10-12 enter per year)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5 years; first-year written qualifying exam; second-year oral exam on two topics; dissertation; on-campus residential (New York, NY); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 2, 2026, 11:59 p.m. Eastern Time (ET)**. No rolling admissions. Note: GRE Subject scores may arrive by January 1 without adverse consequence if application filed on time.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test (DET) required for applicants whose undergraduate degree is from an institution in a country whose official language is not English (Columbia GSAS)",
        "test": {"cls": "GRE MATH SUBJECT REQUIRED (Columbia Mathematics: 'GRE Subject Exam scores are required of all applicants. However, in light of continued difficulties scheduling these exams, Fall 2026 applications without GRE Subject Exam scores will receive full consideration, if applicants can provide convincing evidence that they were unable to schedule the exam...' GRE General is not required. 3 LOR (up to 4); SOP; Personal Statement; transcripts; resume.)"},
        "tui": "Columbia GSAS offers 5 years of full fellowship support to doctoral students: all students admitted to PhD program become fellows in the Department and are exempt from tuition (may be responsible for certain fees). Students serve as teaching assistant or instructor for 4 years beginning Year 2; at least one semester as primary instructor. Affordable University housing in Morningside Heights available.",
        "url": "details/columbia-math-phd.html",
    },
    {
        "id": "cornell-math-phd",
        "s": "cornell",
        "n": "数学博士",
        "en": "PhD in Mathematics (Cornell University, Graduate Field of Mathematics, Ithaca campus; leads only to PhD - students are not accepted for terminal M.S.; 5-6 years; faculty strengths in algebra, algebraic geometry, analysis, applied math, combinatorics, dynamical systems, geometry, logic, Lie groups, number theory, probability, topology; Fall admission only)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Most students take 5-6 years to complete; minimum 6 semesters; A exam (candidacy) by second year before third year; B exam (dissertation defense) typically Year 5-6; on-campus residential (Ithaca, NY); Fall admission only (no Spring)",
        "ddl": "Fall 2027: application opened mid-September 2026. **Deadline December 15, 2026** for all application materials; incomplete applications not reviewed; LOR received after deadline may not be reviewed. Fee $105. First round decisions mid-February; offers continue until April 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers (Cornell Graduate School minimums); students funded through TA must demonstrate higher English proficiency (TOEFL iBT or IELTS Academic meeting Cornell minimum)",
        "test": {"cls": "GRE MATH SUBJECT REQUIRED, MINIMUM 600 (Cornell Mathematics: 'GRE MATH Subject Score: Required 600 or above. Applications without a GRE MATH Subject score or with a score below 600 will not be reviewed for admission. Only GRE MATH Subject scores will be considered; the General GRE scores will not be considered.' 3 LOR (up to 5); SOP; Personal Statement; transcripts.)"},
        "tui": "Cornell Graduate School typically guarantees fully-funded PhD support for all admitted students typically for 5 years, including full tuition, stipend, and health insurance, through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, Cornell Fellowship, etc.).",
        "url": "details/cornell-math-phd.html",
    },
]

DETAIL_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{school} - {en}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;max-width:960px;margin:24px auto;padding:0 20px;color:#222;line-height:1.6}}
h1{{font-size:24px;border-bottom:2px solid #1a73e8;padding-bottom:8px}}
h2{{font-size:18px;color:#1a73e8;margin-top:24px}}
.card{{background:#f8f9fa;border-left:4px solid #1a73e8;padding:12px 16px;margin:12px 0;border-radius:4px}}
.meta{{display:grid;grid-template-columns:120px 1fr;gap:6px 12px;font-size:14px}}
.meta b{{color:#555}}
ul{{margin:6px 0;padding-left:20px}}
.note{{background:#fff3cd;border-left-color:#ffc107;padding:10px 14px;margin-top:16px;font-size:13px}}
a{{color:#1a73e8}}
</style>
</head>
<body>
<h1>{school} - {en}</h1>
<div class="card">
<div class="meta">
<b>Degree</b><span>{deg}</span>
<b>Level</b><span>Research Doctorate (PhD)</span>
<b>STEM</b><span>{stem_label}</span>
<b>Duration</b><span>{dur}</span>
<b>Deadline</b><span>{ddl}</span>
<b>Language</b><span>{lang}</span>
<b>Standardized</b><span>{test_cls}</span>
<b>Funding</b><span>{tui}</span>
</div>
</div>

<h2>Program Overview</h2>
<div class="card">
{overview}
</div>

<h2>Admissions Requirements</h2>
<div class="card">
{requirements}
</div>

<h2>Research Areas</h2>
<div class="card">
{research}
</div>

<h2>Official Source</h2>
<div class="card">
{source}
</div>

<div class="note">
<strong>Note:</strong> Second batch of basic-science PhD sweep (Harvard, Yale, Caltech, Columbia, Cornell Mathematics PhD). Continues the Math PhD GRE policy divergence finding from Round 248. Yale and Columbia require GRE Math Subject Test; Cornell requires Math Subject with minimum 600 (below which applications are not reviewed); Harvard does not accept GRE General at all (Subject optional); Caltech does not consider either General or Subject. Deadlines: Dec 2 (Columbia ET), Dec 15 (Harvard 5pm ET / Yale 11:59pm ET / Caltech / Cornell). All 5 programs are STEM-designated, fully-funded, on-campus residential, and Fall admission only. Cornell admits only to PhD (no terminal MS); Columbia awards en route MA (Year 1) and MPhil (Year 4). Note: Columbia allows scheduling hardship waiver for Math Subject (with a written statement); Cornell has a hard 600 floor below which applications are not reviewed.
</div>
</body>
</html>
"""

PAGES = {
    "harvard-math-phd": {
        "school": "Harvard University, Kenneth C. Griffin Graduate School of Arts and Sciences, Department of Mathematics",
        "en": "PhD in Mathematics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5-6 years; coursework; general exam; thesis advisor; original research; dissertation defense; on-campus residential (Cambridge, MA); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 15, 2026, 5:00 p.m. ET**. No rolling admissions.",
        "lang": "TOEFL iBT / IELTS Academic required (Harvard GSAS minimums); Duolingo also accepted; waivers for English-instructed degree",
        "test_cls": "GRE GENERAL NOT ACCEPTED (Harvard GSAS: 'GRE General: Not Accepted; GRE Subject: Optional.' Submitted General scores not reviewed. 3 LOR; SOP; no personal statement accepted.)",
        "tui": "Harvard GSAS guarantees fully-funded PhD support for all admitted students typically for 5 years: full tuition, stipend, and health insurance through RA, TF, and fellowships.",
        "overview": "The Harvard University Department of Mathematics, through the Kenneth C. Griffin Graduate School of Arts and Sciences (GSAS), offers a PhD program designed for students looking to conduct original mathematical research with the aim of becoming a research mathematician. Students are located in Cambridge, Massachusetts, one of the most active centers of mathematics in the world; other universities in the area include Boston College, Boston University, Brandeis University, MIT, and Northeastern University. Students have access to a wide range of resources, including the Center of Mathematical Sciences and Applications, which hosts conferences, seminars, and workshops bringing together researchers from an extensive variety of disciplines and institutions. Most graduates of the program have been very successful at securing postdoctoral fellowships in academia; a number of recent graduates have won prestigious fellowships including the Clay Fellowship, the Simons Fellowship, and NSF Graduate Research Fellowship. Others take jobs in industry. The application deadline is December 15, 2026 at 5:00 p.m. Eastern Time. Critically, Harvard GSAS does not accept GRE General Test scores for the Mathematics PhD program; the GRE Subject Test is optional. A statement of purpose should convince the admissions committee that the applicant is able to communicate effectively and with a deep understanding of mathematics; it is not intended to be a biographical sketch. Personal Statement is Not Accepted. Three letters of recommendation are required along with transcripts.",
        "requirements": "<ul><li>Bachelor's degree in mathematics or related quantitative field</li><li>**GRE General NOT ACCEPTED** (submitted General scores not reviewed)</li><li>GRE Subject Test optional (not required)</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers</li><li>Duolingo also accepted by GSAS</li><li>Harvard GSAS online application</li><li>Statement of Purpose (deep understanding of mathematics; not a biographical sketch)</li><li>Personal Statement NOT accepted</li><li>3 letters of recommendation</li><li>CV/resume</li><li>Transcripts</li><li>**Deadline December 15, 2026, 5:00 p.m. ET**</li><li>Fall admission only</li><li>On-campus residential (Cambridge, MA)</li><li>PhD only (no terminal MS listed)</li></ul>",
        "research": "<ul><li>Pure mathematics (algebra, analysis, geometry, topology, number theory, logic)</li><li>Applied mathematics</li><li>Mathematical physics</li><li>Probability</li><li>Combinatorics</li><li>Partial differential equations</li><li>Access to Center of Mathematical Sciences and Applications</li></ul>",
        "source": '<a href="https://gsas.harvard.edu/program/mathematics" target="_blank">Harvard GSAS: Mathematics (Dec 15, 2026, 5:00pm ET; PhD only; GRE General Not Accepted; GRE Subject Optional; TOEFL/IELTS; 3 LOR; Statement of Purpose; Personal Statement Not Accepted; contact Marjorie Bell 617-495-2171)</a> | <a href="https://gsas.harvard.edu/programs?f%5B0%5D=degrees_offered%3A157&f%5B1%5D=gre_requirement%3A161&f%5B2%5D=gre_requirement%3A162&f%5B3%5D=gre_requirement%3A163&page=4" target="_blank">Harvard GSAS Program Search: Mathematics (GRE Requirement: Not Accepted; Degrees: PhD; Deadline Dec 15, 2025/2026 5:00pm)</a>',
    },
    "yale-math-phd": {
        "school": "Yale University, Graduate School of Arts and Sciences, Department of Mathematics",
        "en": "PhD in Mathematics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5 (sometimes 6) years; first two years coursework and qual exams; research and dissertation; on-campus (New Haven, CT); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 15, 2026, 11:59 p.m. ET**. Fee $105. Fee waiver request deadline January 2, 2027.",
        "lang": "TOEFL iBT / IELTS Academic required for most applicants whose native language is not English; exemption for undergraduate degree from English-instructed institution with at least 3 years in residence",
        "test_cls": "GRE MATH SUBJECT REQUIRED (Yale GSAS Mathematics: 'GRE is optional. GRE Mathematics Subject Test is required.' ETS 3987; no department code needed. General optional; Subject mandatory. 3 LOR; SOP.)",
        "tui": "Yale guarantees fully-funded PhD support for all admitted students typically for 5 years: 12-month stipend plus fellowship covering full tuition and student healthcare. No teaching in first year; relatively low teaching in later years.",
        "overview": "The Yale University Department of Mathematics offers a PhD program with one of the top graduate programs in the US. The program gives students the opportunity to do research under the guidance of distinguished mathematicians. Its graduates take positions at leading mathematics departments world-wide, as well as prominent positions in industry. The program offers five years of support and provides a competitive stipend. There is no teaching in the first year and relatively low teaching in later years. In their first two years, students focus on building their general knowledge and passing the qualifying exams, but are also encouraged to use the time to think about their areas of interest, work together to explore them, and begin making connections with faculty advisors. There are few formal requirements and this flexibility allows students to develop independence, formulating and following their own goals. Mathematics, while requiring intense individual focus, also thrives on collaborative work. Students form study groups and seminars together, and also benefit from the excellent cohort of Gibbs Assistant Professors and other Postdoctoral Fellows. Research, and the contribution of new ideas and results to the body of mathematical knowledge, naturally form the main focus of the next few years; typically students complete their PhD by the end of the 5th (sometimes 6th) year. For Academic Year 2027-2028, the application deadline is December 15, 2026. GRE Subject Math Test scores are required; GRE General Test scores are optional. TOEFL or IELTS scores are required for most applicants whose native language is not English. The application fee is $105; applicants wishing to apply for a fee waiver should apply as early as possible and at least several days before the deadline; the fee waiver request deadline is January 2, 2027. ETS institution code is 3987. PhD students at Yale are normally fully-funded: during their programs, students receive a twelve-month stipend to cover living expenses and a fellowship that covers the full cost of tuition and student healthcare.",
        "requirements": "<ul><li>Bachelor's degree in mathematics or related quantitative field</li><li>GRE General optional</li><li>**GRE Mathematics Subject Test REQUIRED**</li><li>ETS institution code 3987 (no department code needed)</li><li>TOEFL iBT / IELTS Academic required for most applicants whose native language is not English</li><li>Exemption for undergraduate degree from English-instructed institution with at least 3 years in residence</li><li>Yale GSAS online application</li><li>Statement of purpose</li><li>3 letters of recommendation</li><li>Transcripts</li><li>Fee $105</li><li>Fee waiver request deadline January 2, 2027</li><li>**Deadline December 15, 2026, 11:59 p.m. ET**</li><li>Fall admission only</li><li>5 years of support; no teaching in first year</li><li>On-campus residential (New Haven, CT)</li></ul>",
        "research": "<ul><li>Algebraic geometry</li><li>Applied mathematics</li><li>Combinatorics and discrete mathematics</li><li>Complex and real analysis</li><li>Differential geometry</li><li>Geometric analysis</li><li>Group actions and dynamical systems</li><li>Harmonic analysis</li><li>Lie groups and discrete subgroups</li><li>Low-dimensional topology</li><li>Mathematical physics</li><li>Number theory</li><li>Numerical analysis</li><li>Partial differential equations</li><li>Probability and stochastic analysis</li><li>Representation theory</li><li>Teichmuller theory</li></ul>",
        "source": '<a href="https://gsas.yale.edu/programs-of-study/mathematics" target="_blank">Yale GSAS: Mathematics (Dec 15, 11:59pm ET; GRE General optional; GRE Math Subject REQUIRED; TOEFL/IELTS; 12-month stipend + full tuition + healthcare; DGS Ivan Loseu)</a> | <a href="https://math.yale.edu/graduates" target="_blank">Yale Mathematics Graduates (AY 2027-2028: deadline Dec 15, 2026; GRE Subject Math required; GRE General optional; TOEFL/IELTS; $105 fee; fee waiver recommended early; 5 years support; no teaching first year; typically PhD by end of 5th (sometimes 6th) year)</a> | <a href="https://gsas.yale.edu/admissions/phdmasters-application-process/standardized-testing-requirements" target="_blank">Yale GSAS Standardized Testing Requirements (Mathematics: GRE General Optional; GRE Math Subject REQUIRED; ETS 3987; no department code needed)</a> | <a href="https://gsas.yale.edu/admissions/phdmasters-application-process/dates-deadlines" target="_blank">Yale GSAS Dates & Deadlines (Dec 15, 2026 for Mathematics; Jan 2, 2027 for fee waiver requests and Applied & Computational Mathematics; April 15, 2027 reply deadline)</a>',
    },
    "caltech-math-phd": {
        "school": "California Institute of Technology, Division of Physics, Mathematics and Astronomy, Department of Mathematics",
        "en": "PhD in Mathematics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Expected graduation by June of 5th year; financial support not covered for summer after 5th year; on-campus (Pasadena, CA); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 15, 2026** (Caltech Graduate Studies Office deadline for Mathematics option). Offers typically issued during February. Reply by April 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic / PTE Academic / Duolingo accepted; self-reported scores accepted; all international students evaluated for English proficiency upon arrival (ESL course if needed)",
        "test_cls": "GRE GENERAL NOT ACCEPTED, SUBJECT NOT CONSIDERED (Caltech Mathematics: 'The GRE general and subject tests are not required and will not be considered in our evaluations.' ETS 4034; no minimum GPA; holistic review.)",
        "tui": "Caltech guarantees financial support for math graduate students for 5 years provided satisfactory academic progress. Support includes GTA (Oct-Jun) plus GRA or department fellowship (Jul-Sep), with full tuition grant and monthly stipend. Support independent of domestic/international status.",
        "overview": "The California Institute of Technology Department of Mathematics offers a PhD program. All applications are submitted online at the Graduate Studies Office and are due by December 15 (department page notes applications due by December 10th for the following academic year). Critically, the GRE general and subject tests are not required and will not be considered in the department's evaluations. The Math Graduate Admissions Committee reviews applications, and recommendations for admission are sent to the Graduate Studies Office. The official offer of admission comes from the Graduate Studies Office via email through the online application system, generally during the month of February. Students must respond to the offer by April 15. Financial support for math graduate students is guaranteed for 5 years, provided the student is making satisfactory academic progress. Students are generally supported by a Graduate Teaching Assistantship for the academic months (October - June) and either by a Graduate Research Assistantship or math department fellowship for the summer months (July - September). All assistantships and fellowships include a full tuition grant and monthly stipend to cover living expenses. All support is independent of whether the student is domestic or international. Graduation is expected by June of the 5th year of study, so financial support is not covered for the summer after the 5th year. ETS institution code is 4034. Caltech accepts self-reported scores and will validate scores electronically with ETS. Caltech recognizes TOEFL, PTE, IELTS, and Duolingo. There is no minimum GPA; personal statement, transcripts, and letters of recommendation are all taken into consideration.",
        "requirements": "<ul><li>Bachelor's degree in science or engineering related to Mathematics option</li><li>**GRE General NOT ACCEPTED** (submitted scores not considered)</li><li>**GRE Subject NOT required and not considered**</li><li>ETS institution code 4034</li><li>TOEFL iBT / IELTS Academic / PTE Academic / Duolingo accepted</li><li>Self-reported scores accepted; all international students evaluated for English proficiency upon arrival</li><li>Caltech Graduate Studies online application</li><li>Personal statement</li><li>3 letters of recommendation</li><li>Transcripts</li><li>No minimum GPA; holistic review</li><li>**Deadline December 15, 2026** (department page: December 10th)</li><li>Fall admission only (no rolling)</li><li>Expected graduation by June of 5th year</li><li>5 years guaranteed support (satisfactory progress required)</li><li>On-campus residential (Pasadena, CA)</li></ul>",
        "research": "<ul><li>Pure mathematics (algebra, analysis, geometry, topology, number theory)</li><li>Applied mathematics</li><li>Mathematical physics</li><li>Probability</li><li>Dynamical systems</li><li>Combinatorics</li><li>Cross-disciplinary with CMS (Computing + Mathematical Sciences), Physics, Astronomy</li></ul>",
        "source": '<a href="https://mathematics.caltech.edu/academics/graduate-studies/admissions-and-financial-support" target="_blank">Caltech Mathematics: Admissions and Financial Support (due by December 10th; GRE general and subject not required and not considered; offers in February; reply by April 15; 5-year guaranteed support; full tuition + monthly stipend; independent of citizenship; graduation expected by June Year 5)</a> | <a href="https://gradoffice.caltech.edu/documents/28937/AppInstructions_Required_Tests_rev.9-2024.pdf" target="_blank">Caltech Required Tests PDF (Mathematics PhD: GRE General N = Not Accepted; ETS 4034; self-reported accepted; TOEFL/PTE/IELTS/Duolingo accepted; no minimum score)</a> | <a href="https://gradoffice.caltech.edu/admissions" target="_blank">Caltech Graduate Studies Admissions (no minimum GPA; holistic review; applicants may only apply to one option per admission cycle; late applications at disadvantage for financial aid)</a>',
    },
    "columbia-math-phd": {
        "school": "Columbia University, Graduate School of Arts and Sciences, Department of Mathematics",
        "en": "PhD in Mathematics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5 years; first-year written qual exam; second-year oral exam on two topics; dissertation; on-campus (New York, NY); Fall admission only",
        "ddl": "Fall 2027: application is open. **Deadline December 2, 2026, 11:59 p.m. ET**. GRE Subject scores may arrive by January 1 without adverse consequence if application filed on time.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test (DET) required for applicants whose undergraduate degree is from a country whose official language is not English",
        "test_cls": "GRE MATH SUBJECT REQUIRED (Columbia Mathematics: 'GRE Subject Exam scores are required of all applicants. However, in light of continued difficulties scheduling these exams, Fall 2026 applications without GRE Subject Exam scores will receive full consideration, if applicants can provide convincing evidence that they were unable to schedule the exam...' GRE General not required. 3 LOR (up to 4); SOP; Personal Statement; resume.)",
        "tui": "Columbia GSAS offers 5 years of full fellowship support: all PhD students become fellows and are exempt from tuition (certain fees may apply). Students serve as TA or instructor for 4 years beginning Year 2; at least one semester as primary instructor. Affordable University housing in Morningside Heights available.",
        "overview": "The Columbia University Department of Mathematics offers an intensive PhD program for full-time students planning careers in research and university teaching. The MA degree is earned, as a matter of course, after completing two Residence Units and the written qualifying examination. After fulfilling the requirements for the MA degree in Mathematics, a graduate student takes a variety of advanced courses offered by the department and, in some cases, by certain related departments. The student also may participate in seminars related to his or her interests. Doctoral students generally receive five years of full fellowship support and in return are required to participate in the teaching program for four years beginning in the second year of study. Fellowships are awarded in recognition of academic achievement and in expectation of scholarly success. In the first year of PhD studies, students must pass written examinations in the areas of the basic first-year courses. In the second year an oral examination on two selected topics must be passed. Subsequent years are devoted to seminars, research, and the preparation of a dissertation. Students are required to serve as a teaching assistant or instructor for four years beginning with the second year of study; all students must serve as a primary instructor for at least one semester. En route to the PhD, students earn three degrees: a Master of Arts (after year one), a Master of Philosophy (after year four), and the Doctorate of Philosophy (after a successful thesis defense). The PhD program in mathematics has an enrollment of approximately 60 students; typically 10-12 students enter each year. The application deadline for Fall admission is December 2, 2026. Critically, GRE Subject Exam scores are required of all applicants; however, in light of continued difficulties scheduling these exams, applications without GRE Subject Exam scores will receive full consideration if applicants can provide convincing evidence that they were unable to schedule the exam in an accessible location (a statement describing the difficulties should be uploaded via the 'Additional Information and Supplementary Media' page). GRE General Test is not required. All applicants whose undergraduate degree is from an institution in a country whose official language is not English must submit TOEFL, IELTS, or Duolingo English Test. Three letters of recommendation are required (at least two from academic recommenders); up to four letters may be included. A statement of academic purpose, a personal statement, and a resume are required.",
        "requirements": "<ul><li>Bachelor's degree in mathematics or related quantitative field</li><li>GRE General Test not required</li><li>**GRE Mathematics Subject Test REQUIRED**</li><li>Scheduling hardship waiver available: upload statement describing difficulties via 'Additional Information and Supplementary Media'</li><li>GRE Subject scores may arrive by January 1 without adverse consequence if application filed on time</li><li>TOEFL iBT / IELTS Academic / Duolingo English Test (DET) required for non-English-instructed undergraduate degree</li><li>Columbia GSAS online application</li><li>Statement of academic purpose</li><li>Personal statement</li><li>Resume/CV (required)</li><li>3 letters of recommendation (at least 2 from academic recommenders; up to 4)</li><li>Transcripts</li><li>**Deadline December 2, 2026, 11:59 p.m. ET**</li><li>Fall admission only</li><li>5 years full fellowship support</li><li>4 years of teaching beginning Year 2 (at least 1 semester as primary instructor)</li><li>En route degrees: MA (Year 1), MPhil (Year 4), PhD (Year 5)</li><li>~60 students; 10-12 enter per year</li><li>On-campus residential (New York, NY)</li></ul>",
        "research": "<ul><li>Pure mathematics (algebra, analysis, geometry, topology, number theory, logic)</li><li>Algebraic geometry and number theory</li><li>Modern geometry</li><li>Lie groups and representations</li><li>Complex analysis and Riemann surfaces</li><li>Probability and stochastic analysis</li><li>Financial mathematics (academic research; professional finance qualification via Master's in Mathematical Finance)</li><li>Applied mathematics (directed to Applied Physics and Applied Mathematics Department)</li><li>Allied doctoral programs in statistics, computer science, and applied mathematics</li></ul>",
        "source": '<a href="https://www.gsas.columbia.edu/content/mathematics" target="_blank">Columbia GSAS: Mathematics (Dec 2, 2026 11:59pm ET; PhD only; GRE General No; GRE Math Subject Yes with scheduling hardship waiver; TOEFL/IELTS/DET; 3 LOR; SOP; Personal Statement; Resume; DGS Michael Harris; Chair Chiu-Chu Melissa Liu)</a> | <a href="https://www.math.columbia.edu/programs-math/graduate-program/prospective-doctoral-students/" target="_blank">Columbia Mathematics: Prospective Doctoral Students (General recommended but not required; Math Subject required with scheduling hardship waiver; scores by January 1 OK; no transfer credits; Columbia first-year courses mandatory)</a> | <a href="https://www.math.columbia.edu/programs-math/graduate-program/" target="_blank">Columbia Mathematics Graduate Program (first-year written exam; second-year oral on two topics; 4 years TA/instructor beginning Year 2; en route MA + MPhil + PhD; ~60 students; 10-12 enter/year; all PhD students exempt from tuition)</a> | <a href="https://www.gsas.columbia.edu/content/admissions-deadlines" target="_blank">Columbia GSAS Admissions Deadlines (Mathematics PhD Fall 12/2/2026; Statistics PhD 1/7/2027; all deadlines 11:59pm ET)</a>',
    },
    "cornell-math-phd": {
        "school": "Cornell University, Graduate Field of Mathematics, Ithaca Campus",
        "en": "PhD in Mathematics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Most students take 5-6 years to complete; minimum 6 semesters; A exam by second year before third year; B exam typically Year 5-6; on-campus (Ithaca, NY); Fall admission only (no Spring)",
        "ddl": "Fall 2027: application opened mid-September 2026. **Deadline December 15, 2026** for all materials. Fee $105. First round decisions mid-February; offers continue until April 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers (Cornell Graduate School minimums); TA-funded students must demonstrate higher English proficiency",
        "test_cls": "GRE MATH SUBJECT REQUIRED, MINIMUM 600 (Cornell Mathematics: 'GRE MATH Subject Score: Required 600 or above. Applications without a GRE MATH Subject score or with a score below 600 will not be reviewed for admission. Only GRE MATH Subject scores will be considered; the General GRE scores will not be considered.' 3 LOR (up to 5); SOP; Personal Statement.)",
        "tui": "Cornell Graduate School typically guarantees fully-funded PhD support for all admitted students typically for 5 years: full tuition, stipend, and health insurance through RA, TA, and fellowships (NSF GRFP, Cornell Fellowship).",
        "overview": "The Cornell University Graduate Field of Mathematics offers a PhD program that leads only to the PhD degree; students are not accepted for an M.S. degree. The program takes most students five to six years of graduate study to complete. One feature that makes the program at Cornell particularly attractive is the broad range of interests of the faculty. The department has outstanding groups in the areas of algebra, algebraic geometry, analysis, applied mathematics, combinatorics, dynamical systems, geometry, logic, Lie groups, number theory, probability, and topology. The field also maintains close ties with distinguished graduate programs in the fields of applied mathematics, computer science, operations research, and statistics and data science. PhD students in the field of mathematics may earn a special master's of science in computer science. The application cycle for Fall 2027 opened mid-September 2026. The application deadline is December 15, 2026 for all application materials; incomplete applications will not be considered for admissions. Applications missing letters of recommendation or with letters received past this deadline may not be reviewed. Critically, the GRE Math Subject Score is required at 600 or above; applications without a GRE Math Subject score or with a score below 600 will not be reviewed for admission. Only the GRE Math Subject scores will be considered; the General GRE scores will not be considered. The application fee is $105. Three letters of recommendation are required (five letters allowed); additional letters are allowed. A statement of purpose and a personal statement are required. Transcripts are required from every college or university attended. The first round of admission decisions is made in mid-February; the department typically continues to consider applications and make offers until April 15. The application is considered by the graduate admissions committee until the applicant receives a rejection letter or until 8 p.m. on April 15th, whichever comes first. Core courses include MATH 6110 Real Analysis, MATH 6120 Complex Analysis, MATH 6310 Algebra, MATH 6320 Algebra, and MATH 6510 Algebraic Topology. The A exam (admission to candidacy) field deadline is second year, before the beginning of the third year.",
        "requirements": "<ul><li>Bachelor's degree; demonstrated mastery of undergraduate mathematics major material</li><li>**GRE Math Subject Test REQUIRED, minimum 600**</li><li>Applications without Math Subject score or with score below 600 will not be reviewed</li><li>**GRE General Test NOT considered**</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers (Cornell Graduate School minimums)</li><li>TA-funded students must demonstrate higher English proficiency</li><li>Cornell Graduate School online application (opened mid-September 2026)</li><li>Statement of purpose (describing experiences and goals in mathematics)</li><li>Personal statement (background and how it influenced decision to pursue graduate degree)</li><li>3 letters of recommendation (up to 5 allowed; additional letters allowed)</li><li>Transcripts from every college or university attended</li><li>Fee $105</li><li>Fee waiver request available through payment page</li><li>**Deadline December 15, 2026** for all materials</li><li>Incomplete applications not reviewed; LOR after deadline may not be reviewed</li><li>Fall admission only (no Spring)</li><li>5-6 years typical completion; minimum 6 semesters</li><li>PhD only (no terminal MS)</li><li>A exam by second year before third year</li><li>First round decisions mid-February; offers continue until April 15, 2027</li><li>On-campus residential (Ithaca, NY)</li></ul>",
        "research": "<ul><li>Algebra</li><li>Algebraic geometry</li><li>Analysis</li><li>Applied mathematics</li><li>Combinatorics</li><li>Dynamical systems</li><li>Geometry</li><li>Logic</li><li>Lie groups</li><li>Number theory</li><li>Probability</li><li>Topology</li><li>Close ties with applied mathematics, computer science, operations research, statistics and data science</li></ul>",
        "source": '<a href="https://math.cornell.edu/graduate-admissions-application" target="_blank">Cornell Mathematics Graduate Admissions (Fall 2027 opened mid-September 2026; Dec 15, 2026 deadline; GRE Math Subject Required 600+; below 600 not reviewed; General GRE not considered; 3 LOR (up to 5); SOP; Personal Statement; fee $105; first round decisions mid-February; offers until April 15)</a> | <a href="https://courses.cornell.edu/programs/mathematics-phd/" target="_blank">Cornell Courses: Mathematics (PhD) (CIP 27.0101; 5-6 years; no terminal MS; core courses MATH 6110/6120/6310/6320/6510; A exam by second year; TOEFL/IELTS; 3 LOR up to 5; contact gradinfo@math.cornell.edu 607-254-8993)</a> | <a href="https://gradschool.cornell.edu/academics/fields-of-study/subject/mathematics/mathematics-phd-ithaca/" target="_blank">Cornell Graduate School: Mathematics PhD (Ithaca) (Fall Dec 15; no Spring; GRE Subject minimum 600; 3 LOR up to 5; English proficiency required; 5-6 years; PhD students may earn special MS in CS; math minor and math concentration available)</a>',
    },
}

# Write detail pages
for p in PROGRAMS:
    key = p["id"]
    d = PAGES[key]
    html = DETAIL_TEMPLATE.format(
        school=d["school"], en=d["en"], deg=d["deg"], stem_label=d["stem_label"],
        dur=d["dur"], ddl=d["ddl"], lang=d["lang"], test_cls=d["test_cls"], tui=d["tui"],
        overview=d["overview"], requirements=d["requirements"],
        research=d["research"], source=d["source"],
    )
    path = os.path.join(DET, key + ".html")
    with open(path, "w", encoding="utf-8") as f:
        f.write(html)
    print(f"Wrote: {key}.html")

# Append PROGRAMS
idx_path = os.path.join(BASE, "index_main.html")
with open(idx_path, "r", encoding="utf-8") as f:
    html = f.read()

def build_entry(p):
    return ('{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},'
            'dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test_cls}"}},'
            'tui:"{tui}",url:"{url}"}}').format(
        id=p["id"], s=p["s"], n=p["n"], en=p["en"], deg=p["deg"], lvl=p["lvl"],
        stem=p["stem"], dur=p["dur"], ddl=p["ddl"], lang=p["lang"],
        test_cls=p["test"]["cls"].replace('"', "'"),
        tui=p["tui"].replace('"', "'"), url=p["url"],
    )

new_entries = ",\n".join(build_entry(p) for p in PROGRAMS)

m = re.search(r'const\s+PROGRAMS\s*=\s*\[', html)
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[': depth += 1
    elif c == ']': depth -= 1
    i += 1
insert_pos = i - 1
prefix = html[:insert_pos].rstrip()
suffix = html[insert_pos:]
if prefix.endswith('{'):
    new_block = prefix + "\n" + new_entries + "\n" + suffix
else:
    new_block = prefix + ",\n" + new_entries + "\n" + suffix

# Append VD on new_block (re-locate to avoid offset)
vd_entries = ",\n".join(f'"{p["url"]}"' for p in PROGRAMS)
m2 = re.search(r'VERIFIED_DETAILS\s*=\s*new\s+Set\s*\(\s*\[', new_block)
vstart = m2.end()
vdepth = 1
j = vstart
while j < len(new_block) and vdepth > 0:
    c = new_block[j]
    if c == '[': vdepth += 1
    elif c == ']': vdepth -= 1
    j += 1
vinsert_pos = j - 1
vprefix = new_block[:vinsert_pos].rstrip()
vsuffix = new_block[vinsert_pos:]
if vprefix.endswith(','):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
elif vprefix.endswith('['):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
else:
    new_block = vprefix + ",\n" + vd_entries + "\n" + vsuffix

with open(idx_path, "w", encoding="utf-8") as f:
    f.write(new_block)

print(f"Appended {len(PROGRAMS)} PROGRAMS entries and {len(PROGRAMS)} VD entries")
print(f"Done. File size: {os.path.getsize(idx_path)}")
