Statistics

Problem Statement for "HomeAwayLeague"

Problem Statement

There are N football teams in the region. The number N is even. Each team has it own home stadium.

The league committee has decided to organize a short summer league for all N teams. The league should have the following properties:

  • The league will consist of exactly two rounds of football matches.
  • Each team will play one match in each round.
  • Each pair of teams will play each other at most once.
  • It is well known that playing at its home stadium gives the team a slight advantage. To keep the league fair, each team must play exactly one home game and one away game.

Count all valid league schedules and return that count modulo 10^9 + 7.

Formally: A match is an ordered pair (home team, away team). A round schedule is an unordered set of matches such that each team appears in exactly one match. A league schedule is an ordered pair of round schedules.

Definition

Class:
HomeAwayLeague
Method:
matches
Parameters:
int
Returns:
int
Method signature:
int matches(int x)
(be sure your method is public)

Constraints

  • N will be between 4 and 500,000, inclusive.
  • N will be even.

Examples

  1. 4

    Returns: 12

    Let's use (X,Y) to denote a match where X is the home team and Y is the away team, i.e., a match played at X's home stadium. Here are three of the twelve distinct valid league schedules: First round: (A,B), (C,D). Second round: (B,C), (D,A). First round: (A,B), (D,C). Second round: (B,D), (C,A). First round: (C,A), (B,D). Second round: (A,B), (D,C). Note that the third schedule can be obtained from the second one by swapping the order of the rounds. These two schedules are considered distinct.

  2. 6

    Returns: 240

  3. 8

    Returns: 15120

  4. 10

    Returns: 1330560

  5. 12

    Returns: 176299200

  6. 14

    Returns: 69156896

  7. 16

    Returns: 116573321

  8. 18

    Returns: 28210500

  9. 20

    Returns: 162558033

  10. 22

    Returns: 513950234

  11. 24

    Returns: 742109722

  12. 26

    Returns: 292189190

  13. 500000

    Returns: 623944634

  14. 1750

    Returns: 692254544

  15. 1044

    Returns: 685546564

  16. 1540

    Returns: 405552029

  17. 386

    Returns: 769284936

  18. 286

    Returns: 863638954

  19. 218560

    Returns: 244378502

  20. 278886

    Returns: 707028450

  21. 393300

    Returns: 25770988

  22. 246512

    Returns: 59741836

  23. 279900

    Returns: 25393081

  24. 442576

    Returns: 110915818

  25. 413732

    Returns: 947210709

  26. 441540

    Returns: 852768510

  27. 491658

    Returns: 661561938

  28. 414322

    Returns: 443057932

  29. 471748

    Returns: 829114589

  30. 449028

    Returns: 159750116

  31. 406112

    Returns: 358542402

  32. 402700

    Returns: 40765893

  33. 489594

    Returns: 79550224

  34. 469260

    Returns: 552298495

  35. 419108

    Returns: 84098132

  36. 418928

    Returns: 289154756

  37. 423892

    Returns: 489589847

  38. 485600

    Returns: 625422281

  39. 410048

    Returns: 445472463

  40. 429568

    Returns: 498078487

  41. 420326

    Returns: 336312449

  42. 454322

    Returns: 813967975

  43. 433664

    Returns: 773966314

  44. 428028

    Returns: 17595816

  45. 430844

    Returns: 6657054

  46. 478486

    Returns: 56532561

  47. 493662

    Returns: 626335551

  48. 441404

    Returns: 668742480

  49. 487874

    Returns: 798619102

  50. 499998

    Returns: 788359703

  51. 359210

    Returns: 984387624

  52. 1000

    Returns: 975860204

  53. 220464

    Returns: 884801879

  54. 5000

    Returns: 822163173

  55. 42

    Returns: 729578447

  56. 50000

    Returns: 676502078


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: