$A_1, A_2, \ldots, A_n$ are subsets of a set $S$ with $|S| = 2019$ such that the union of any three of them equals $S$, but the union of any two does not equal $S$. Find the maximum value of $n$.

Let's think step by step and output the final answer within \boxed{}.
user