MERGSORT - Mergesort

no tags 

Simple. Sort the numbers on the standard input using the merge sort algorithm. Don't try to cheat by just calling your build in functions... I can see your source.

Input

On the standard input you will receive N (1 <= N <= 100000). Each number will fit in 32-bit integer

Output

Output the same integers in a sorted manner. Smallest to largest.

Example

Input:
7 3 2 5 4 3

Output:
2 3 3 4 5 7

hide comments
bansal: 2012-08-28 20:30:17

how will i know how many numbers are there ?????

Felipe Lima [UFS]: 2012-06-04 23:48:52

Anurag, the input is finished with end of file

Anurag Atri: 2011-03-14 03:19:06

how will i know how many numbers are there ?Or how can i know the end of input .

যোবায়ের: 2009-09-23 17:23:27

Number of inversions can also be counted by quicksort, but a bit tedious.
A problem can be mentioned at UVA OJ, 10810, ULTRA QUICK SORT

David Pìgøímek (Davpe): 2009-03-08 18:49:33

I think, this problem is really good, finally something, that forces me to program MergeSort ;). But it should be in tutorial, so no one could bother cheating.

.:: Pratik ::.: 2009-11-03 13:49:41

why is SPOJ going down these days?

Brian Bi: 2009-03-02 21:35:19

How about counting the number of inversions in the sequence? It's doable with mergesort but not any other sort (I think), and is an intrinsic property of the sequence, whereas the left/right switch count seems a bit... ad hoc. For example, given the sequence 3 1 2, the number of switches depends on whether you split it as 3 | 1 2 or 3 1 | 2.

Last edit: 2009-03-02 21:35:19
Navin Parakkal: 2009-03-01 01:43:42

can the author really look at the source ?

Srinivas Iyengar: 2009-02-28 07:49:45

Well I guess you have a valid Point. The Author should have asked about the number of swaps or something that was solely related to MergeSort.

Miorel-Lucian Palii: 2009-02-28 06:17:29

By the way, you can see my source, but I can obfuscate it. ;)


Added by:Nikola P Borisov
Date:2008-11-17
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET