// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
callq 0x1120
movq %rax, %rbx
xorl %edi, %edi
callq 0x1050
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
movq 0x3b50(%rip), %rdi      # 0x4fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %edx
movq 0x3b35(%rip), %rdi      # 0x4fe0
leaq 0x38(%rsp), %rsi
callq 0x1180
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
leaq 0x58(%rsp), %r14
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
leaq 0x1b3b(%rip), %rsi      # 0x300d
xorl %r12d, %r12d
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x187a
movslq %eax, %rsi
movq %rax, %rdx
shlq $0x20, %rdx
movq (%r14), %rcx
movq 0x8(%r14), %rax
cmpq %rsi, %rcx
cmovbq %rcx, %rsi
testq %rsi, %rsi
je 0x151f
xorl %edi, %edi
xorl %r12d, %r12d
movsbq (%rax,%rdi), %r8
leaq (%r12,%r12,4), %r9
leaq (%r8,%r9,2), %r12
addq $-0x30, %r12
incq %rdi
cmpq %rdi, %rsi
jne 0x1506
movabsq $0x100000000, %rsi      # imm = 0x100000000
addq %rsi, %rdx
sarq $0x20, %rdx
cmpq %rdx, %rcx
jb 0x16ff
xorl %r14d, %r14d
cmpq %rdx, %rcx
je 0x155c
xorl %r14d, %r14d
movsbl (%rax,%rdx), %esi
leal (%r14,%r14,4), %edi
leal (%rsi,%rdi,2), %r14d
addl $-0x30, %r14d
incq %rdx
cmpq %rdx, %rcx
jne 0x1544
movabsq $0x3200000000, %rax     # imm = 0x3200000000
movq %r12, %r13
imulq %rax, %r13
sarq $0x20, %r13
movq %r13, %rdi
callq 0x1130
movq %rax, %r15
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movl %r12d, %edi
movq %rax, %rdx
movq %r13, %rcx
callq 0x12ec
movq (%rsp), %r13
movq 0x8(%rsp), %r12
cmpq %r12, %r13
je 0x161e
movq %r12, %rax
subq %r13, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
leaq 0x1(%rcx), %rax
shrq $0x3f, %rax
leaq (%rcx,%rax), %rdx
incq %rdx
sarq %rdx
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x1ab6
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0x15fc
movq 0x28(%rsp), %rcx
movq %r13, %rdi
movq %r12, %rsi
callq 0x1bca
jmp 0x1607
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b3d
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x10d0
movq %rsp, %rdi
movl %r14d, %esi
callq 0x13ea
movl $0x1, %esi
movq %r15, %rdi
callq 0x10d0
callq 0x1120
movq %rax, %r14
movq 0x398b(%rip), %rdi      # 0x4fd0
leaq 0x19b8(%rip), %rsi      # 0x3004
movl $0xa, %edx
callq 0x1100
subq %rbx, %r14
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r14, %rax
imulq %rcx
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x12, %rdx
addq %rdx, %rsi
movq 0x3952(%rip), %rdi      # 0x4fd0
callq 0x10a0
movq %rax, %rbx
leaq 0x1982(%rip), %rsi      # 0x300f
movl $0x3, %edx
movq %rax, %rdi
callq 0x1100
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x16d7
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x16ee
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x10d0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1927(%rip), %rdi      # 0x302d
leaq 0x1906(%rip), %rsi      # 0x3013
xorl %eax, %eax
callq 0x1140
movq %rax, %rbx
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x10d0
jmp 0x173e
jmp 0x173b
jmp 0x1734
movq %rax, %rbx
jmp 0x1754
jmp 0x173b
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1754
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x176b
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1170
nop