#C333. Enhanced Merge Sort

    ID: 46745 Type: Default 1000ms 256MiB

Enhanced Merge Sort

Enhanced Merge Sort

This problem requires you to implement an enhanced merge sort algorithm that can sort a list of numbers in either ascending or descending order. Merge sort is a classic divide and conquer algorithm with a worst-case time complexity of $O(n\log n)$.

You will be given the sort order and a list of numbers via standard input. Your program should output the sorted list to standard output.

inputFormat

The input is read from standard input and consists of three lines:

  • The first line is a string which is either ascending or descending indicating the sort order.
  • The second line is an integer N representing the number of elements.
  • The third line contains N space-separated numbers (each can be an integer or a floating-point number).

outputFormat

Output a single line containing the sorted numbers in the specified order, separated by a single space.

## sample
ascending
5
5 4 3 2 1
1 2 3 4 5