import java.util.Scanner;

/**
 * @author zq
 */
public class Main {
    public static void main(String[] args) {
        //两种排序方式
        Scanner scanner = new Scanner(System.in);
       
        while (scanner.hasNextInt()){
            int n = scanner.nextInt();
            String[] s = new String[n];
            for (int i = 0; i < n; i++) {
                s[i] = scanner.next();
            }
        
        if (zi(s)&&chang(s)){
            System.out.println("both");
        }else if (zi(s)){
            System.out.println("lexicographically");
        }else if (chang(s)){
            System.out.println("lengths");
        }else {
            System.out.println("none");
        }
    }
    }
    //判断是否按字典序排列
    public static boolean zi(String[] s){
        for (int i = 0; i < s.length-1; i++) {
            if (s[i].compareTo(s[i+1])>0){
                return false;
            }
            
        }
        return true;

    }
    //判断是否按长度排
    public static boolean chang(String[] strings){
        for (int i = 0; i < strings.length-1; i++) {
            if (strings[i].length()>strings[i+1].length()){
                return false;
            }
        }
        return true;
    }

}