#C14319. Segregate and Sort Mixed List

    ID: 43955 Type: Default 1000ms 256MiB

Segregate and Sort Mixed List

Segregate and Sort Mixed List

You are given a list of n elements which can be either integers or strings. Your task is to separate the integers and strings into two different lists and then sort each list in ascending order using the insertion sort algorithm. Note that you should not use any built-in sorting functions.

The insertion sort algorithm works by iterating through an array and inserting each element into its correct position in the already sorted portion of the array. Its time complexity is given by $O(n^2)$ in the worst case.

Example:

Input:
6
3
apple
1
banana
2
cherry

Output: 1 2 3 apple banana cherry

</p>

If an element can be converted to an integer, consider it an integer; otherwise, treat it as a string.

inputFormat

The first line of input contains an integer n, the number of elements in the list. The following n lines each contain one element. An element is considered an integer if it can be parsed as a number, otherwise it is considered a string.

For example:

6
3
apple
1
banana
2
cherry

outputFormat

The output consists of two lines. The first line contains the sorted integers (in ascending order) separated by a space. The second line contains the sorted strings (in ascending order) separated by a space. If there are no integers or no strings, output an empty line accordingly.

For example:

1 2 3
apple banana cherry
## sample
6
3
apple
1
banana
2
cherry
1 2 3

apple banana cherry

</p>