Log inSign up
Problems / B062

Six photos on an album page

200 ptsCases 14Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A photo studio makes albums that hold six photos on each page. A customer brings k candidate photos, and the studio picks six of them to fill one page.

The candidate photos carry numbers that are all different, and the numbers are given in ascending order from the smallest to the largest. The same photo is never stuck on one page twice. The studio also does not write down which slot each of the six photos went into, so if the photos picked are the same, it counts as the same case.

The studio wants to show the customer every possible case and let them pick one of them. Write a program that prints every way to pick six photos, in lexicographic order. Each case writes the numbers of the photos picked in ascending order. Lexicographic order means that a case whose first number is smaller comes first, and if that number is the same, a case whose second number is smaller comes first.

Several customers come in one after another. The number of candidate photos and their numbers are given separately for each customer, and the answer is printed separately for each customer.

For example, suppose some customer brought k=7 candidate photos, numbered 14, 24, 26, 28, 29, 32 and 36 in that order. There are 7 ways to pick six of them, and listed in lexicographic order they are the ones in the table below.

CaseNumbers of the photos picked
Case 114 24 26 28 29 32
Case 214 24 26 28 29 36
Case 314 24 26 28 32 36
Case 414 24 26 29 32 36
Case 514 24 28 29 32 36
Case 614 26 28 29 32 36
Case 724 26 28 29 32 36

With seven candidate photos, picking six comes to the same thing as picking the one photo that is left off, so there are 7 cases. Case 1 in the table leaves off photo 36, and case 7 leaves off photo 14.

If k is 6, every candidate photo goes on the page, so there is only one case. As the number of candidate photos grows, the number of cases grows as in the table below.

Number of candidate photos k678910111213
Number of cases that can be picked1728842104629241,716

So the number of lines printed for one customer is between 1 and 1,716, and one blank line follows them.

Input and Output Examples

Example 1

Input

7 14 24 26 28 29 32 36
0

Output

14 24 26 28 29 32
14 24 26 28 29 36
14 24 26 28 32 36
14 24 26 29 32 36
14 24 28 29 32 36
14 26 28 29 32 36
24 26 28 29 32 36

Example 2

Input

6 19 25 32 40 47 49
0

Output

19 25 32 40 47 49

Example 3

Input

6 8 12 29 34 39 43
6 11 21 24 27 30 34
0

Output

8 12 29 34 39 43

11 21 24 27 30 34

Input

  • The input is made of several lines, and each line is the information for one customer. Each line first gives the number of candidate photos k that the customer brought, and then the k photo numbers, separated by spaces. k is a natural number from 6 to 13, and the photo numbers are different natural numbers from 1 to 49, given in ascending order.

  • The last line holds a single 0. That line means there are no more customers, so no answer is printed for it. There are at least 1 and at most 4 customers.

Output

  • For each customer, print every way to pick six photos, in lexicographic order, one case per line. A line writes the numbers of the six photos picked in ascending order. That leaves one space after the last number on a line as well. When a line holds more than one value, the values are separated by a single space.

Requirements

  • Exactly six photos go on one page
  • The same photo is never stuck on a page twice
  • If the photos picked are the same it is the same case, so print each case only once
  • Write the numbers of each case in ascending order, and print the cases in lexicographic order
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 14 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 14 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 14 cases to solve this.

Input
Expected output
6 19 25 32 40 47 49
0
19 25 32 40 47 49
6 8 12 29 34 39 43
6 11 21 24 27 30 34
0
8 12 29 34 39 43

11 21 24 27 30 34
7 14 24 26 28 29 32 36
0
14 24 26 28 29 32
14 24 26 28 29 36
14 24 26 28 32 36
14 24 26 29 32 36
14 24 28 29 32 36
14 26 28 29 32 36
24 26 28 29 32 36

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 4.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal252ms368 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.