  We present magic state factory constructions for producing $|CCZ\rangle$
states and $|T\rangle$ states. For the $|CCZ\rangle$ factory we apply the
surface code lattice surgery construction techniques described by Fowler et al.
to the fault-tolerant Toffoli. The resulting factory has a footprint of $12d
\times 6d$ (where $d$ is the code distance) and produces one $|CCZ\rangle$
every $5.5d$ surface code cycles. Our $|T\rangle$ state factory uses the
$|CCZ\rangle$ factory's output and a catalyst $|T\rangle$ state to exactly
transform one $|CCZ\rangle$ state into two $|T\rangle$ states. It has a
footprint 25% smaller than the factory of Fowler et al. but outputs $|T\rangle$
states twice as quickly. We show how to generalize the catalyzed transformation
to arbitrary phase angles, and note that the case $\theta=22.5^\circ$ produces
a particularly efficient circuit for producing $|\sqrt{T}\rangle$ states.
Compared to using the $12d \times 8d \times 6.5d$ $|T\rangle$ factory of Fowler
et al., our $|CCZ\rangle$ factory can quintuple the speed of algorithms that
are dominated by the cost of applying Toffoli gates, including Shor's algorithm
and the chemistry algorithm of Babbush et al.. Assuming a physical gate error
rate of $10^{-3}$, our CCZ factory can produce $\sim 10^{10}$ states on average
before an error occurs. This is sufficient for classically intractable
instantiations of the chemistry algorithm, but for more demanding algorithms
such as Shor's algorithm the mean number of states until failure can be
increased to $\sim 10^{12}$ by increasing the factory footprint ~20%.
