#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

const size_t screen_width = 80;
const size_t max_asterix = screen_width - 3 - 1;

int main()
{
    // ============================ INPUT ============================
    size_t num_count=0;
    cerr << "Enter number count: ";
    cin >> num_count;
    vector<double> numbers(num_count);
    cerr << "Enter " << num_count << " numbers\n";

    for (int i = 0; i < num_count; ++i)
        cin >> numbers[i];

    cerr << "Enter bins count:";
    size_t bin_count = 0;
    cin >> bin_count;

    // ============================ LOGIC ============================

    double min = numbers[0];
    double max = numbers[0];

    for (double x : numbers)
    {
        if (x < min)
        {
            min = x;
        }
        else if (x > max)
        {
            max = x;
        }
    }

    vector<size_t> bins(bin_count);
    double bins_size = (max - min) / bin_count;

    for (size_t i = 0; i < num_count; i++)
    {
        bool found = false;
            for (size_t j = 0; (j < bin_count - 1) && !found; j++)
            {
                auto lo = min + j * bins_size;
                auto hi = min + (j + 1) * bins_size;
                if ((lo <= numbers[i]) && (numbers[i] < hi))
                {
                    bins[j]++;
                    found = true;
                }
            }
        if (!found) 
        {
            bins[bin_count - 1]++;
        }
    }

    size_t max_bin = bins[0];

    for (size_t i=0; i < bin_count; i++)
    {
        if (max_bin < bins[i])
        {
            max_bin = bins[i];
        }
    }
    //Округление и подсчет символьной длины размера корзины для выравнивания по крайнему символу границы корзины
    stringstream bins_size_round;
    bins_size_round << setiosflags(ios::fixed) << setprecision(2) << bins_size;
    bins_size_round >> bins_size;
    ostringstream bin_step;
    bin_step << (max + bins_size);
    string bin_step_string = bin_step.str();
    size_t line_size = bin_step_string.length();
    string line(line_size, ' ');

    // ============================ OUTPUT ============================

    for (size_t i = 0; i < bin_count; i++) 
    {
        cout << line;
        if ((bins[i] < 100) && (max_bin >= 100))
        {
            cout << " ";
        }
        if ((bins[i] < 10) && (max_bin >= 10))
        {
            cout << " ";
        }
        cout << bins[i] << "|";
        size_t height = 0;

        if (max_bin > 76)
        {
            height = max_asterix * (static_cast<double>(bins[i]) / max_bin);
        }
        else
        {
            height = bins[i];
        }
        for(size_t j=0; j<height;j++)
        {
            cout << "*";
        }
        if (i != bin_count-1)
        {
            cout << "\n" << (min + bins_size * (i + 1));
        }
        cout << "\n";
    }

}