the amount of the deficit referred to in subparagraph (B). (4) Netting among United States shareholders in same affiliated group (A) In general In the case of any affiliated group which includes at least one E&P net surplus shareholder and one E&P net deficit shareholder, the amount which would (but for this paragraph) be taken into account under section 951(a)(1) by reason of subsection (a) by each such E&P net surplus shareholder shall be reduced (but not below zero) by such shareholder’s applicable share of the affiliated group’s aggregate unused E&P deficit. (B) E&P net surplus shareholder For purposes of this paragraph, the term E&P net surplus shareholder means any United States shareholder which would (determined without regard to this paragraph) take into account an amount greater than zero under section 951(a)(1) by reason of subsection (a). (C) E&P net deficit shareholder For purposes of this paragraph, the term E&P net deficit shareholder means any United States shareholder if— (i) the aggregate foreign E&P deficit with respect to such shareholder (as defined in paragraph (3)(A)), exceeds (ii) the amount which would (but for this subsection) be taken into account by such shareholder under section 951(a)(1) by reason of subsection (a). (D) Aggregate unused E&P deficit For purposes of this paragraph— (i) In general The term aggregate unused E&P deficit means, with respect to any affiliated group, the lesser of— (I) the sum of the excesses described in subparagraph (C), determined with respect to each E&P net deficit shareholder in such group, or (II) the amount determined under subparagraph (E)(ii). (ii) Reduction with respect to E&P net deficit shareholders which are not wholly owned by the affiliated group If the group ownership percentage of any E&P net deficit shareholder is less than 100 percent, the amount of the excess described in subparagraph (C) which is taken into account under clause (i)(I) with respect to such E&P net deficit shareholder shall be such group ownership percentage of such