This page is still under construction.

Parts of this page are still being built. What you see may change.

Building Snowmen

Interview

Time limit1sMemory limit128 MB

Summary
Given snowball diameters, find the maximum number of triples where each triple's sizes satisfy the stacking ratio inequalities.
Level

Medium6 of 10

Topics
Greedy, Sorting, Two pointers, Binary search
Solved
No attempts yet

Problem

You want to build an army of snowmen. To do so, you have gathered a bunch of snowballs of varying sizes. Each snowman is built by stacking three snowballs on top of one another: first choose a snowball for the base, then a smaller one for the middle, and finally an even smaller one for the top.

Each snowball has a diameter dd. For a given snowman, let the diameter of the base snowball be dbd_b, the diameter of the middle snowball be dmd_m, and the diameter of the top snowball be dtd_t. Then both of the following inequalities must hold:

  • 2db≥3dm2 d_b \geq 3 d_m
  • 2dm≥3dt2 d_m \geq 3 d_t

Compute the maximum number of snowmen that can be built from the available snowballs while satisfying these conditions.

Input

The first line contains the number of data sets KK. Then KK data sets follow, each in the form below.

The first line of each data set contains the number of snowballs NN (3≤N≤10003 \leq N \leq 1000). The next line contains NN integers, each between 11 and 10001000 inclusive. The ii-th integer is the diameter of the ii-th snowball.

Output

For each data set, first output Data Set x: on its own line, where xx is the data set's number. On the next line, output the maximum number of proper snowmen that can be completed. Separate consecutive data sets with a single blank line.

Examples1

  1. Example 1

    Input
    2
    6
    3 5 1 2 6 4
    6
    3 5 1 3 6 4
    
    Expected output
    Data Set 1:
    2
    
    Data Set 2:
    1