of paragraph (4) on the resident level for the hospital determined without regard to this paragraph but taking into account paragraph (7)(A). (iv) Applicable residency training program (I) In general The term applicable residency training program means a medical residency training program that is for the applicable primary specialty that, as of the date of the enactment of this paragraph, is the applicable primary specialty that has most recently been designated as a primary specialty by the American Board of Medical Specialties. (II) Applicable primary specialty The term applicable primary specialty means a primary specialty a resident of which is not, as of the date of the enactment of this paragraph, counted as an FTE resident for purposes of this subsection. For purposes of the preceding sentence, the term primary specialty does not include a subspecialty. (H) Affiliation The provisions of this paragraph shall be applied to hospitals which are members of the same affiliated group (as defined by the Secretary under paragraph (4)(H)(ii)) and the reference resident level for each such hospital shall be the reference resident level with respect to the cost reporting period that results in the smallest difference between the reference resident level and the otherwise applicable resident limit. . (b) IME (1) In general Section 1886(d)(5)(B)(v) of the Social Security Act ( 42 U.S.C. 1395ww(d)(5)(B)(v) ), in the second sentence, is amended by striking subsections (h)(7) and (h)(8) and inserting subsections (h)(7), (h)(8), and (h)(9) . (2) Conforming amendment Section 1886(d)(5)(B) of the Social Security Act ( 42 U.S.C. 1395ww(d)(5)(B) ) is amended by adding at the end the following clause: (xii) For discharges occurring on or after July 1, 2018, insofar as an additional payment amount under this subparagraph is attributable to resident positions distributed to a hospital under subsection (h)(9)(B), the indirect teaching adjustment factor shall be computed in the same manner as provided under clause (ii) with respect