import java.util.*;

public class separador {
    static class QueueInfo implements Comparable<QueueInfo> {
        long weight;
        int id;

        public QueueInfo(long weight, int id) {
            this.weight = weight;
            this.id = id;
        }

        @Override
        public int compareTo(QueueInfo other) {
            if (this.weight != other.weight) {
                return Long.compare(this.weight, other.weight);
            }
            return Integer.compare(this.id, other.id);
        }
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int f = s.nextInt();

        List<List<Long>> queues = new ArrayList<>();
        for (int i = 0; i <= f; i++) {
            queues.add(new ArrayList<>());
        }

        TreeSet<QueueInfo> set = new TreeSet<>();
        for (int i = 1; i <= f; i++) {
            set.add(new QueueInfo(0, i));
        }

        for (int i = 0; i < n; i++) {
            long p = s.nextLong();
            
            QueueInfo q = set.pollFirst();
            queues.get(q.id).add(p);
            q.weight += p;
            set.add(q);
        }

        for (int i = 1; i <= f; i++) {
            List<Long> q = queues.get(i);
            for (int j = 0; j < q.size(); j++) {
                System.out.print(q.get(j));
                if (j + 1 < q.size()) System.out.print(" ");
            }
            System.out.println();
        }

        s.close();
    }
}
