small-is-cute
Source: hackerearth
Difficulty: EASY

Problem Statement
As they say, small is cute and beautiful.

Given N distinct positive integers, find the smallest number that can be formed by concatenating all of them.
Input Format
The first line of the input file contains a positive integer N. Then N lines follow.
Each line contains a single positive integer K.

Output Format
Output the smallest possible number that can be formed by concatenating all the numbers.

Constraints
1 ≤ N ≤ 5000
1 ≤ K ≤ 10^15

SAMPLE INPUT
5
14
66
907
1234567890
9876543210

SAMPLE OUTPUT
123456789014669079876543210


def func(a,b):
	if(len(a) != len(b)):
		#a = int(a)
		#b = int(b)
		str1 = a + b   
		str2 = b + a
		if str1 > str2:
			return 1
		elif str1 == str2:
			return 0
		else:
			return -1
	else:
		if a > b:
			return 1
		elif a==b:
			return 0
		else:
			return -1
lines = int(input())
lst = []
for i in range(lines):
	lst.append(input())
lst.sort(func)
res = ""
for i in lst:
	res = res + i
print((int(res)))


def cmp2(x,y):
	if len(x)==len(y):
		return cmp(x,y)
	m=min(len(x),len(y))
	if cmp(x[:m],y[:m]):
		return cmp(x,y)
	
	if len(x)>len(y):
		return cmp(x[len(y):],y)
	return 	cmp(x,y[len(x):])
x=sorted([input().strip() for x in range(eval(input()))],cmp2)

print("".join(x))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
def func(a,b):
	if(len(a) != len(b)):
		#a = int(a)
		#b = int(b)
		str1 = a + b   
		str2 = b + a
		if str1 > str2:
			return 1
		elif str1 == str2:
			return 0
		else:
			return -1
	else:
		if a > b:
			return 1
		elif a==b:
			return 0
		else:
			return -1
lines = int(input())
lst = []
for i in range(lines):
	lst.append(input())
lst.sort(func)
res = ""
for i in lst:
	res = res + i
print((int(res)))