## $n$ families, each with four members, a father, a mother, a son and a daughter, were invited to a restaurant. They were all seated at a large circular table with $4n$ seats such that men and women alternate.

Let $M(n)$ be the number of ways the families can be seated such that none of the families were seated together. A family is considered to be seated together only when all the members of a family sit next to each other.

For example, $M(1)=0$, $M(2)=896$, $M(3)=890880$ and $M(10) \equiv 170717180 \pmod {1\,000\,000\,007}$.

Let $S(n)=\displaystyle \sum_{k=2}^nM(k)$.

For example, $S(10) \equiv 399291975 \pmod {1\,000\,000\,007}$.

Find $S(2021)$. Give your answer modulo $1\,000\,000\,007$.

### Given the complexity and specific nature of this problem, it seems it’s a combinatoric question from a contest such as Project Euler or the International Mathematical Olympiad rather than a typical high school or undergraduate study topic.

Unfortunately, the exact formula for $M(n)$ isn’t straightforward and is a complex problem of combinatorics. If we could find such a formula, we could substitute it into $S(n)$ exactly and receive an exact solution, but this might not be practical.

A general approach, however, would be to think about the problem in terms of permutations.

As given in the problem, men and women are seated alternatively and no family members are seated together. Let’s start with fewer families (like $M(2)$) and see if we can find a pattern:

When $n=2$ (two families), since men and women alternate, there are two possible arrangements: Men from Family 1 and Family 2 can sit next to each other, or women from Family 1 and Family 2 can sit next to each other. Secondly, the two men and two women from each family can be arranged in $2!=2$ ways amongst them.

This gives us a total of $2 \cdot 2^4 = 32$. However, this includes arrangements where one or both families sit together. Since each family can arrange itself in $4!=24$ ways and there are 2 such families, $2 \cdot 24=48$ is removed from 32 which is impossible, hence the negative solutions (-16) are added to the total of $4! \cdot 4! = 576$ (which is when both families sit together) to give $M(2)=576-16=560$. But we must also account for the rotations around the table, because they’re identical since the table is circular, which results in dividing our total by 4. So our final calculation for $M(2)$ is $560/4=140$, and multiplying this by $2^4 = 16$ (which is due to the two genders and two family members of each gender) for alternating arrangements gives $140 \cdot 16 = 2240$.

These general steps can be followed for larger $n$, but as you can see, it gets increasingly difficult.

The result $M(10) \equiv 170717180 \pmod {1\,000\,000\,007}$ and $S(10) \equiv 399291975 \pmod {1\,000\,000\,007}$ would have been obtained by using a computer program which follows this logic, as the calculations get exponentially larger and thus are not feasible by hand.

You will probably need a similar program or script to calculate $S(2021)$, given how large that number will be.

Due to the complexity and specific nature of this problem, it’s likely that more advanced mathematical modelling or computational techniques would be needed to solve it, such as generating functions or backtracking algorithms for combinatorics problems, or techniques for solving large systems of congruences.

##### More Answers:

Minimum Area of a Convex Grid PolygonWhat? Where? When?

Sum of Squares II