AtCoder Beginner Contest 042 - Iroha Loves Strings (ABC Edition)

Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.
She will concatenate all of the strings in some order, to produce a long string.
Among all strings that she can produce in this way, find the lexicographically smallest one.
Here, a string s=s_1s_2s_3...s_n is lexicographically smaller than another string t=t_1t_2t_3...t_m if and only if one of the following holds:

 - There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.
 - s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.

-----Constraints-----
 - 1 ≦ N, L ≦ 100
 - For each i, the length of S_i equals L.
 - For each i, S_i consists of lowercase letters.

-----Input-----
The input is given from Standard Input in the following format:
N L
S_1
S_2
:
S_N

-----Output-----
Print the lexicographically smallest string that Iroha can produce.

-----Sample Input-----
3 3
dxx
axx
cxx

-----Sample Output-----
axxcxxdxx

The following order should be used: axx, cxx, dxx.

Difficulty: EASY

Starter code:

Solutions:
(N, L) = map(int, input().split())
print(''.join(sorted([input() for i in range(N)])))


(n, l) = map(int, input().split())
print(*sorted([input() for _ in range(n)]), sep='')


(a, b) = map(int, input().split())
c = list((input() for _ in range(a)))
c.sort()
print(''.join(c))


(N, L) = map(int, input().split())
S = [input() for i in range(N)]
S.sort()
print(*S, sep='')


(a, b) = map(int, input().split())
s = sorted([input() for i in range(a)])
print(*s, sep='')


(n, l) = map(int, input().split())
A = [input() for _ in range(n)]
print(''.join(sorted(A)))


print(''.join(sorted([input() for i in range(int(input().split()[0]))])))


(N, L) = map(int, input().split())
s = [input() for i in range(N)]
s.sort()
print(''.join(s))


(N, L) = map(int, input().split())
S = sorted([input() for l in range(N)])
print(''.join(S))


(N, _) = map(int, input().split())
print(''.join(sorted([input() for _ in range(N)])))


(N, L) = map(int, input().split())
print(*sorted([input() for n in range(N)]), sep='')


(n, l) = map(int, input().split())
lst = []
for i in range(n):
	s = input()
	lst.append(s)
lst = sorted(lst)
print(''.join(lst))


(m, l) = map(int, input().split())
s = sorted([input() for i in range(m)])
print(*s, sep='')


import collections
import sys
m = collections.defaultdict(int)
line = input()
tokens = line.split()
n = int(tokens[0])
strings = []
for i in range(n):
	s = input()
	strings.append(s)
print(''.join(sorted(strings)))


(a, b) = map(int, input().split())
s = sorted([input() for x in range(a)])
print(''.join(s))


(n, l) = map(int, input().split())
s = [input() for _ in range(n)]
s.sort()
print(''.join(s))


(a, b) = map(int, input().split())
c = sorted([input() for i in range(a)])
print(''.join(c))


(n, l) = map(int, input().split())
a = sorted([input() for i in range(n)])
print(''.join(a))


(N, L) = map(int, input().split())
word = []
count = 0
while N > count:
	S = input()
	word.append(S)
	count += 1
word = sorted(word)
ans = ''.join(word)
print(ans)


(n, l) = map(int, input().split())
s_l = [str(input()) for _ in range(n)]
s_l = sorted(s_l)
print(''.join(s_l))


(n, l) = map(int, input().split())
a = [input() for _ in range(n)]
a.sort()
print(*a, sep='')


(n, l) = [int(x) for x in input().split()]
la = []
for i in range(n):
	la.append(str(input()))
la.sort()
print(''.join((str(x) for x in la)))


(N, L) = map(int, input().split())
print(''.join(sorted([input() for _ in [''] * N])))


(n, m) = map(int, input().split())
s = sorted([input() for i in range(n)])
print(''.join(s))


n = list(map(int, input().split()))[0]
ss = list(sorted([input() for _ in range(n)]))
print(''.join(ss))


(n, l) = list(map(int, input().split()))
A = [input() for _ in range(n)]
A.sort()
print(''.join(A))


(n, l) = map(int, input().split())
string_list = [input() for i in range(n)]
string_list.sort()
ans = string_list[0]
for i in range(1, n):
	ans += string_list[i]
print(ans)


(n, l, *s) = open(0).read().split()
print(''.join(sorted(s)))


(_, _, *S) = open(0).read().split()
print(''.join(sorted(S)))


print(''.join(sorted(open(0).read().split()[2:])))


(a, b) = map(int, input().split())
a = [input() for i in range(a)]
a.sort()
print(''.join(a))


(n, l) = map(int, input().split())
s = [input() for _ in range(n)]
an = ''
for _ in range(n):
	an += min(s)
	s.remove(min(s))
print(an)


(N, L, *S) = map(str, open(0).read().split())
S.sort()
print(''.join(S))


(n, l) = map(int, input().split())
ss = [input() for i in range(n)]
ss.sort()
print(''.join(ss))


(n, l) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
a.sort()
print(''.join(a))


def main():
	(N, L) = list(map(int, input().split()))
	S = []
	for i in range(N):
		s = input()
		S.append(s)
	S.sort()
	ans = ''.join(S)
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, L) = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
print(''.join(S))


(N, L) = map(int, input().split())
w = []
for _ in range(N):
	w.append(input())
w.sort()
print(''.join(w))


n = int(input().split()[0])
print(''.join(sorted([input() for _ in [0] * n])))


(N, L) = map(int, input().split())
array = [str(input()) for i in range(N)]
array = sorted(array)
ans = ''
for j in array:
	ans = ans + j
print(ans)


(n, l) = map(int, input().split())
s = [input() for _ in [0] * n]
print(''.join(sorted(s)))


from typing import List

def answer(n: int, l: int, s: List[str]) -> str:
	return ''.join(sorted(s))

def main():
	(n, l) = map(int, input().split())
	s = [input() for _ in range(n)]
	print(answer(n, l, s))

def __starting_point():
	main()
__starting_point()


print(''.join(sorted([input() for _ in [''] * int(list(map(int, input().split()))[0])])))


nl = list(map(int, input().split()))
N = nl[0]
L = nl[1]
ss = [input() for i in range(N)]
ss.sort()
res = ''
for i in ss:
	res = res + i
print(res)


(N, L) = map(int, input().split())
word_list = [input() for i in range(N)]
word_list.sort()
for i in word_list:
	print(i, end='')
print()


(N, L) = map(int, input().split())
S = [input() for n in range(N)]
S.sort()
T = ''.join(S)
print(T)


(n, m) = map(int, input().split())
print(''.join(sorted((input() for _ in range(n)))))


(a, b) = map(int, input().split())
s = []
for i in range(a):
	s.append(input())
s.sort()
for i in range(a):
	print(s[i], end='')


(n, _) = map(int, input().split())
a = sorted([input() for _ in [0] * n])
print(*a, sep='')


(N, L) = map(int, input().split())
text_list = [input() for _ in range(N)]
sorted_list = sorted(text_list)
print(''.join(sorted_list))


(n, l) = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(input())
s.sort()
print(''.join(s))


(n, l) = map(int, input().split())
s = sorted([input() for i in range(n)])
ans = ''
for i in range(n):
	ans += s[i]
print(ans)


import itertools
(n, l) = map(int, input().split())
li = [list(input().split()) for i in range(n)]
li.sort()
lis = list(itertools.chain.from_iterable(li))
print(''.join(lis))


(N, L) = map(int, input().split())
List = sorted([input() for i in range(N)])
print(*List, sep='')


(n, l) = input().split()
s = [input() for _ in range(int(n))]
print(''.join(sorted(s)))


(n, L) = map(int, input().split())
s = sorted([input() for _ in range(n)])
print(''.join(s))


(N, L) = list(map(int, input().split()))
S = []
for i in range(N):
	S.append(input())
S.sort()
out = ''
for i in range(N):
	out = out + S[i]
print(out)


(N, L) = map(int, input().split())
mat = []
for i in range(N):
	mat.append(input())
while i <= N:
	FINISH = 0
	for i in range(N - 1):
		if mat[i] > mat[i + 1]:
			tmp = mat[i]
			mat[i] = mat[i + 1]
			mat[i + 1] = tmp
			FINISH += 1
	if FINISH == 0:
		break
for i in range(N):
	print(mat[i], end='')


import sys

def readint():
	return int(sys.stdin.readline())

def readints():
	return tuple(map(int, sys.stdin.readline().split()))

def readintslist(n):
	return [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)]

def main():
	(n, l) = readints()
	s = [input() for _ in range(n)]
	s = sorted(s)
	print(*s, sep='')

def __starting_point():
	main()
__starting_point()


(n, l) = map(int, input().split())
s = [input() for _ in range(n)]
s = sorted(s)
for i in s:
	print(i, end='')


(n, l) = map(int, input().split())
li = [input() for i in range(n)]
sortli = sorted(li)
print(''.join(sortli))


(n, l) = map(int, input().split())
List = sorted([input() for i in range(n)])
print(*List, sep='')


def __starting_point():
	(N, L) = list(map(int, input().split()))
	si = []
	for i in range(N):
		si.append(str(input()))
	si.sort()
	print(''.join(si))
__starting_point()


(n, l) = map(int, input().split())
a = [input() for x in range(n)]
a.sort()
print(''.join(a))


print(*sorted(open(0).read().split()[2:]), sep='')


from collections import Counter
import math
import statistics
import itertools
(a, b) = list(map(int, input().split()))
lis = [input() for i in range(a)]
ra = a - 1
for i in range(ra):
	for k in range(ra - i):
		if lis[k] > lis[k + 1]:
			a = lis[k]
			lis[k] = lis[k + 1]
			lis[k + 1] = a
print(''.join(lis))


(_, _, *s) = open(0).read().split()
s.sort()
print(*s, sep='')


nl = input().split()
N = int(nl[0])
L = int(nl[1])
lst = []
for i in range(N):
	lst.append(input())
lst.sort()
ans = ''
for s in lst:
	ans += s
print(ans)


(N, L) = map(int, input().split())
S = []
for i in range(N):
	S.append(input())
S.sort()
for i in range(N):
	print(S[i], end='')


(a, b) = map(int, input().split())
print(''.join(sorted([input() for _ in range(a)])))


(x, y) = map(int, input().split())
print(''.join(sorted([input() for _ in range(x)])))


(n, l) = input().split()
s = [input() for i in range(int(n))]
s.sort()
print(''.join(s))


(N, L) = list(map(int, input().split()))
S = []
for i in range(N):
	S.append(input())
print(''.join(sorted(S)))


(n, l) = map(int, input().split())
t = list()
for i in range(n):
	s = input()
	t.append(s)
t.sort()
ans = ''
for j in range(n):
	ans += t[j]
print(ans)


a = input().split(' ')
s = [input() for i in range(int(a[0]))]
print(''.join(sorted(s)))


(n, k) = input().split()
print(''.join(sorted([input() for i in range(int(n))])))


(n, l) = map(int, input().split())
S = []
for i in range(n):
	s = input()
	S.append(s)
S.sort()
ans = ''
for i in range(n):
	ans += S[i]
print(ans)


(n, l) = input().split()
print(''.join(sorted(eval('input(),' * int(n)))))


(N, L) = input().split()
s = [input() for x in range(int(N))]
s.sort()
print(''.join(s))


def main():
	(N, L) = list(map(int, input().split()))
	Sn = [input() for i in range(N)]
	Sn2 = sorted(Sn)
	ans = ''
	for val in Sn2:
		ans = ans + val
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, l) = map(int, input().split())
s = [input() for i in range(n)]
s.sort()
print(*s, sep='')


a = input().split()
c = int(a[0])
strlist = []
d = ''
for i in range(c):
	b = input().split()
	strlist.append(b[0])
strlist.sort()
for i in range(c):
	d += strlist[i]
print(d)


(n, l) = map(int, input().split())
s = sorted((input() for k in range(n)))
print(''.join(s))


(n, l) = map(int, input().split())
words = [input() for i in range(n)]
words = list(sorted(words))
s = ''
for i in range(n):
	s += words[i]
print(s)


(N, L) = map(int, input().split())
S = [input() for i in range(N)]
S_sorted = sorted(S)
Word = ''.join(S_sorted)
print(Word)


(N, L) = map(int, input().split())
S = sorted([input() for _ in range(N)])
print(*S, sep='')


(n, l) = map(int, input().split())
print(''.join(sorted([input() for _ in '1' * n])))


(N, L) = map(int, input().split())
S = []
for i in range(N):
	array = input()
	S.append(array)
S.sort()
S = ''.join(S)
print(S)


(N, L) = map(int, input().split())
l = list()
for i in range(N):
	l.append(input())
print(*sorted(l), sep='')


(_, _, *s) = open(0).read().split()
print(''.join(sorted(s)))


import sys

def resultSur97(x):
	return x % (10 ** 9 + 7)

def __starting_point():
	nl = list(map(int, input().split()))
	x = nl[0]
	sList = [input() for _ in range(x)]
	sListSorted = sorted(sList)
	out = ''
	for s in sListSorted:
		out += s
	print('{}'.format(out))
__starting_point()


from sys import stdin, stdout
from time import perf_counter
import sys
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
(n, l) = map(int, input().split())
a = [input() for item in range(n)]
b = sorted(a)
print(''.join(b))


(N, L) = input().split()
ss = [input() for _ in range(int(N))]
print(''.join(sorted(ss)))


(N, L, *Ss) = open(0).read().split()
ans = ''
for s in sorted(Ss):
	ans += s
print(ans)


(N, L, *S) = open(0).read().split()
S.sort()
print(''.join(S))


import sys
input = sys.stdin.readline

def main():
	(n, l) = map(int, input().split())
	words = []
	words = [input().rstrip() for _ in range(n)]
	s_words = sorted(words, key=lambda x: x[0:])
	ans = ''
	for s_word in s_words:
		ans += s_word
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, L) = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
for s in S:
	print(s, end='')


import sys
input()
l = list(sys.stdin.read().split())
l.sort()
print(''.join(l))


print(''.join(sorted((input() for _ in range(int(input().split()[0]))))))


(n, l) = list(map(int, input().split()))
strList = []
for _ in range(0, n):
	strList.append(input())
strList.sort()
ans = ''
for i in range(0, n):
	ans += strList[i]
print(ans)


(n, l) = map(int, input().split())
sl = list((input() for _ in range(n)))
sl_s = sorted(sl)
print(*sl_s, sep='')


(N, L) = map(int, input().split())
str_list = []
for w in range(N):
	str_list.append(input())
output = ''.join(sorted(str_list))
print(output)


(n, l) = input().split(' ')
print(''.join(sorted([input() for x in range(int(n))])))


(N, L) = map(int, input().split())
S = []
for n in range(N):
	s = input()
	S.append(s)
S.sort()
print(''.join(S))


(_, _, *s) = open(0).read().split()
print(*sorted(s), sep='')


(N, L) = input().split()
(N, L) = (int(N), int(L))
S = []
count = 0
while count < N:
	str = input()
	S.append(str)
	count += 1
S_ord = sorted(S)
print(''.join(S_ord))


import math
from datetime import date

def main():
	line = input().split()
	n = int(line[0])
	k = int(line[1])
	a = []
	for i in range(n):
		s = input()
		a.append(s)
	ans = ''
	for x in sorted(a):
		ans += x
	print(ans)
main()


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
(n, l) = readInts()
S = sorted([input() for _ in range(n)])
print(''.join(S))


import sys
input()
print(''.join(sorted([x.rstrip() for x in sys.stdin.readlines()])))


(n, l) = map(int, input().split())
str = [input() for i in range(n)]
str.sort()
for i in str:
	print(i, end='')


main = list([int(x) for x in input().split()])
(n, l) = (main[0], main[1])
final = []
for i in range(n):
	string = input()
	final.append(string)
final.sort()
print(''.join(final))


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
a.sort()
print(*a, sep='')


def main():
	(n, l) = list(map(int, input().split()))
	s = sorted([input() for i in range(n)])
	print(''.join(s))

def __starting_point():
	main()
__starting_point()


print(''.join(sorted([input() for x in range(list(map(int, input().split()))[0])])))


n = int(input().split()[0])
s = [input() for i in [0] * n]
s.sort()
print(''.join(s))


(N, L) = map(int, input().split())
l = []
for _ in range(N):
	s = input()
	l.append(s)
l.sort()
for i in l:
	print(i, end='')


import sys
(N, L, *V) = sys.stdin.read().split()
print(*sorted(V), sep='')


(n, l) = map(int, input().split())
strings = []
for _ in range(n):
	s = input()
	strings.append(s)
strings.sort()
ans = ''
for string in strings:
	ans += string
print(ans)


(N, L, *s) = open(0).read().split()
print(''.join(sorted(s)))


(n, l) = map(int, input().split())
s = list((input() for i in range(n)))
s.sort()
a = ''
for i in range(n):
	a = a + s[i]
print(a)


(N, L) = map(int, input().split())
S = sorted(list((input() for _ in range(N))))
print(''.join(S))