问题 AB: DNA sorting

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:339 解决:106

题目描述

序列“未排序程度”的一个计算方式是元素乱序的元素对个数。例如:在单词序列“DAABEC'”中,因为D大于右边四个单词,E大于C,所以计算结果为5。这种计算方法称为序列的逆序数。序列“AACEDGG”逆序数为1(E与D)——近似排序,而序列``ZWQM'' 逆序数为6(它是已排序序列的反序)。 你的任务是分类DNA字符串(只有ACGT四个字符)。但是你分类它们的方法不是字典序,而是逆序数,排序程度从好到差。所有字符串长度相同。

输入

The first line contains two integers: a positive integer n (0< n \leq 500<n50) giving the length of the strings; and a positive integer m (0< m \leq 1000<m100) giving the number of strings. These are followed by m lines, each containing a string of length n.

输出

Output the list of input strings, arranged from most sorted'' to least sorted''. Since two strings can be equally sorted, then output them according to the orginal order.


样例输入 复制

10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

样例输出 复制

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA