dfs

import java.util.*;
public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            while(sc.hasNextInt()) {
                int n = sc.nextInt();
                int[] a = new int[n];
                for (int i =0; i <n; i++) {
                    a[i] = sc.nextInt();
                }
                ArrayList<String> list = new ArrayList<String>();
                dfs(0,0, a, new Stack<Integer>(),list, "");
                Collections.sort(list);
                list.forEach(s-> System.out.println(s));
                
            }
        }
    public static void dfs(int i,int j, int[] a,Stack<Integer> input, ArrayList<String> list, String output) {
        if (i == j && j == a.length) {
            list.add(output);
            return;
        }
        if (i != a.length) {
            input.push(a[i]);
            dfs(i + 1, j, a, input, list, output);
            input.pop();
        }
        if (!input.isEmpty()) {
            int x = input.pop();
            dfs(i, j+1, a, input, list, output +x + " ");
            input.push(x);
        }
    }
}