Navvye/Olympiad-Problems-CSV huggingface dataset:
Problem: Find the number of ordered pairs of integers $(a, b)$ such that the sequence \[3, 4, 5, a, b, 30, 40, 50\] is strictly increasing and no set of four (not necessarily consecutive) terms forms an arithmetic progression.

Solution: We will follow the solution from earlier in a rigorous manner to show that there are no other cases missing.
We recognize that an illegal sequence (defined as one that we subtract from our 231) can never have the numbers {3, 4} and {4,5} because we have not included a 6 in our count. Similarly, sequences with {30,40} and {40,50} will not give us any subtractions because those sequences must all include a 20. Let's stick with the lower ones for a minute: if we take them two at a time, then {3,5} will give us the subtraction of 1 sequence {3,5,7,9}. We have exhausted all pairs of numbers we can take, and if we take the triplet of single digit numbers, the only possible sequence must have a 6, which we already don't count. Therefore, we subtract $\textbf{1}$ from the count of illegal sequences with any of the single-digit numbers and none of the numbers 30,40,50.
(Note if we take only 1 at a time, there will have to be 3 of $a, b$ , which is impossible.)
If we have the sequence including {30,50}, we end up having negative values, so these do not give us any subtractions, and the triplet {30,40,50} gives us a 20. Hence by the same reasoning as earlier, we have 0 subtractions from the sequences with these numbers and none of the single digit numbers {3,4,5}.
Finally, we count the sequences that are something like (one of 3,4,5,), $a, b$ , (one of 30, 40, 50). If this is to be the case, then let $a$ be the starting value in the sequence. The sequence will be $a, a+d, a+2d, a+3d$ ; We see that if we subtract the largest term by the smallest term we have $3d$ , so the subtraction of one of (30,40,50) and one of (3,4,5) must be divisible by 3. Therefore the only sequences possible are $3,a,b,30; 4,a,b,40; 5,a,b,50$ . Of these, only the last is invalid because it gives $b = 35$ , larger than our bounds $6<a<b<30$ . Therefore, we subtract $\textbf{2}$ from this case.
Our final answer is $231 - 1 - 2 = \boxed{228}$

Answer:  228
Problem: Find the number of ordered pairs of integers $(a, b)$ such that the sequence \[3, 4, 5, a, b, 30, 40, 50\] is strictly increasing and no set of four (not necessarily consecutive) terms forms an arithmetic progression.

Solution: Denote $S = \left\{ (a, b) : 6 \leq a < b \leq 29 \right\}$
Denote by $A$ a subset of $S$ , such that there exists an arithmetic sequence that has 4 terms and includes $a$ but not $b$
Denote by $B$ a subset of $S$ , such that there exists an arithmetic sequence that has 4 terms and includes $b$ but not $a$
Hence, $C$ is a subset of $S$ , such that there exists an arithmetic sequence that has 4 terms and includes both $a$ and $b$
Hence, this problem asks us to compute \[ | S | - \left( | A | + | B | + | C | \right) . \]
First, we compute $| S |$
We have $| S | = \binom{29 - 6 + 1}{2} = \binom{24}{2} = 276$
Second, we compute $| A |$
$\textbf{Case 1}$ $a = 6$
We have $b = 8 , \cdots , 19, 21, 22, \cdots, 29$ .
Thus, the number of solutions is 22.
$\textbf{Case 2}$ $a = 20$
We have $b = 21, 22, \cdots , 29$ .
Thus, the number of solutions is 9.
Thus, $| A | = 22 + 9 = 31$
Third, we compute $| B |$
In $B$ , we have $b = 6, 20$ . However, because $6 \leq a < b$ , we have $b \geq 7$ .
Thus, $b = 20$
This implies $a = 7, 8, 9, 11, 12, \cdots , 19$ . Note that $(a, b)=(10, 20)$ belongs in $C$
Thus, $| B | = 12$
Fourth, we compute $| C |$
$\textbf{Case 1}$ : In the arithmetic sequence, the two numbers beyond $a$ and $b$ are on the same side of $a$ and $b$
Hence, $(a, b) = (6 , 7), (7, 9) , (10, 20)$ .
Therefore, the number solutions in this case is 3.
$\textbf{Case 2}$ : In the arithmetic sequence, the two numbers beyond $a$ and $b$ are on the opposite sides of $a$ and $b$
$\textbf{Case 2.1}$ : The arithmetic sequence is $3, a, b, 30$
Hence, $(a, b) = (12, 21)$
$\textbf{Case 2.2}$ : The arithmetic sequence is $4, a, b, 40$
Hence, $(a, b) = (16, 28)$
$\textbf{Case 2.3}$ : The arithmetic sequence is $5, a, b, 50$
Hence, $(a, b) = (20, 35)$ . However, the sequence $... 20, 35, 30, 40, 50$ is not strictly increasing.
Putting two cases together, $| C | = 65.$
Therefore, \[| S | - \left( | A | + | B | + | C | \right) = 276 - \left( 31 + 12 + 5 \right) = \boxed{228}.\]

Answer:  228
Problem: Find the number of ordered pairs of integers $(a, b)$ such that the sequence \[3, 4, 5, a, b, 30, 40, 50\] is strictly increasing and no set of four (not necessarily consecutive) terms forms an arithmetic progression.

Solution: divide cases into $7\leq a<20; 21\leq a\leq28$ .(Notice that $a$ can't be equal to $6,20$ , that's why I divide them into two parts.
There are three cases that arithmetic sequence forms: $3,12,21,30;4,16,28,40;3,5,7,9$ .(NOTICE that $5,20,35,50$ IS NOT A VALID SEQUENCE!)
So when $7\leq a<20$ , there are $10+11+12+...+22-3-13=192$ possible ways( 3 means the arithmetic sequence and 13 means there are 13 "a" s and b cannot be 20)
When $21\leq a \leq 28$ , there are $1+2+\cdots+8=36$ ways.
In all, there are $192+36=\boxed{228}$ possible sequences.

Answer:  228
Problem: Let $a,b,c,d,e,f,g,h,i$ be distinct integers from $1$ to $9.$ The minimum possible positive value of \[\dfrac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i}\] can be written as $\frac{m}{n},$ where $m$ and $n$ are relatively prime positive integers. Find $m+n.$

Solution: To minimize a positive fraction, we minimize its numerator and maximize its denominator. It is clear that $\frac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i} \geq \frac{1}{7\cdot8\cdot9}.$
If we minimize the numerator, then $a \cdot b \cdot c - d \cdot e \cdot f = 1.$ Note that $a \cdot b \cdot c \cdot d \cdot e \cdot f = (a \cdot b \cdot c) \cdot (a \cdot b \cdot c - 1) \geq 6! = 720,$ so $a \cdot b \cdot c \geq 28.$ It follows that $a \cdot b \cdot c$ and $d \cdot e \cdot f$ are consecutive composites with prime factors no other than $2,3,5,$ and $7.$ The smallest values for $a \cdot b \cdot c$ and $d \cdot e \cdot f$ are $36$ and $35,$ respectively. So, we have $\{a,b,c\} = \{2,3,6\}, \{d,e,f\} = \{1,5,7\},$ and $\{g,h,i\} = \{4,8,9\},$ from which $\frac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i} = \frac{1}{288}.$
If we do not minimize the numerator, then $a \cdot b \cdot c - d \cdot e \cdot f > 1.$ Note that $\frac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i} \geq \frac{2}{7\cdot8\cdot9} > \frac{1}{288}.$
Together, we conclude that the minimum possible positive value of $\frac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i}$ is $\frac{1}{288}.$ Therefore, the answer is $1+288=\boxed{289}.$

Answer:  289
Problem: Let $a,b,c,d,e,f,g,h,i$ be distinct integers from $1$ to $9.$ The minimum possible positive value of \[\dfrac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i}\] can be written as $\frac{m}{n},$ where $m$ and $n$ are relatively prime positive integers. Find $m+n.$

Solution: Obviously, to find the correct answer, we need to get the largest denominator with the smallest numerator.
To bash efficiently, we can start out with $7\cdot8\cdot9$ as our denominator. This, however, leaves us with the numbers $1, 2, 3, 4, 5,$ and $6$ left. The smallest we can make out of this is $1\cdot5\cdot6 - 2\cdot3\cdot4 = 30 - 24 = 6$ . When simplified, it gives us $\frac{1}{84}$ , which gives a small answer of $85$ . Obviously there are larger answers than this.
After the first bash, we learn to bash even more efficiently, we can consider both the numerator and the denominator when guessing. We know the numerator has to be extremely small while still having a large denominator. When bashing, we soon find out the couple $(a,b,c)=(2,3,6)$ and $(d,e,f)=(1,5,7)$
This gives us a numerator of $36-35=1$ , which is by far the smallest yet. With the remaining numbers $4, 8,$ and $9$ , we get $\frac{36-35}{4\cdot8\cdot9}=\frac{1}{288}$
Finally, we add up our numerator and denominator: The answer is $1+288=\boxed{289}$

Answer:  289
Problem: Let $a,b,c,d,e,f,g,h,i$ be distinct integers from $1$ to $9.$ The minimum possible positive value of \[\dfrac{a \cdot b \cdot c - d \cdot e \cdot f}{g \cdot h \cdot i}\] can be written as $\frac{m}{n},$ where $m$ and $n$ are relatively prime positive integers. Find $m+n.$

Solution: To minimize the numerator, we must have $abc - def = 1$ . Thus, one of these products must be odd and the other must be even. The odd product must consist of only odd numbers. The smallest such value $(d, e, f) = (1, 3, 5)$ cannot result in a difference of $1$ , and the next smallest product, $(d, e, f) = (1, 3, 7)$ cannot either, but $(d, e, f) = (1, 5, 7)$ can if $(a, b, c) = (2, 3, 6)$ . Thus, the denominator must be $(g, h, i) = (4, 8, 9)$ , and the smallest fraction possible is $\dfrac{36 - 35}{288} = \dfrac{1}{288}$ , making the answer $1 + 288 = \boxed{289}$

Answer:  289
Problem: Equilateral triangle $\triangle ABC$ is inscribed in circle $\omega$ with radius $18.$ Circle $\omega_A$ is tangent to sides $\overline{AB}$ and $\overline{AC}$ and is internally tangent to $\omega.$ Circles $\omega_B$ and $\omega_C$ are defined analogously. Circles $\omega_A,$ $\omega_B,$ and $\omega_C$ meet in six points---two points for each pair of circles. The three intersection points closest to the vertices of $\triangle ABC$ are the vertices of a large equilateral triangle in the interior of $\triangle ABC,$ and the other three intersection points are the vertices of a smaller equilateral triangle in the interior of $\triangle ABC.$ The side length of the smaller equilateral triangle can be written as $\sqrt{a} - \sqrt{b},$ where $a$ and $b$ are positive integers. Find $a+b.$

Solution: Let $O$ be the center, $R = 18$ be the radius, and $CC'$ be the diameter of $\omega.$ Let $r$ be the radius, $E,D,F$ are the centers of $\omega_A, \omega_B,\omega_C.$ Let $KGH$ be the desired triangle with side $x.$ We find $r$ using \[CC' = 2R = C'K + KC = r + \frac{r}{\sin 30^\circ} = 3r.\] \[r = \frac{2R}{3} = 12.\] \[OE = R – r = 6.\] Triangles $\triangle DEF$ and $\triangle KGH$ – are equilateral triangles with a common center $O,$ therefore in the triangle $OEH$ $OE = 6, \angle EOH = 120^\circ, OH = \frac{x}{\sqrt3}.$
We apply the Law of Cosines to $\triangle OEH$ and get \[OE^2 + OH^2 + OE \cdot OH = EH^2.\] \[6^2 + \frac{x^2}{3} + \frac{6x}{\sqrt3} = 12^2.\] \[x^2 + 6x \sqrt{3} = 324\] \[x= \sqrt{351} - \sqrt{27}  \implies 351 + 27 = \boxed{378}\]

Answer:  378
Problem: Equilateral triangle $\triangle ABC$ is inscribed in circle $\omega$ with radius $18.$ Circle $\omega_A$ is tangent to sides $\overline{AB}$ and $\overline{AC}$ and is internally tangent to $\omega.$ Circles $\omega_B$ and $\omega_C$ are defined analogously. Circles $\omega_A,$ $\omega_B,$ and $\omega_C$ meet in six points---two points for each pair of circles. The three intersection points closest to the vertices of $\triangle ABC$ are the vertices of a large equilateral triangle in the interior of $\triangle ABC,$ and the other three intersection points are the vertices of a smaller equilateral triangle in the interior of $\triangle ABC.$ The side length of the smaller equilateral triangle can be written as $\sqrt{a} - \sqrt{b},$ where $a$ and $b$ are positive integers. Find $a+b.$

Solution: Let $O$ be the center of $\omega$ $X$ be the intersection of $\omega_B,\omega_C$ further from $A$ , and $O_A$ be the center of $\omega_A$ . Define $Y, Z, O_B, O_C$ similarly. It is well-known that the $A$ -mixtilinear inradius $R_A$ is $\tfrac{r}{\cos^2\left(\frac{\angle A}{2}\right)} = \tfrac{9}{\cos^2\left(30^{\circ}\right)} = 12$ , so in particular this means that $OO_B = 18 -  R_B = 6 = OO_C$ . Since $\angle O_BOO_C = \angle BOC = 120^\circ$ , it follows by Law of Cosines on $\triangle OO_BO_C$ that $O_BO_C = 6\sqrt{3}$ . Then the Pythagorean theorem gives that the altitude of $O_BO_CX$ is $\sqrt{117}$ , so $OY = OX = \text{dist}(X, YZ) - \text{dist}(O, YZ) = \sqrt{117} - 3$ and $YZ = \tfrac{O_BO_C\cdot OY}{OO_B} = \tfrac{6\sqrt{3}(\sqrt{117} - 3)}{6}=\sqrt{351} - \sqrt{27}$ so the answer is $351 + 27 = \boxed{378}$

Answer:  378
Problem: Ellina has twelve blocks, two each of red ( $\textbf{R}$ ), blue ( $\textbf{B}$ ), yellow ( $\textbf{Y}$ ), green ( $\textbf{G}$ ), orange ( $\textbf{O}$ ), and purple ( $\textbf{P}$ ). Call an arrangement of blocks $\textit{even}$ if there is an even number of blocks between each pair of blocks of the same color. For example, the arrangement \[\textbf{R B B Y G G Y R O P P O}\] is even. Ellina arranges her blocks in a row in random order. The probability that her arrangement is even is $\frac{m}{n},$ where $m$ and $n$ are relatively prime positive integers. Find $m+n.$

Solution: Consider this position chart: \[\textbf{1 2 3 4 5 6 7 8 9 10 11 12}\] Since there has to be an even number of spaces between each pair of the same color, spots $1$ $3$ $5$ $7$ $9$ , and $11$ contain some permutation of all $6$ colored balls. Likewise, so do the even spots, so the number of even configurations is $6! \cdot 6!$ (after putting every pair of colored balls in opposite parity positions, the configuration can be shown to be even). This is out of $\frac{12!}{(2!)^6}$ possible arrangements, so the probability is: \[\frac{6!\cdot6!}{\frac{12!}{(2!)^6}} = \frac{6!\cdot2^6}{7\cdot8\cdot9\cdot10\cdot11\cdot12} = \frac{2^4}{7\cdot11\cdot3} = \frac{16}{231},\] which is in simplest form. So, $m + n = 16 + 231 = \boxed{247}$

Answer:  247
Problem: Ellina has twelve blocks, two each of red ( $\textbf{R}$ ), blue ( $\textbf{B}$ ), yellow ( $\textbf{Y}$ ), green ( $\textbf{G}$ ), orange ( $\textbf{O}$ ), and purple ( $\textbf{P}$ ). Call an arrangement of blocks $\textit{even}$ if there is an even number of blocks between each pair of blocks of the same color. For example, the arrangement \[\textbf{R B B Y G G Y R O P P O}\] is even. Ellina arranges her blocks in a row in random order. The probability that her arrangement is even is $\frac{m}{n},$ where $m$ and $n$ are relatively prime positive integers. Find $m+n.$

Solution: We can simply use constructive counting. First, let us place the red blocks; choose the first slot in $12$ ways, and the second in $6$ ways, because the number is cut in half due to the condition in the problem. This gives $12 \cdot 6$ ways to place the red blocks. Similarly, there are $10 \cdot 5$ ways to place the blue blocks, and so on, until there are $2 \cdot 1$ ways to place the purple blocks. Thus, the probability is \[\frac{12 \cdot 6 \cdot 10 \cdot 5 \cdot 8 \cdot 4 \cdot 6 \cdot 3 \cdot 4 \cdot 2 \cdot 2 \cdot 1}{12!}=\frac{16}{231},\] and the desired answer is $16+231=\boxed{247}$

Answer:  247
Problem: Three spheres with radii $11$ $13$ , and $19$ are mutually externally tangent. A plane intersects the spheres in three congruent circles centered at $A$ $B$ , and $C$ , respectively, and the centers of the spheres all lie on the same side of this plane. Suppose that $AB^2 = 560$ . Find $AC^2$

Solution: Let the distance between the center of the sphere to the center of those circular intersections as $a,b,c$ separately.
According to the problem, we have $a^2-11^2=b^2-13^2=c^2-19^2; (11+13)^2-(b-a)^2=560.$ After solving we have $b-a=4,$ plug this back to $11^2-a^2=13^2-b^2,$ we have $a=4, b=8,$ and $c=16.$
The desired value is $(11+19)^2-(16-4)^2=\boxed{756}.$

Answer:  756
Problem: Three spheres with radii $11$ $13$ , and $19$ are mutually externally tangent. A plane intersects the spheres in three congruent circles centered at $A$ $B$ , and $C$ , respectively, and the centers of the spheres all lie on the same side of this plane. Suppose that $AB^2 = 560$ . Find $AC^2$

Solution: Denote by $r$ the radius of three congruent circles formed by the cutting plane.
Denote by $O_A$ $O_B$ $O_C$ the centers of three spheres that intersect the plane to get circles centered at $A$ $B$ $C$ , respectively.
Because three spheres are mutually tangent, $O_A O_B = 11 + 13 = 24$ $O_A O_C = 11 + 19 = 30$
We have $O_A A^2 = 11^2 - r^2$ $O_B B^2 = 13^2 - r^2$ $O_C C^2 = 19^2 - r^2$
Because $O_A A$ and $O_B B$ are perpendicular to the plane, $O_A AB O_B$ is a right trapezoid, with $\angle O_A A B = \angle O_B BA = 90^\circ$
Hence, \begin{align*} O_B B - O_A A & = \sqrt{O_A O_B^2 - AB^2} \\ & = 4 . \hspace{1cm} (1) \end{align*}
Recall that \begin{align*} O_B B^2 - O_A A^2 & = \left( 13^2 - r^2 \right) - \left( 11^2 - r^2 \right) \\ & = 48 . \hspace{1cm} (2) \end{align*}
Hence, taking $\frac{(2)}{(1)}$ , we get \[ O_B B + O_A A = 12 . \hspace{1cm} (3) \]
Solving (1) and (3), we get $O_B B = 8$ and $O_A A = 4$
Thus, $r^2 = 11^2 - O_A A^2 = 105$
Thus, $O_C C = \sqrt{19^2 - r^2} = 16$
Because $O_A A$ and $O_C C$ are perpendicular to the plane, $O_A AC O_C$ is a right trapezoid, with $\angle O_A A C = \angle O_C CA = 90^\circ$
Therefore, \begin{align*} AC^2 & = O_A O_C^2 - \left( O_C C - O_A A \right)^2 \\ & = \boxed{756}

Answer:  756
Problem: For any finite set $X$ , let $| X |$ denote the number of elements in $X$ . Define \[S_n = \sum | A \cap B | ,\] where the sum is taken over all ordered pairs $(A, B)$ such that $A$ and $B$ are subsets of $\left\{ 1 , 2 , 3,  \cdots , n \right\}$ with $|A| = |B|$ .
For example, $S_2 = 4$ because the sum is taken over the pairs of subsets \[(A, B) \in \left\{ (\emptyset, \emptyset) , ( \{1\} , \{1\} ), ( \{1\} , \{2\} ) , ( \{2\} , \{1\} ) , ( \{2\} , \{2\} ) , ( \{1 , 2\} , \{1 , 2\} ) \right\} ,\] giving $S_2 = 0 + 1 + 0 + 0 + 1 + 2 = 4$ .
Let $\frac{S_{2022}}{S_{2021}} = \frac{p}{q}$ , where $p$ and $q$ are relatively prime positive integers. Find the remainder when $p + q$ is divided by
1000.

Solution: We take cases based on the number of values in each of the subsets in the pair. Suppose we have $k$ elements in each of the subsets in a pair (for a total of n elements in the set). The expected number of elements in any random pair will be $n \cdot \frac{k}{n} \cdot \frac{k}{n}$ by linearity of expectation because for each of the $n$ elements, there is a $\frac{k}{n}$ probability that the element will be chosen. To find the sum over all such values, we multiply this quantity by $\binom{n}{k}^2$ . Summing, we get \[\sum_{k=1}^{n} \frac{k^2}{n} \binom{n}{k}^2\] Notice that we can rewrite this as \[\sum_{k=1}^{n} \frac{1}{n} \left(\frac{k \cdot n!}{(k)!(n - k)!}\right)^2 = \sum_{k=1}^{n} \frac{1}{n} n^2 \left(\frac{(n-1)!}{(k - 1)!(n - k)!}\right)^2 = n \sum_{k=1}^{n} \binom{n - 1}{k - 1}^2 = n \sum_{k=1}^{n} \binom{n - 1}{k - 1}\binom{n - 1}{n - k}\] We can simplify this using Vandermonde's identity to get $n \binom{2n - 2}{n - 1}$ . Evaluating this for $2022$ and $2021$ gives \[\frac{2022\binom{4042}{2021}}{2021\binom{4040}{2020}} = \frac{2022 \cdot 4042 \cdot 4041}{2021^3} = \frac{2022 \cdot 2 \cdot 4041}{2021^2}\] Evaluating the numerators and denominators mod $1000$ gives $804 + 441 = 1\boxed{245}$

Answer:  245
Problem: For any finite set $X$ , let $| X |$ denote the number of elements in $X$ . Define \[S_n = \sum | A \cap B | ,\] where the sum is taken over all ordered pairs $(A, B)$ such that $A$ and $B$ are subsets of $\left\{ 1 , 2 , 3,  \cdots , n \right\}$ with $|A| = |B|$ .
For example, $S_2 = 4$ because the sum is taken over the pairs of subsets \[(A, B) \in \left\{ (\emptyset, \emptyset) , ( \{1\} , \{1\} ), ( \{1\} , \{2\} ) , ( \{2\} , \{1\} ) , ( \{2\} , \{2\} ) , ( \{1 , 2\} , \{1 , 2\} ) \right\} ,\] giving $S_2 = 0 + 1 + 0 + 0 + 1 + 2 = 4$ .
Let $\frac{S_{2022}}{S_{2021}} = \frac{p}{q}$ , where $p$ and $q$ are relatively prime positive integers. Find the remainder when $p + q$ is divided by
1000.

Solution: For each element $i$ , denote $x_i = \left( x_{i, A}, x_{i, B} \right) \in \left\{ 0 , 1 \right\}^2$ , where $x_{i, A} = \Bbb I \left\{ i \in A \right\}$ (resp. $x_{i, B} = \Bbb I \left\{ i \in B \right\}$ ).
Denote $\Omega = \left\{ (x_1, \cdots , x_n): \sum_{i = 1}^n x_{i, A} = \sum_{i = 1}^n x_{i, B} \right\}$
Denote $\Omega_{-j} = \left\{ (x_1, \cdots , x_{j-1} , x_{j+1} , \cdots , x_n): \sum_{i \neq j} x_{i, A} = \sum_{i \neq j} x_{i, B} \right\}$
Hence, \begin{align*} S_n & = \sum_{(x_1, \cdots , x_n) \in \Omega} \sum_{i = 1}^n \Bbb I \left\{ x_{i, A} = x_{i, B} = 1 \right\} \\ & = \sum_{i = 1}^n \sum_{(x_1, \cdots , x_n) \in \Omega} \Bbb I \left\{ x_{i, A} = x_{i, B} = 1 \right\} \\ & = \sum_{i = 1}^n \sum_{(x_1, \cdots , x_{i-1} , x_{i+1} , \cdots , x_n) \in \Omega_{-i}} 1  \\ & = \sum_{i = 1}^n \sum_{j=0}^{n-1} \left( \binom{n-1}{j} \right)^2 \\ & = n \sum_{j=0}^{n-1} \left( \binom{n-1}{j} \right)^2 \\ & = n \sum_{j=0}^{n-1} \binom{n-1}{j} \binom{n-1}{n-1-j} \\ & = n \binom{2n-2}{n-1} . \end{align*}
Therefore, \begin{align*} \frac{S_{2022}}{S_{2021}} & = \frac{2022 \binom{4042}{2021}}{2021 \binom{4040}{2020}} \\ & = \frac{4044 \cdot 4041}{2021^2} . \end{align*}
This is in the lowest term.
Therefore, modulo 1000, \begin{align*} p + q  & \equiv 4044 \cdot 4041 + 2021^2 \\ & \equiv 44 \cdot 41 + 21^2 \\ & \equiv \boxed{245}

Answer:  245
Problem: Given $\triangle ABC$ and a point $P$ on one of its sides, call line $\ell$ the $\textit{splitting line}$ of $\triangle ABC$ through $P$ if $\ell$ passes through $P$ and divides $\triangle ABC$ into two polygons of equal perimeter. Let $\triangle ABC$ be a triangle where $BC = 219$ and $AB$ and $AC$ are positive integers. Let $M$ and $N$ be the midpoints of $\overline{AB}$ and $\overline{AC},$ respectively, and suppose that the splitting lines of $\triangle ABC$ through $M$ and $N$ intersect at $30^\circ.$ Find the perimeter of $\triangle ABC.$

Solution: We now need to solve $a^2+ab+b^2 = 3^2\cdot 73^2$ . A quick $(\bmod 9)$ check gives that $3\mid a$ and $3\mid b$ . Thus, it's equivalent to solve $x^2+xy+y^2 = 73^2$
Let $\omega$ be one root of $\omega^2+\omega+1=0$ . Then, recall that $\mathbb Z[\omega]$ is the ring of integers of $\mathbb Q[\sqrt{-3}]$ and is a unique factorization domain. Notice that $N(x-y\omega) = (x-y\omega)(x-y\omega^2) = x^2+xy+y^2$ . Therefore, it suffices to find an element of $\mathbb Z[\omega]$ with the norm $73^2$
To do so, we factor $73$ in $\mathbb Z[\omega]$ . Since it's $1\pmod 3$ , it must split. A quick inspection gives $73 = (8-\omega)(8-\omega^2)$ . Thus, $N(8-\omega) = 73$ , so \begin{align*} 73^2 &= N((8-\omega)^2) \\ &= N(64 - 16\omega + \omega^2) \\ &= N(64 - 16\omega + (-1-\omega)) \\ &= N(63 - 17\omega), \end{align*} giving the solution $x=63$ and $y=17$ , yielding $a=189$ and $b=51$ , so the sum is $\boxed{459}$ . Since $8-\omega$ and $8-\omega^2$ are primes in $\mathbb Z[\omega]$ , the solution must divide $73^2$ . One can then easily check that this is the unique solution.

Answer:  459
Problem: Given $\triangle ABC$ and a point $P$ on one of its sides, call line $\ell$ the $\textit{splitting line}$ of $\triangle ABC$ through $P$ if $\ell$ passes through $P$ and divides $\triangle ABC$ into two polygons of equal perimeter. Let $\triangle ABC$ be a triangle where $BC = 219$ and $AB$ and $AC$ are positive integers. Let $M$ and $N$ be the midpoints of $\overline{AB}$ and $\overline{AC},$ respectively, and suppose that the splitting lines of $\triangle ABC$ through $M$ and $N$ intersect at $30^\circ.$ Find the perimeter of $\triangle ABC.$

Solution: We wish to solve the Diophantine equation $a^2+ab+b^2=3^2 \cdot 73^2$ . It can be shown that $3|a$ and $3|b$ , so we make the substitution $a=3x$ and $b=3y$ to obtain $x^2+xy+y^2=73^2$ as our new equation to solve for.
Notice that $r^2+r+1=(r-\omega)(r-{\omega}^2)$ , where $\omega=e^{i\frac{2\pi}{3}}$ . Thus, \[x^2+xy+y^2 = y^2((x/y)^2+(x/y)+1) = y^2 (\frac{x}{y}-\omega)(\frac{x}{y}-{\omega}^2) = (x-y\omega)(x-y{\omega}^2).\]
Note that $8^2+1^2+8 \cdot 1=73$ . Thus, $(8-\omega)(8-{\omega}^2)=73$ . Squaring both sides yields \begin{align} (8-\omega)^2(8-{\omega}^2)^2&=73^2\\ (63-17\omega)(63-17{\omega}^2)&=73^2. \end{align} Thus, by $(2)$ $(63, 17)$ is a solution to $x^2+xy+y^2=73^2$ . This implies that $a=189$ and $b=51$ , so our final answer is $189+51+219=\boxed{459}$

Answer:  459