/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2008 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P05MergeSort {
  private static final String FileInputName = "MSort.in";
  private static final String FileOutputName = "MSort.out";

  private static void mergeSort(int arr[]) {
    if (arr.length <= 1)
      return;
    int v1[] = new int[arr.length / 2];
    int v2[] = new int[arr.length - v1.length];
    System.arraycopy(arr, 0, v1, 0, arr.length/2);
    System.arraycopy(arr, arr.length/2, v2, 0, arr.length-v1.length);
    mergeSort(v1);
    mergeSort(v2);
    int i1 = 0, i2 = 0;
    for (int k = 0; k < v1.length + v2.length;)
      if ((i2 >= v2.length) || (i1 < v1.length && v1[i1] <= v2[i2])) {
        arr[k++] = v1[i1++];
      } else {
        arr[k++] = v2[i2++];      
      }
  }

  public static void main(String[] args) throws IOException {
    Scanner sc = null;
    PrintStream out = null;
    try {
      out = new PrintStream(new File(FileOutputName));
      sc = new Scanner(new File(FileInputName));
      List<Integer> list = new ArrayList<Integer>();
      while (sc.hasNextInt()) {
          list.add( sc.nextInt() );
      }        
      int arr[] = new int[list.size()];
      for(int i=0; i<list.size(); i++)
        arr[i] = list.get(i);
      mergeSort(arr);
      for (int i = 0; i < arr.length; i++) {
        out.print(arr[i]);
        out.print(' ');
      }
    } finally {
      if (sc != null) {
        sc.close();
      }
      if (out != null) {
        out.close();
      }
    }
  }
}

