[step:Apply Selberg's upper-bound sieve to the twin-prime residue system]Define the multiplicative function $\omega:\mathbb{N}\to\mathbb{N}\cup\{0\}$ on prime powers by $\omega(q^k)=\omega(q)$ for every prime $q$ and every $k\geq 1$, with
\begin{align*}
\omega(2) := 1
\end{align*}
and, for each odd prime $q$,
\begin{align*}
\omega(q) := 2.
\end{align*}
For every squarefree divisor $d$ of $P(z)$, the value $\omega(d)$ is the number of residue classes modulo $d$ on which $d \mid n(n+2)$.
We use the following Selberg upper-bound sieve estimate.
[claim:Selberg sieve estimate for the twin-prime residue system]
There are absolute constants $C_0,C_1 > 0$ such that, for all $x \geq 16$ and all $2 \leq z \leq x^{1/2}$,
\begin{align*}
S(x,z) \leq C_0 x \frac{(\log\log z)^2}{(\log z)^2} + C_1 z^2(\log z)^6.
\end{align*}
[/claim]
[proof]
For squarefree $d \mid P(z)$, define $A_d:[16,\infty)\to\mathbb{N}\cup\{0\}$ by letting $A_d(x)$ be the number of integers $n \in \{1,\dots,\lfloor x \rfloor\}$ such that $d \mid n(n+2)$. By the [Chinese remainder theorem](/theorems/734), the congruence $d \mid n(n+2)$ is the union of exactly $\omega(d)$ residue classes modulo $d$. Hence there is a remainder function $R_d:[16,\infty)\to\mathbb{R}$ such that
\begin{align*}
A_d(x) = \frac{\omega(d)}{d}x + R_d(x), \qquad |R_d(x)| \leq \omega(d).
\end{align*}
We invoke Selberg's upper-bound sieve in dimension two for the residue system $n(n+2)$. In the form used here, it states that if $2\leq z\leq x^{1/2}$, $\omega(2)=1$, $\omega(q)=2$ for odd primes $q$, and the local counting functions satisfy the remainder estimate above, then there are Selberg weights $\lambda_d\in\mathbb{R}$ supported on squarefree $d\mid P(z)$ with $d\leq z$ and $\lambda_1=1$ such that
\begin{align*}
S(x,z) \leq \frac{x}{G(z)} + C_2 z^2(\log z)^6,
\end{align*}
where $C_2>0$ is an absolute constant and $G:[2,\infty)\to(0,\infty)$ is the Selberg denominator
\begin{align*}
G(z) := \sum_{\substack{r \mid P(z), r \leq z}} \mu(r)^2 \prod_{q \mid r}\frac{\omega(q)}{q-\omega(q)}.
\end{align*}
Here $\mu:\mathbb{N}\to\{-1,0,1\}$ is the Mobius function, so $\mu(r)^2$ is the indicator that $r$ is squarefree. The same sieve theorem includes the dimension-two denominator estimate
\begin{align*}
G(z) \geq c_2 \frac{(\log z)^2}{(\log\log z)^2}
\end{align*}
for every $z\geq3$, with an absolute constant $c_2>0$. This denominator estimate is the standard truncated Euler-product estimate for the weights $2/(q-2)$; its hypotheses are exactly the displayed values of $\omega(q)$ and the restriction to squarefree divisors of $P(z)$.
Combining the two displayed estimates gives
\begin{align*}
S(x,z) \leq c_2^{-1}x\frac{(\log\log z)^2}{(\log z)^2} + C_2 z^2(\log z)^6.
\end{align*}
Renaming the absolute constants proves the asserted estimate.
[/proof]
Since $z=x^{1/4}$ and $x \geq 16$, the hypotheses $2 \leq z \leq x^{1/2}$ hold. Therefore
\begin{align*}
S(x,z) \leq C_0 x \frac{(\log\log z)^2}{(\log z)^2} + C_1 z^2(\log z)^6.
\end{align*}[/step]