1. 

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 400 - Unix ls
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=98&problem=341&mosmsg=Submission+received+with+ID+8015369
*
* @author Evgeni Pavlidis
* @version 1.0, 06/02/2010
*
* Method : Ad hoc
* Status : Accepted
* Runtime: 1.364
*/

import java.io.*;
import java.util.*;

class Main {
public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

List<String> list = new ArrayList<String>();

String input;
int n, max, columns, rows, pos = 0;

while((input = reader.readLine()) != null)
{
max = 0;
list.clear();

n = Integer.parseInt(input);
for(int w = 0; w < n; w++)
{
input = reader.readLine();
list.add(input);
if(input.length() > max)
max = input.length();
}

Collections.sort(list);
columns = (60 - max) / (max+2) + 1;
rows = (list.size()+columns-1) / columns;

System.out.println("------------------------------------------------------------");

for(int r = 0; r < rows; r++)
{
pos = r;
for(int c = 0; c < columns; c++, pos += rows)
if(pos < list.size())
System.out.printf("%-" + (max + 2) + "s", list.get(pos));

System.out.println();
}

}
}
}