5. In the country of Lemonia, coins of denominations $6n+1$, $6n+4$, $6n+7$, and $6n+10$ piasters are in circulation, where $n$ is a natural number. A resident of the country went to the bank without any cash on hand. What is the largest amount that the bank will not be able to give him?
Answer: $12 n^{2}+14 n-1$.

Solution. Let's call a natural number $s$ decomposable if the bank can pay the sum $s$ using only coins of value $6 n+4, 6 n+7$, and $6 n+10$ piastres. For any $r=1, \ldots, 6 n$, let $m_{r}$ be the smallest decomposable number that gives a remainder of $r$ when divided by $6 n+1$. We will prove two statements.

1) If $r \in\{1, \ldots, 6 n\}, s \bmod (6 n+1)=r$, then for $s \geqslant m_{r}$, the bank can pay the sum $s$, and for $s<m_{r}$, it cannot. The first statement is obvious: one needs to pay the sum $m_{r}$ first, and then add some number of coins worth $6 n+1$ piastres. Suppose now that $s<m_{r}$ and the sum $s$ can be paid. In this case, several coins worth $6 n+1$ piastres will have to be used. Removing all these coins, we get a decomposable sum, smaller than $m_{r}$ and also giving a remainder of $r$ when divided by $6 n+1$. This contradicts the minimality of $m_{r}$.
2) The numbers $3 k \bmod (6 n+1)$ take on the values $\{1, \ldots, 6 n\}$ for $k=1, \ldots, 6 n$. Indeed, it is enough to show that all of them are distinct. If $3 k-3 k^{\prime}$ is divisible by $(6 n+1)$, then $\left(k-k^{\prime}\right) \vdots(6 n+1)$. Since $\left|k-k^{\prime}\right| \leqslant 6 n$, we get $k=k^{\prime}$.

Obviously, sums that are multiples of $6 n+1$ can be paid. Then, by 1), the answer to the problem will be $\max \left\{m_{1}, \ldots, m_{6 n}\right\}-(6 n+1)$. Let's find the largest of the numbers $m_{r}$. Let $r \in\{1, \ldots, 6 n\}$. Note that

$$
6 n+4=(6 n+1)+3, \quad 6 n+7=(6 n+1)+6 \quad \text { and } \quad 6 n+10=(6 n+1)+9
$$

By 2), there exists a unique number $k \in\{1, \ldots, 6 n\}$ for which $3 k \bmod (6 n+1)=r$. Since the remainders of the coins modulo $6 n+1$ take the values 3, 6, and 9, we need to represent $3 k$ as the sum of the smallest number of these numbers. This is achieved as follows: we add nines until we get the largest number not exceeding $3 k$, and then add 3 or 6 if necessary. In this sum, there will be $\left[\frac{k+2}{3}\right]$ terms. Then

$$
m_{r}=3 k+\left[\frac{k+2}{3}\right] \cdot(6 n+1) \leqslant 3 \cdot 6 n+2 n(6 n+1)=12 n^{2}+20 n
$$

and equality is achieved when $k=6 n$. Therefore, the answer to the problem is

$$
12 n^{2}+20 n-(6 n+1)=12 n^{2}+14 n-1
$$

## Variant 3