//package geeksforgeek1;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
public class SortString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
TreeSet<String> set=new TreeSet<>();
String s[]=new String[n];
for(int i=0;i<n;i++)
{
s[i]=sc.next();
}
Arrays.sort(s);
System.out.println();
for(int i=0;i<s.length;i++)
{
if((i+1)<n&&s[i+1].length()>s[i].length())
{
System.out.println(s[i+1]);
System.out.println(s[i]);
i++;
}
else
{
System.out.println(s[i]);
}
}
}
}
it is giving no such element exception even it is running correctly on eclipse