Problem

Source: 2019 Saudi Arabia BMO TST II p1

Tags: combinatorics



There are $n$ people with hats present at a party. Each two of them greeted each other exactly once and each greeting consisted of exchanging the hats that the two persons had at the moment. Find all $n \ge 2$ for which the order of greetings can be arranged in such a way that after all of them, each person has their own hat back.