
The regional soccer championship brought together all the town and district teams (though there were still fewer than 1,000 of them). The tournament was held in two stages. In the first stage, participants were divided into equal groups, within which they played one match against each other. The top two teams from each group advanced to the next stage and continued playing in a single-elimination format until the final, which determined the champion and runner-up, while the teams that finished in third and fourth place competed against each other for the bronze medal. It turned out that the total number of matches played during the tournament by the four finalist teams was half the number of participants in the competition.
How many teams arrived at the tournament?