EN
Santa's sleighs

2025 · Task 2

Santa's Sleighs

Author: Toma Petrušić

06/12/2025 00:01 – 19/12/2025 23:59

Santa is facing a huge logistical challenge: he has to distribute 420 extremely heavy packages (presents) across the 140 sleighs at his disposal.

Every package is enormously heavy. The weights are integers between 1013 and 1014.

Santa needs your help to make sure all the sleighs are loaded as evenly as possible. His reindeer, worn out after a long season, will be happiest if the largest total weight of any single sleigh is as small as possible.

Your task is to distribute the packages across the sleighs so that the largest total load of any sleigh is as small as possible.

Input

The input consists of 420 numbers (the weights described above), separated by newlines.

Example:

22277302519162
75947866978990
95962420265476
51912118423886
...

IMPORTANT! The position of a weight in the input defines its ordinal number (index). Indexing starts at 0 for the first line and goes up to 419 for the last line. Your output consists of the indices of the weights, not the weights themselves.

Output

Your output must contain exactly 140 lines, where each line represents one sleigh. The first line represents the first sleigh, the second line the second sleigh, and so on.

Each line will contain the indices of the presents assigned to that sleigh, separated by spaces. Of course, every index must be assigned to a sleigh.

Scoring

The score is based on the largest total weight of any sleigh:

  score = 100 000 × (D_MAX – heaviest_sleigh) / (D_MAX – D_MIN)

where:

D_MAX - a value chosen to widen the score range. It is not the theoretically worst possible result, but the largest sum produced by the simplest greedy algorithm that doesn't use sorting. Its value is 230136843644340

D_MIN – represents the theoretical optimum. It is the total sum of all weights divided by the number of sleighs, rounded up. Its value is 171514003252241.

The result is between 0 and 100 000 points.

The smaller the largest weight, the better the result.

Example

This is a simplified example with 6 packages and 2 sleighs (the weights are much smaller to make it easier to follow):

Input

12
16
24
32
40
48

Output

0 5 1
2 4 3

On the first sleigh we put the presents with indices 0, 5 and 1 (weights 12, 48 and 16), giving a total weight of 76. On the second sleigh we put the presents with indices 2, 4 and 3 (weights 24, 40 and 32), giving a total weight of 96. The heaviest sleigh weighs 96. This is the weight used in the scoring formula.

Good luck and happy coding! 🎄📸