import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Euler480 {

    static class Tuple {
        int[] arr;
        int remaining;

        Tuple(int[] a, int r) {
            arr = a;
            remaining = r;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Tuple tuple = (Tuple) o;
            return remaining == tuple.remaining && Arrays.equals(arr, tuple.arr);
        }

        @Override
        public int hashCode() {
            int result = Arrays.hashCode(arr);
            result = 31 * result + remaining;
            return result;
        }
    }

    static Map<Tuple, Long> dp = new HashMap<>();

    private static void reverseSort(int[] a) {
        Arrays.sort(a);
        for (int i = 0; i < a.length / 2; i++) {
            int temp = a[i];
            a[i] = a[a.length - 1 - i];
            a[a.length - 1 - i] = temp;
        }
    }

    private static long countSubtree(int[] counts, int remaining) {
        if (remaining == 0)
            return 1;

        int[] copy = counts.clone();
        reverseSort(copy);
        int len = copy.length;
        while (len > 0 && copy[len - 1] == 0) {
            len--;
        }
        int[] truncated = Arrays.copyOf(copy, len);
        Tuple key = new Tuple(truncated, remaining);

        Long val = dp.get(key);
        if (val != null) {
            return val;
        }

        long total = 1;
        for (int i = 0; i < truncated.length; i++) {
            if (truncated[i] == 0)
                continue;
            int[] next = truncated.clone();
            next[i]--;
            total += countSubtree(next, remaining - 1);
        }

        dp.put(key, total);
        return total;
    }

    private static String buildWord(int[] counts, int remaining, long pos) {
        if (pos == 1)
            return "";

        pos--;
        for (int c = 0; c < 26; c++) {
            if (counts[c] == 0)
                continue;
            counts[c]--;
            long cnt = countSubtree(counts, remaining - 1);
            if (cnt < pos) {
                counts[c]++;
                pos -= cnt;
                continue;
            }
            return (char) ('a' + c) + buildWord(counts, remaining - 1, pos);
        }
        return "";
    }

    private static long positionOf(int[] counts, int remaining, String target) {
        if (target.isEmpty())
            return 1;

        int first = target.charAt(0) - 'a';
        long pos = 1;

        for (int c = 0; c < first; c++) {
            if (counts[c] == 0)
                continue;
            int[] next = counts.clone();
            next[c]--;
            pos += countSubtree(next, remaining - 1);
        }

        int[] next = counts.clone();
        next[first]--;
        pos += positionOf(next, remaining - 1, target.substring(1));
        return pos;
    }

    public static void main(String[] args) {
        String source = "thereisasyetinsufficientdataforameaningfulanswer";
        int[] counts = new int[26];
        for (char ch : source.toCharArray()) {
            counts[ch - 'a']++;
        }

        long t1 = positionOf(counts.clone(), 15, "legionary") - 1;
        long t2 = positionOf(counts.clone(), 15, "calorimeters") - 1;
        long t3 = positionOf(counts.clone(), 15, "annihilate") - 1;
        long t4 = positionOf(counts.clone(), 15, "orchestrated") - 1;
        long t5 = positionOf(counts.clone(), 15, "fluttering") - 1;

        long target = t1 + t2 - t3 + t4 - t5;
        System.out.println(buildWord(counts.clone(), 15, target + 1));
    }
}
