problem: Let $a, b, c$ be fixed positive integers. There are $a+b+c$ ducks sitting in a circle, one behind the other. Each duck picks either rock, paper, or scissors, with $a$ ducks picking rock, $b$ ducks picking paper, and $c$ ducks picking scissors.  A move consists of an operation of one of the following three forms:  - If a duck picking rock sits behind a duck picking scissors, they switch places. - If a duck picking paper sits behind a duck picking rock, they switch places. - If a duck picking scissors sits behind a duck picking paper, they switch places.  Determine, in terms of $a, b$, and $c$, the maximum number of moves which could take place, over all possible initial configurations.

solution: The maximum possible number of moves is $\max (a b, a c, b c)$. First, we prove this is best possible. We define a feisty triplet to be an unordered triple of ducks, one of each of rock, paper, scissors, such that the paper duck is between the rock and scissors duck and facing the rock duck, as shown. (There may be other ducks not pictured, but the orders are irrelevant.) ![](https://cdn.mathpix.com/cropped/2024_11_19_a8f70a0d08e0809deba0g-04.jpg?height=1100&width=1098&top_left_y=1500&top_left_x=479)  Claim - The number of feisty triplets decreases by $c$ if a paper duck swaps places with a rock duck, and so on.   Obviously the number of feisty triples is at most $a b c$ to start. Thus at most $\max (a b, b c, c a)$ moves may occur, since the number of feisty triplets should always be nonnegative, at which point no moves are possible at all.  To see that this many moves is possible, assume WLOG $a=\min (a, b, c)$ and suppose we have $a$ rocks, $b$ papers, and $c$ scissors in that clockwise order. ![](https://cdn.mathpix.com/cropped/2024_11_19_a8f70a0d08e0809deba0g-05.jpg?height=1109&width=1052&top_left_y=750&top_left_x=505)  Then, allow the scissors to filter through the papers while the rocks stay put. Each of the $b$ papers swaps with $c$ scissors, for a total of $b c=\max (a b, a c, b c)$ swaps.  Remark (Common errors). One small possible mistake: it is not quite kösher to say that "WLOG $a \leq b \leq c$ " because the condition is not symmetric, only cyclic. Therefore in this solution we only assume $a=\min (a, b, c)$.  It is true here that every pair of ducks swaps at most once, and some solutions make use of this fact. However, this fact implicitly uses the fact that $a, b, c>0$ and is false without this hypothesis.


problem: Let $A B C$ be a scalene triangle with incenter $I$. The incircle of $A B C$ touches $\overline{B C}$, $\overline{C A}, \overline{A B}$ at points $D, E, F$, respectively. Let $P$ be the foot of the altitude from $D$ to $\overline{E F}$, and let $M$ be the midpoint of $\overline{B C}$. The rays $A P$ and $I P$ intersect the circumcircle of triangle $A B C$ again at points $G$ and $Q$, respectively. Show that the incenter of triangle $G Q M$ coincides with $D$.

solution: Refer to the figure below. ![](https://cdn.mathpix.com/cropped/2024_11_19_a8f70a0d08e0809deba0g-06.jpg?height=798&width=803&top_left_y=906&top_left_x=632)  Claim - The point $Q$ is the Miquel point of $B F E C$. Also, $\overline{Q D}$ bisects $\angle B Q C$.  The spiral similarity mentioned then gives $\frac{Q B}{B F}=\frac{Q C}{C E}$, so $\overline{Q D}$ bisects $\angle B Q C$. Remark. The point $Q$ and its properties mentioned in the first claim have appeared in other references. See for example Canada 2007/5, ELMO 2010/6, HMMT 2016 T-10, USA TST 2017/2, USA TST 2019/6 for a few examples.  Claim - We have $(Q G ; B C)=-1$, so in particular $\overline{G D}$ bisects $\angle B G C$.  $$ -1=(A I ; E F) \stackrel{Q}{=}(\overline{A Q} \cap \overline{E F}, P ; E, F) \stackrel{A}{=}(Q G ; B C) $$  The last statement follows from Apollonian circle, or more bluntly $\frac{G B}{G C}=\frac{Q B}{Q C}=\frac{B D}{D C}$. Hence $\overline{Q D}$ and $\overline{G D}$ are angle bisectors of $\angle B Q C$ and $\angle B G C$. However, $\overline{Q M}$ and $\overline{Q G}$ are isogonal in $\angle B Q C$ (as median and symmedian), and similarly for $\angle B G C$, as desired.


problem: We say a nondegenerate triangle whose angles have measures $\theta_{1}, \theta_{2}, \theta_{3}$ is quirky if there exists integers $r_{1}, r_{2}, r_{3}$, not all zero, such that  $$ r_{1} \theta_{1}+r_{2} \theta_{2}+r_{3} \theta_{3}=0 $$  Find all integers $n \geq 3$ for which a triangle with side lengths $n-1, n, n+1$ is quirky.

solution: The answer is $n=3,4,5,7$. We first introduce a variant of the $k$ th Chebyshev polynomials in the following lemma (which is standard, and easily shown by induction).  ## Lemma  For each $k \geq 0$ there exists $P_{k}(X) \in \mathbb{Z}[X]$, monic for $k \geq 1$ and with degree $k$, such that  $$ P_{k}\left(X+X^{-1}\right) \equiv X^{k}+X^{-k} . $$  The first few are $P_{0}(X) \equiv 2, P_{1}(X) \equiv X, P_{2}(X) \equiv X^{2}-2, P_{3}(X) \equiv X^{3}-3 X$. Suppose the angles of the triangle are $\alpha<\beta<\gamma$, so the law of cosines implies that  $$ 2 \cos \alpha=\frac{n+4}{n+1} \quad \text { and } \quad 2 \cos \gamma=\frac{n-4}{n-1} $$  Claim - The triangle is quirky iff there exists $r, s \in \mathbb{Z}_{\geq 0}$ not both zero such that  $$ \cos (r \alpha)= \pm \cos (s \gamma) \quad \text { or equivalently } \quad P_{r}\left(\frac{n+4}{n+1}\right)= \pm P_{s}\left(\frac{n-4}{n-1}\right) $$   If $r=0$, then by rational root theorem on $P_{s}(X) \pm 2$ it follows $\frac{n-4}{n-1}$ must be an integer which occurs only when $n=4$ (recall $n \geq 3$ ). Similarly we may discard the case $s=0$.  Thus in what follows assume $n \neq 4$ and $r, s>0$. Then, from the fact that $P_{r}$ and $P_{s}$ are nonconstant monic polynomials, we find  ## Corollary  If $n \neq 4$ works, then when $\frac{n+4}{n+1}$ and $\frac{n-4}{n-1}$ are written as fractions in lowest terms, the denominators have the same set of prime factors.  But $\operatorname{gcd}(n+1, n-1)$ divides 2 , and $\operatorname{gcd}(n+4, n+1), \operatorname{gcd}(n-4, n-1)$ divide 3 . So we only have three possibilities:  - $n+1=2^{u}$ and $n-1=2^{v}$ for some $u, v \geq 0$. This is only possible if $n=3$. Here $2 \cos \alpha=\frac{7}{4}$ and $2 \cos \gamma=-\frac{1}{2}$, and indeed $P_{2}(-1 / 2)=-7 / 4$. - $n+1=3 \cdot 2^{u}$ and $n-1=2^{v}$ for some $u, v \geq 0$, which implies $n=5$. Here $2 \cos \alpha=\frac{3}{2}$ and $2 \cos \gamma=\frac{1}{4}$, and indeed $P_{2}(3 / 2)=1 / 4$. - $n+1=2^{u}$ and $n-1=3 \cdot 2^{v}$ for some $u, v \geq 0$, which implies $n=7$. Here $2 \cos \alpha=\frac{11}{8}$ and $2 \cos \gamma=\frac{1}{2}$, and indeed $P_{3}(1 / 2)=-11 / 8$.  Finally, $n=4$ works because the triangle is right, completing the solution. Remark (Major generalization due to Luke Robitaille). In fact one may find all quirky triangles whose sides are integers in arithmetic progression.  Indeed, if the side lengths of the triangle are $x-y, x, x+y$ with $\operatorname{gcd}(x, y)=1$ then the problem becomes  $$ P_{r}\left(\frac{x+4 y}{x+y}\right)= \pm P_{s}\left(\frac{x-4 y}{x-y}\right) $$  and so in the same way as before, we ought to have $x+y$ and $x-y$ are both of the form $3 \cdot 2^{*}$ unless $r s=0$. This time, when $r s=0$, we get the extra solutions $(1,0)$ and $(5,2)$.  For $r s \neq 0$, by triangle inequality, we have $x-y \leq x+y<3(x-y)$, and $\min \left(\nu_{2}(x-\right.$ $\left.y), \nu_{2}(x+y)\right) \leq 1$, so it follows one of $x-y$ or $x+y$ must be in $\{1,2,3,6\}$. An exhaustive check then leads to  $$ (x, y) \in\{(3,1),(5,1),(7,1),(11,5)\} \cup\{(1,0),(5,2),(4,1)\} $$  In conclusion the equilateral triangle, $3-5-7$ triangle (which has a $120^{\circ}$ angle) and $6-11-16$ triangle (which satisfies $B=3 A+4 C$ ) are exactly the new quirky triangles (up to similarity) whose sides are integers in arithmetic progression.


problem: Find all pairs of positive integers $(a, b)$ satisfying the following conditions: (i) $a$ divides $b^{4}+1$, (ii) $b$ divides $a^{4}+1$, (iii) $\lfloor\sqrt{a}\rfloor=\lfloor\sqrt{b}\rfloor$.

solution: Obviously, $\operatorname{gcd}(a, b)=1$, so the problem conditions imply  $$ a b \mid(a-b)^{4}+1 $$  since each of $a$ and $b$ divide the right-hand side. We define  $$ k \stackrel{\text { def }}{=} \frac{(b-a)^{4}+1}{a b} . $$  Claim (Size estimate) — We must have $k \leq 16$.   $$ \begin{aligned} a b & \geq n^{2}\left(n^{2}+1\right) \geq n^{4}+1 \\ (b-a)^{4}+1 & \leq(2 n)^{4}+1=16 n^{4}+1 \end{aligned} $$  which shows $k \leq 16$.  Claim (Orders argument) - In fact, $k=1$.   Thus $k$ is odd. However, every odd prime divisor of $(b-a)^{4}+1$ is congruent to 1 $(\bmod 8)$ and is thus at least 17 , so $k=1$ or $k \geq 17$. It follows that $k=1$.  At this point, we have reduced to solving  $$ a b=(b-a)^{4}+1 $$   $$ a^{2}-d a-\left(d^{4}+1\right)=0 $$  The discriminant $d^{2}+4\left(d^{4}+1\right)=4 d^{4}+d^{2}+4$ must be a perfect square.  - The cases $d=0$ and $d=1$ lead to pairs $(1,1)$ and $(1,2)$. - If $d \geq 2$, then we can sandwich  $$ \left(2 d^{2}\right)^{2}<4 d^{4}+d^{2}+4<4 d^{4}+4 d^{2}+1=\left(2 d^{2}+1\right)^{2} $$  so the discriminant is not a square. Remark (Author remarks on origin). This comes from the problem of the existence of a pair of elliptic curves over $\mathbb{F}_{a}, \mathbb{F}_{b}$ respectively, such that the number of points on one is the field size of the other. The bound $n^{2} \leq a, b<(n+1)^{2}$ is the Hasse bound. The divisibility conditions correspond to asserting that the embedding degree of each curve is 8 , so that they are pairing friendly. In this way, the problem is essentially the key result of https://arxiv.org/pdf/1803.02067.pdf, shown in Proposition 3.


problem: Let $\mathbb{N}^{2}$ denote the set of ordered pairs of positive integers. A finite subset $S$ of $\mathbb{N}^{2}$ is stable if whenever $(x, y)$ is in $S$, then so are all points $\left(x^{\prime}, y^{\prime}\right)$ of $\mathbb{N}^{2}$ with both $x^{\prime} \leq x$ and $y^{\prime} \leq y$. Prove that if $S$ is a stable set, then among all stable subsets of $S$ (including the empty set and $S$ itself), at least half of them have an even number of elements.

solution: Suppose $|S| \geq 2$. For any $p \in S$, let $R(p)$ denote the stable rectangle with upper-right corner $p$. We say such $p$ is pivotal if $p+(1,1) \notin S$ and $|R(p)|$ is even. ![](https://cdn.mathpix.com/cropped/2024_11_19_a8f70a0d08e0809deba0g-12.jpg?height=455&width=818&top_left_y=1069&top_left_x=622)  Claim - If $|S| \geq 2$, then a pivotal $p$ always exists.  - If it has length at least 2 , one of the two rightmost points in it is pivotal. - Otherwise, the top row has length 1. Now either the top point or the point below it (which exists as $|S| \geq 2$ ) is pivotal.  We describe how to complete the induction, given some pivotal $p \in S$. There is a partition  $$ S=R(p) \sqcup S_{1} \sqcup S_{2} $$  where $S_{1}$ and $S_{2}$ are the sets of points in $S$ above and to the right of $p$ (possibly empty). Claim - The desired inequality holds for stable subsets containing $p$.  Since $|R(p)|$ is even, exactly $E_{1} E_{2}+O_{1} O_{2}$ stable subsets containing $p$ are even, and exactly $E_{1} O_{2}+E_{2} O_{1}$ are odd. As $E_{1} \geq O_{1}$ and $E_{2} \geq O_{2}$ by inductive hypothesis, we obtain $E_{1} E_{2}+O_{1} O_{2} \geq E_{1} O_{2}+E_{2} O_{1}$ as desired.  By the inductive hypothesis, the desired inequality also holds for stable subsets not containing $p$, so we are done.


problem: Let $A, B, C, D$ be four points such that no three are collinear and $D$ is not the orthocenter of triangle $A B C$. Let $P, Q, R$ be the orthocenters of $\triangle B C D, \triangle C A D$, $\triangle A B D$, respectively. Suppose that lines $A P, B Q, C R$ are pairwise distinct and are concurrent. Show that the four points $A, B, C, D$ lie on a circle.

solution: Let $T$ be the concurrency point, and let $H$ be the orthocenter of $\triangle A B C$. ![](https://cdn.mathpix.com/cropped/2024_11_19_a8f70a0d08e0809deba0g-14.jpg?height=593&width=806&top_left_y=863&top_left_x=631)  Claim (Key claim) - $T$ is the midpoint of $\overline{A P}, \overline{B Q}, \overline{C R}, \overline{D H}$, and $D$ is the orthocenter of $\triangle P Q R$.  By symmetric reasoning, we get that $A Q C P B R$ is a hexagon with opposite sides parallel and concurrent diagonals as $\overline{A P}, \overline{B Q}, \overline{C R}$ meet at $T$. This implies that the hexagon is centrally symmetric about $T$; indeed  $$ \frac{A T}{T P}=\frac{T Q}{B T}=\frac{C T}{T R}=\frac{T P}{A T} $$  so all the ratios are equal to +1 . Next, $\overline{P D} \perp \overline{B C} \| \overline{Q R}$, so by symmetry we get $D$ is the orthocenter of $\triangle P Q R$. This means that $T$ is the midpoint of $\overline{D H}$ as well.  ## Corollary  The configuration is now symmetric: we have four points $A, B, C, D$, and their reflections in $T$ are four orthocenters $P, Q, R, H$.  Let $S$ be the centroid of $\{A, B, C, D\}$, and let $O$ be the reflection of $T$ in $S$. We are ready to conclude:  Claim - $A, B, C, D$ are equidistant from $O$. Then $T^{\prime}$ is the midpoint of $\overline{A^{\prime} D^{\prime}}$, so $S^{\prime}=\frac{1}{4}\left(A^{\prime}+D^{\prime}+B+C\right)$ gives that $O^{\prime}$ is the midpoint of $\overline{B C}$.  Thus $O B=O C$ and we're done.


problem: Find all nonconstant polynomials $P(z)$ with complex coefficients for which all complex roots of the polynomials $P(z)$ and $P(z)-1$ have absolute value 1.

solution: The answer is $P(x)$ should be a polynomial of the form $P(x)=\lambda x^{n}-\mu$ where $|\lambda|=|\mu|$ and $\operatorname{Re} \mu=-\frac{1}{2}$. One may check these all work; let's prove they are the only solutions. \l First approach (Evan Chen). We introduce the following notations:  $$ \begin{aligned} P(x) & =c_{n} x^{n}+c_{n-1} x^{n-1}+\cdots+c_{1} x+c_{0} \\ & =c_{n}\left(x+\alpha_{1}\right) \ldots\left(x+\alpha_{n}\right) \\ P(x)-1 & =c_{n}\left(x+\beta_{1}\right) \ldots\left(x+\beta_{n}\right) \end{aligned} $$  By taking conjugates,  $$ \begin{aligned} \left(x+\alpha_{1}\right) \cdots\left(x+\alpha_{n}\right) & =\left(x+\beta_{1}\right) \cdots\left(x+\beta_{n}\right)+c_{n}^{-1} \\ \Longrightarrow\left(x+\frac{1}{\alpha_{1}}\right) \cdots\left(x+\frac{1}{\alpha_{n}}\right) & =\left(x+\frac{1}{\beta_{1}}\right) \cdots\left(x+\frac{1}{\beta_{n}}\right)+\left(\overline{c_{n}}\right)^{-1} \end{aligned} $$  The equation $(\boldsymbol{\oplus})$ is the main player: Claim - We have $c_{k}=0$ for all $k=1, \ldots, n-1$.   $$ \frac{c_{n-k}}{\prod_{i} \alpha_{i}}=\frac{c_{n-k}}{\prod_{i} \beta_{i}} $$  but $\prod_{i} \alpha_{i}-\prod_{i} \beta_{i}=\frac{1}{c_{n}} \neq 0$. Hence $c_{k}=0$. It follows that $P(x)$ must be of the form $P(x)=\lambda x^{n}-\mu$, so that $P(x)=\lambda x^{n}-(\mu+1)$. This requires $|\mu|=|\mu+1|=|\lambda|$ which is equivalent to the stated part.


solution: The answer is $P(x)$ should be a polynomial of the form $P(x)=\lambda x^{n}-\mu$ where $|\lambda|=|\mu|$ and $\operatorname{Re} \mu=-\frac{1}{2}$. One may check these all work; let's prove they are the only solutions. II Second approach (from the author). We let $A=P$ and $B=P-1$ to make the notation more symmetric. We will as before show that $A$ and $B$ have all coefficients equal to zero other than the leading and constant coefficient; the finish is the same.  First, we rule out double roots. Claim - Neither $A$ nor $B$ have double roots.   Let $\omega=e^{2 \pi i / n}$, let $a_{1}, \ldots, a_{n}$ be the roots of $A$, and let $b_{1}, \ldots, b_{n}$ be the roots of $B$. For each $k$, let $A_{k}$ and $B_{k}$ be the points in the complex plane corresponding to $a_{k}$ and $b_{k}$ 。  Claim (Main claim) - For any $i$ and $j, \frac{a_{i}}{a_{j}}$ is a power of $\omega$.  $$ \frac{a_{i}-b_{1}}{a_{j}-b_{1}} \cdots \frac{a_{i}-b_{n}}{a_{j}-b_{n}}=\frac{B\left(a_{i}\right)}{B\left(a_{j}\right)}=\frac{A\left(a_{i}\right)-1}{A\left(a_{j}\right)-1}=\frac{0-1}{0-1}=1 $$  Since the points $A_{i}, A_{j}, B_{k}$ all lie on the unit circle, interpreting the left-hand side geometrically gives  $$ \measuredangle A_{i} B_{1} A_{j}+\cdots+\measuredangle A_{i} B_{n} A_{j}=0 \Longrightarrow n \widehat{A_{i} A_{j}}=0 $$  where angles are directed modulo $180^{\circ}$ and arcs are directed modulo $360^{\circ}$. This implies that $\frac{a_{i}}{a_{j}}$ is a power of $\omega$.  Now the finish is easy: since $a_{1}, \ldots, a_{n}$ are all different, they must be $a_{1} \omega^{0}, \ldots, a_{1} \omega^{n-1}$ in some order; this shows that $A$ is a multiple of $x^{n}-a_{1}^{n}$, as needed.


problem: For every positive integer $N$, let $\sigma(N)$ denote the sum of the positive integer divisors of $N$. Find all integers $m \geq n \geq 2$ satisfying  $$ \frac{\sigma(m)-1}{m-1}=\frac{\sigma(n)-1}{n-1}=\frac{\sigma(m n)-1}{m n-1} . $$

solution: The answer is that $m$ and $n$ should be powers of the same prime number. These all work because for a prime power we have  $$ \frac{\sigma\left(p^{e}\right)-1}{p^{e}-1}=\frac{\left(1+p+\cdots+p^{e}\right)-1}{p^{e}-1}=\frac{p\left(1+\cdots+p^{e-1}\right)}{p^{e}-1}=\frac{p}{p-1} $$  So we now prove these are the only ones. Let $\lambda$ be the common value of the three fractions.   $$ \begin{aligned} \sigma(m n) & \geq \sigma(m)+m \sigma(n)-m \\ & =(\lambda m-\lambda+1)+m(\lambda n-\lambda+1)-m \\ & =\lambda m n-\lambda+1 \end{aligned} $$  and so equality holds. Thus these are all the divisors of $m n$, for a count of $d(m)+d(n)-$ 1.  Claim - If $d(m n)=d(m)+d(n)-1$ and $\min (m, n) \geq 2$, then $m$ and $n$ are powers of the same prime.   Remark (Nikolai Beluhov). Here is a completion not relying on $|A \cdot B|=|A|+|B|-1$. By the above arguments, we see that every divisor of $m n$ is either a divisor of $n$, or $n$ times a divisor of $m$.  Now suppose that some prime $p \mid m$ but $p \nmid n$. Then $p \mid m n$ but $p$ does not appear in the above classification, a contradiction. By symmetry, it follows that $m$ and $n$ have the same prime divisors.  Now suppose we have different primes $p \mid m$ and $q \mid n$. Write $\nu_{p}(m)=\alpha$ and $\nu_{p}(n)=\beta$. Then $p^{\alpha+\beta} \mid m n$, but it does not appear in the above characterization, a contradiction. Thus, $m$ and $n$ are powers of the same prime.  Remark (Comments on the function in the problem). Let $f(n)=\frac{\sigma(n)-1}{n-1}$. Then $f$ is not really injective even outside the above solution; for example, we have $f\left(6 \cdot 11^{k}\right)=\frac{11}{5}$ for all $k$, plus sporadic equivalences like $f(14)=f(404)$, as pointed out by one reviewer during test-solving. This means that both relations should be used at once, not independently.  Remark (Authorship remarks). Ankan gave the following story for how he came up with the problem while thinking about so-called almost perfect numbers.  I was in some boring talk when I recalled a conjecture that if $\sigma(n)=2 n-1$, then $n$ is a power of 2 . For some reason (divine intervention, maybe) I had the double idea of (1) seeing whether $m, n, m n$ all almost perfect implies $m, n$ powers of 2 , and (2) trying the naive divisor bound to resolve this. Through sheer dumb luck this happened to work out perfectly. I thought this was kinda cool but I felt that I hadn't really unlocked a lot of the potential this idea had: then I basically tried to find the "general situation" which allows for this manipulation, and was amazed that it led to such a striking statement.


problem: Ten million fireflies are glowing in $\mathbb{R}^{3}$ at midnight. Some of the fireflies are friends, and friendship is always mutual. Every second, one firefly moves to a new position so that its distance from each one of its friends is the same as it was before moving. This is the only way that the fireflies ever change their positions. No two fireflies may ever occupy the same point. Initially, no two fireflies, friends or not, are more than a meter away. Following some finite number of seconds, all fireflies find themselves at least ten million meters away from their original positions. Given this information, find the greatest possible number of friendships between the fireflies.

solution: In general, we show that when $n \geq 70$, the answer is $f(n)=\left\lfloor\frac{n^{2}}{3}\right\rfloor$. Construction: Choose three pairwise parallel lines $\ell_{A}, \ell_{B}, \ell_{C}$ forming an infinite equilateral triangle prism (with side larger than 1). Split the $n$ fireflies among the lines as equally as possible, and say that two fireflies are friends iff they lie on different lines.  To see this works:  1. Reflect $\ell_{A}$ and all fireflies on $\ell_{A}$ in the plane containing $\ell_{B}$ and $\ell_{C}$. 2. Reflect $\ell_{B}$ and all fireflies on $\ell_{B}$ in the plane containing $\ell_{C}$ and $\ell_{A}$. 3. Reflect $\ell_{C}$ and all fireflies on $\ell_{C}$ in the plane containing $\ell_{A}$ and $\ell_{B}$.  Let $g(n)$ be the answer, given that there exist four pairwise friends (say $a, b, c, d$ ). Note that for a firefly to move, all its friends must be coplanar.  Claim (No coplanar $K_{4}$ ) — We can't have four coplanar fireflies which are pairwise friends.   Claim (Key claim — tetrahedrons don't share faces often) — There are at most 12 fireflies $e$ which are friends with at least three of $a, b, c, d$.   WLOG, will assume that $e$ is friends with $a, b, c$. Then $e$ will always be located at one of two points $E_{1}$ and $E_{2}$ relative to $A B C$, such that $E_{1} A B C$ and $E_{2} A B C$ are two congruent tetrahedrons with fixed shape. We note that points $D, E_{1}$, and $E_{2}$ are all different: clearly $D \neq E_{1}$ and $E_{1} \neq E_{2}$. (If $D=E_{2}$, then some fireflies won't be able to move.)  Consider the moment where firefly $a$ moves. Its friends must be coplanar at that time, so one of $E_{1}, E_{2}$ lies in plane $B C D$. Similar reasoning holds for planes $A C D$ and $A B D$.  So, WLOG $E_{1}$ lies on both planes $B C D$ and $A C D$. Then $E_{1}$ lies on line $C D$, and $E_{2}$ lies in plane $A B D$. This uniquely determines $\left(E_{1}, E_{2}\right)$ relative to $A B C D$ :  - $E_{1}$ is the intersection of line $C D$ with the reflection of plane $A B D$ in plane $A B C$. - $E_{2}$ is the intersection of plane $A B D$ with the reflection of line $C D$ in plane $A B C$.  Accounting for WLOGs, there are at most 12 possibilities for the set $\left\{E_{1}, E_{2}\right\}$, and thus at most 12 possibilities for $E$. (It's not possible for both elements of one pair $\left\{E_{1}, E_{2}\right\}$ to be occupied, because then they couldn't move.)  Thus, the number of friendships involving exactly one of $a, b, c, d$ is at most $(n-16)$. $2+12 \cdot 3=2 n+4$, so removing these four fireflies gives  $$ g(n) \leq 6+(2 n+4)+\max \{f(n-4), g(n-4)\} $$   $$ g(n) \leq \max \{f(n),(2 n+10)+g(n-4)\} \quad \forall n \geq 24 $$  By iterating the above inequality, we get  $$ \begin{aligned} g(n) \leq \max \{f(n),(2 n+10) & +(2(n-4)+10) \\ & +\cdots+(2(n-4 r)+10)+g(n-4 r-4)\} \end{aligned} $$  where $r$ satisfies $n-4 r-4<24 \leq n-4 r$. Now  $$ \begin{aligned} & (2 n+10)+(2(n-4)+10)+\cdots+(2(n-4 r)+10)+g(n-4 r-4) \\ = & (r+1)(2 n-4 r+10)+g(n-4 r-4) \\ \leq & \left(\frac{n}{4}-5\right)(n+37)+\binom{24}{2} . \end{aligned} $$  This is less than $f(n)$ for $n \geq 70$, which concludes the solution. Remark. There are positive integers $n$ such that it is possible to do better than $f(n)$ friendships. For instance, $f(5)=8$, whereas five fireflies $a, b, c, d$, and $e$ as in the proof of the Lemma ( $E_{1}$ being the intersection point of line $C D$ with the reflection of plane $(A B D)$ in plane $(A B C), E_{2}$ being the intersection point of plane $(A B D)$ with the reflection of line $C D$ in plane $(A B C)$, and tetrahedron $A B C D$ being sufficiently arbitrary that points $E_{1}$ and $E_{2}$ exist and points $D, E_{1}$, and $E_{2}$ are pairwise distinct) give a total of nine friendships.  Remark (Author comments). It is natural to approach the problem by looking at the two-dimensional version first. In two dimensions, the following arrangement suggests itself almost immediately: We distribute all fireflies as equally as possible among two parallel lines, and two fireflies are friends if and only if they are on different lines.  Similarly to the three-dimensional version, this attains the greatest possible number of friendships for all sufficiently large $n$, though not for all $n$. For instance, at least one friendlier arrangements exists for $n=4$, similarly to the above friendlier arrangement for $n=5$ in three dimensions.  This observation strongly suggests that in three dimensions we should distribute the fireflies as equally as possible among two parallel planes, and that two fireflies should be friends if and only if they are on different planes. It was a great surprise for me to discover that this arrangement does not in fact give the correct answer!  Remark. On the other hand, Ankan Bhattacharya gives the following reasoning as to why the answer should not be that surprising:  I think the answer $\left(10^{14}-1\right) / 3$ is quite natural if you realize that $(n / 2)^{2}$ is probably optimal in 2D and $\binom{n}{2}$ is optimal in super high dimensions (i.e. around $n$ ). So going from dimension 2 to 3 should increase the answer (and indeed it does).