Solution (source code)

= Solution

Put $T=\sum_iX_i$. For interior parameters $0<\theta_0<\theta_1<1$, the alternative-to-null <likelihood ratio> is
$$
\frac{L(\theta_1)}{L(\theta_0)}
=\left(\frac{1-\theta_1}{1-\theta_0}\right)^n
\left(\frac{\theta_1(1-\theta_0)}{\theta_0(1-\theta_1)}\right)^T.
$$
The second base is greater than one, so this is strictly increasing in $T$. The <Neyman-Pearson lemma> therefore gives \b[an upper-tail rejection rule]. Under the <null hypothesis>, $T\sim\operatorname{Bin}(n,\theta_0)$, and an ordinary conservative threshold can be chosen as
$$
C=\{x:T(x)\geq c_\alpha\},\qquad
\Pr_{\theta_0}(T\geq c_\alpha)\leq\alpha.
$$
There is an important discrete qualification: an integer cutoff need not have <test size> exactly $\alpha$. To obtain exact size, choose an integer $b$ with $\Pr_0(T>b)\leq\alpha\leq\Pr_0(T\geq b)$, reject certainly when $T>b$, and at $T=b$ reject with probability
$$
\boxed{\gamma=\frac{\alpha-\Pr_0(T>b)}{\Pr_0(T=b)}.}
$$
This <randomized statistical test> is a <most powerful test> at exact size $\alpha$; when a binomial upper tail equals $\alpha$, no randomization is needed and the stated region is literal. Otherwise the unrandomized upper-tail region has size at most $\alpha$, and the exact-size result includes the boundary randomization. Endpoint parameter cases retain the same upper-tail ordering by taking limits, with ties resolved on the null-supported outcomes.