This page is still under construction.

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

Median

Time limit1sMemory limit128 MB

Summary
For each group, print the middle value in input order, or the average of the two middle values when the count is even.
Level

Easy1 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

The median of a group of values is the value in the middle. The count of values below the median equals the count above it.

Let the whole group be d1,d2,d3,…,dnd_1, d_2, d_3, \dots, d_n.

If nn is odd, the median is the value in position (n+1)/2(n+1)/2.

Median=d(n+1)/2\text{Median} = d_{(n+1)/2}

If nn is even, the median is the average of the values in positions n/2n/2 and n/2+1n/2+1.

Median=dn/2+dn/2+12\text{Median} = \frac{d_{n/2} + d_{n/2+1}}{2}

Positions follow the order in which the values appear in the input. Do not sort the values.

Input

Each line holds one group of values. The first integer on a line is nn, the number of values in that group, and the nn values follow it. Every value is an integer between 11 and 10610^6. The input has at most 100 lines, and one line holds at most 100 values. The last line holds a single 0 and marks the end of the input.

Output

For each group, print its median on its own line, in input order. Each line starts with Case n:, then one space, then the median. Here nn is the group number counting from 1. Print the median with one digit after the decimal point.

Examples1

  1. Example 1

    Input
    5 1 2 3 4 5
    7 100 102 308 305 751 999 1005
    8 48 59 59 60 61 61 61 62
    14 2 3 5 7 11 13 17 19 23 29 31 37 41 43
    0
    
    Expected output
    Case 1: 3.0
    Case 2: 305.0
    Case 3: 60.5
    Case 4: 18.0