import math import sys from time import clock def sort(n): global arr i = 1 while i < len(array): index = array[i] j = i - 1 while j >= 0 and index < array[j]: array[j + 1] = array[j] j -= 1 array[j + 1] = index i += 1 def main(): global array start=clock() f=open("in12_8.txt","r") n=int(f.readline()) array=f.readline().split(",") w=open("out_12_8.txt","w") for i in range(0,len(array)): array[i]=int(array[i]) sort(n) i=0 while(len(array)!=1): w.write("("+str(array[0])+","+str(array[1])+")"+"\n") array[0]=array[0]+array[1] del array[1] sort(len(array)) n=n-1 i+=1 end=clock() time=end-start w.write("\n"+str(array[0])) memory=sys.getsizeof(i)+sys.getsizeof(n)+sys.getsizeof(array)+sys.getsizeof(f)+sys.getsizeof(w) w.write("\nMemory Used:"+str(memory)) w.write("\nExecution Time:"+str(time)) main()