Let $S \subset R$ be a subring. If $S \subset A_1 \cup...\cup A_n, A_i$ ideals and $n-2$ of which are prime, then $S$ belongs to one of $A_j$ 
Let $R$ be a commutative ring and $S$ a subring of $R$, i.e. a ring that may not contain the identity. Suppose that $S \subset A_1 \cup ... \cup A_n$ where $A_i$'s are ideals of $R$ and at least $n-2$ of which are prime ideals. Prove that $S$ is contained in one of the $A_i$'s.

I am totally lost on this one. I supposed on the contrary that there are $x, y \in S$ such that $x \in A_i$ but $y$ is not in $ A_i$, but am unsure how to go about from here. It seems that I might have to break it into two cases, one in which at least one of $x,y$ is in a prime ideal and the second in which neither $x$ or $y$ is in the prime ideal. Any help would be appreciated
 A: This is known as the prime avoidance lemma. I will restate it as the contrapositive: 

Let $J$ be an ideal of $R$, and $I_1, \dots, I_r$ ideals for which at least $r-2$ of which are prime. If $J \not\subset I_i$ for each $i$, then $J \not\subset \bigcup_{i=1}^r I_i$.

There is nothing to prove for $r=1$. For $r=2$, let $x, y \in J$ with $x \not\in I_1, y \not\in I_2$. If $x \not\in I_2$ or $y \not\in I_1$ we are done. Otherwise $x \in I_2, y \in I_1$, and then $x+y$ may not be in either of the ideals (why?).
For $r\geq 3$, by induction we may choose $x_i \in J \setminus \cup_{i \neq j} I_j$. If any of the $x_i$ are not in $I_i$ then we are done, so we suppose that $x_i \in I_i$. Without loss of generality let $I_r$ be prime, and consider
$$
y = x_1 \dots x_{r-1} + x_r.
$$
Then $y$ is in $J$ since it is an ideal. Now $y$ is not in $I_r$, or else $y - x_r = x_1 \dots x_{r-1} \in I_r$, so $x_i \in I_r$ for some $i < r$ by primeness. Also, $y$ is not in any of the $I_i$'s for $i < r$, or else
$$
x_r = y - x_1 \dots x_{r-1} \in I_i,
$$
another contradiction. So we win.

Remark 1. We only needed to know that $J$ was additively and multiplicatively closed, so we get the slightly stronger statement which you wanted.
Remark 2. We could have used the inductive argument for $r \geq 3$ with a slight modification to prove it all at once for $r \geq 2$. In particular, we cannot assume that $I_r$ is prime.

