#!/usr/bin/env python
import random
from time import time
def mergeSort(arr):
    if len(arr)>1:
        mid = len(arr)//2
        lefthalf = arr[:mid]
        righthalf = arr[mid:]
        mergeSort(lefthalf)
        mergeSort(righthalf)
        i=0
        j=0
        k=0
        while i < len(lefthalf) and j < len(righthalf):
            if lefthalf[i] < righthalf[j]:
                arr[k]=lefthalf[i]
                i=i+1
            else:
                arr[k]=righthalf[j]
                j=j+1
            k=k+1

        while i < len(lefthalf):
            arr[k]=lefthalf[i]
            i=i+1
            k=k+1

        while j < len(righthalf):
            arr[k]=righthalf[j]
            j=j+1
            k=k+1

def Kelement(arr,k):
    return arr[k-1]

def listaAleatorios(n):
    lista = []
    for i in range(n):
         lista.append(i)

    return lista
arr = listaAleatorios(6400000)
random.shuffle(arr)
tiempo_inicial = time()

mergeSort(arr)
a = Kelement(arr,10)
tiempo_final = time()

tiempo_ejecucion = tiempo_final - tiempo_inicial
print a
print 'El tiempo de ejecucion fue:',tiempo_ejecucion
