Bingo P36031


Statement
 

pdf   zip

html

A bingo ticket contains 15 different numbers from 1 to 99, in 3 rows of 5 numbers each one, without appearing the same number more than once. The players mark the numbers of their bingo ticket at the same time as those ones are taken out from a lottery drum. It is awarded the first player that marks off all the numbers of one of the lines (“Line correct - please pay out!”) and the first player that marks off the whole bingo ticket (“House correct - please pay out!”). If there are various players that mark off a whole line or the whole bingo ticket at the same time the prize is fairly shared.

In this problem we give the order in which the 99 balls will go out of the lottery drum, and you are asked to discover which ticket would be interesting to have bought, assuming that the price of the ticket is 10 euros and the prizes for a line and house are 17 and 28 euros respectively. In particular, you must solve various similar situations: the order of the ball will be always the same, but in each situation will only be a certain subset k of different tickets that the company that organizes the game has.

Input

The input consists of a line with the number k of tickets, with 1<k<100. Afterwards, and separated by lines in white, are given: the k tickets, the 15 numbers of each ticket separated by spaces and distributed in 3 lines of 5 numbers.

A line with the number q of different situations follows, with 1≤ q≤ 1000. A situation is defined by the subset of size n of the k ticktets that are played and it is described by the number n (1≤ nk) and the indices i1, …, in, between 1 and k, of the n tickets that participate in the situation, all of them in the same line and separated by spaces. Finally, separated by a line in white, the 99 numbers of the lottery drum are given in the order that they go out, separated by spaces and changing of line every 10 numbers.

You are asked to solve 5 inputs like the ones described before in less than 1 second.

Output

Your program must print q lines, one per situation. Each line contains the sorted list of those tickets that are played in the situation and that should have been boufgt, that is, those ones that will receive a prize greater than 10 euros. It must print those indices in increasing order and separated by spaces. Print a line in white in case that there is not any profitable ticket.

Public test cases
  • Input

    5
    
    1 2 3 4 97
    5 6 7 8 98
    9 10 11 12 99
    
    1 2 3 4 97
    15 6 7 8 98
    9 10 11 12 99
    
    1 2 3 4 97
    25 6 7 8 98
    9 10 11 12 99
    
    1 2 3 4 97
    35 6 7 8 98
    9 10 11 12 99
    
    1 2 3 4 97
    45 6 7 8 98
    9 10 11 12 99
    
    5
    1 1
    2 1 2
    5 1 2 3 4 5
    3 1 2 3
    4 1 2 3 4
    
    1 2 3 4 5 6 7 8 9 10
    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29 30
    31 32 33 34 35 36 37 38 39 40
    41 42 43 44 45 46 47 48 49 50
    51 52 53 54 55 56 57 58 59 60
    61 62 63 64 65 66 67 68 69 70
    71 72 73 74 75 76 77 78 79 80
    81 82 83 84 85 86 87 88 89 90
    91 92 93 94 95 96 97 98 99
    

    Output

    1
    1 2
    
    1 2 3
    1 2 3 4
    
  • Input

    5
    
    3 18 35 61 68
    4 24 41 64 75
    12 30 49 66 82
    
    24 35 60 82 93
    29 39 65 86 97
    34 48 66 87 99
    
    7 31 38 68 83
    12 33 46 75 87
    23 34 57 79 97
    
    11 19 45 51 74
    15 23 49 55 94
    16 42 50 66 99
    
    2 17 28 46 66
    7 19 37 49 83
    16 23 39 64 96
    
    7
    1 3
    2 5 4
    3 3 1 2
    2 4 3
    4 3 5 4 1
    5 1 2 3 4 5
    4 1 4 2 3
    
    6 48 97 8 19 66 49 42 95 11
    93 51 79 40 7 47 80 26 37 44
    86 89 25 72 17 31 15 58 76 57
    46 5 61 62 1 4 23 30 55 2
    9 90 64 56 12 91 24 45 21 39
    99 75 83 32 29 78 59 16 22 13
    94 84 77 27 33 85 81 53 69 60
    28 68 67 73 87 70 35 10 43 52
    63 36 65 38 3 14 50 92 34 96
    18 20 71 74 54 41 88 98 82 
    

    Output

    3
    5
    3
    3 4
    3 5
    3 5
    3 4
    
  • Information
    Author
    Omer Giménez
    Language
    English
    Translator
    Carlos Molina
    Original language
    Spanish
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++