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

//Problem "Lexicographically minimal permutation shift"
//9th Internet Olympiad, basic level, season 2007-2008
//Problem Author: Fedor Tsarev, tsarev@rain.ifmo.ru
//Solution Author: Maxim Buzdalov, buzdalov@rain.ifmo.ru

public class minlex_mb {
    public static void main(String[] args) throws IOException {
	BufferedReader in = new BufferedReader(new FileReader("minlex.in"));
	int n = Integer.parseInt(in.readLine());
	assert 1 <= n && n <= 100000 : "N is out of bounds";
	StringTokenizer line = new StringTokenizer(in.readLine());
	assert line.countTokens() == n : "Number of integers in sequence is not equal to N";
	int[] perm = new int[n];
	BitSet used = new BitSet(n + 1);
	for (int i = 0; i < n; ++i) {
	    perm[i] = Integer.parseInt(line.nextToken());
	    assert perm[i] > 0 && perm[i] <= n : "Number is out of bounds";
	    assert !used.get(perm[i]) : "Duplicate numbers";
	    used.set(perm[i]);
	}
	in.close();
	
	PrintWriter out = new PrintWriter("minlex.out");
	for (int i = 0; i < n; ++i) {
	    if (perm[i] == 1) {
		for (int j = 0; j < n; ++j) {
		    out.print(perm[(i + j) % n]);
		    if (j + 1 == n) {
			out.println();
		    } else {
			out.print(" ");
		    }
		}
	    }
	}
	out.close();
    }
}
