// File: /workspace/github_cpp_makefile_star2_O2/noizebox[P]zipfsong/zipfsong_cpp_fast.cpp
// Function: main
int main()
{
    std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();

    std::ios::sync_with_stdio (false);
    std::string input;
    std::getline(std::cin, input);
    auto input_view = std::string_view(input); 
    int pos = input_view.find(" ");
    int no_songs = unsafe_strtol(input_view.substr(0, pos));
    int no_outputs = unsafe_strtol(input_view.substr(pos + 1));

    // Assume max 30 chars per title and 20 chars for number of plays + whitespaces
    size_t mem_size = no_songs * 50;
    char* string_area = static_cast<char*>(malloc(mem_size));

    std::vector<Song> song_list;
    parse_songs(no_songs, song_list, string_area, mem_size);
    stable_sort(song_list.begin(), song_list.end(), std::greater<Song>());
    print_songs(song_list, no_outputs);
    delete string_area;

    std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
    std::cout << "Ex. time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << " ms" << std::endl;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
callq 0x2170
movq %rax, %rbx
xorl %edi, %edi
callq 0x2070
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x3b59(%rip), %rdi      # 0x5fe0
leaq 0x18(%rsp), %rsi
callq 0x2030
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x38(%rsp), %r14
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
leaq 0x1b5f(%rip), %rsi      # 0x400d
movq %r14, %rdi
xorl %edx, %edx
callq 0x273a
movq %rax, %r15
movslq %r15d, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2766
shlq $0x20, %r15
movq %rsp, %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x26d1
movq %rax, %r14
movabsq $0x100000000, %rsi      # imm = 0x100000000
addq %r15, %rsi
sarq $0x20, %rsi
leaq 0x38(%rsp), %rdi
pushq $-0x1
popq %rdx
callq 0x2766
movq %rsp, %r13
movq %rax, (%r13)
movq %rdx, 0x8(%r13)
movq %r13, %rdi
callq 0x26d1
movq %rax, %r15
movabsq $0x3200000000, %rbp     # imm = 0x3200000000
imulq %r14, %rbp
sarq $0x20, %rbp
movq %rbp, %rdi
callq 0x2180
movq %rax, %r12
xorps %xmm0, %xmm0
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
movq %rsp, %rsi
movl %r14d, %edi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x232c
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x2a5b
movq %rsp, %rdi
movl %r15d, %esi
callq 0x23fe
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x2120
callq 0x2170
movq %rax, %r14
movq 0x3a50(%rip), %rdi      # 0x5fd0
leaq 0x1a7d(%rip), %rsi      # 0x4004
callq 0x2100
movq %rax, %rdi
subq %rbx, %r14
movl $0xf4240, %ecx          # imm = 0xF4240
movq %r14, %rax
cqto
idivq %rcx
movq %rax, %rsi
callq 0x20f0
leaq 0x1a61(%rip), %rsi      # 0x400f
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20b0
movq %rsp, %rdi
callq 0x2a36
leaq 0x18(%rsp), %rdi
callq 0x20a0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25ee
jmp 0x25e7
jmp 0x25e7
movq %rax, %rbx
jmp 0x25f9
jmp 0x25ee
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2a36
leaq 0x18(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x21e0
nop