import java.util.Arrays;

public class Permute
{
  public static void main(String args[])
  {
    if(args.length != 1)
    {
      System.out.println("Usage: java Permute <n>");
      System.exit(1);
    }
    int n = Integer.parseInt(args[0]); 
    permute(new Permutation(n), 0);
  }

  public static void permute(Permutation v, int start)
  {
    if(start == v.getN()-1)
    {
      System.out.println(v);
      return ;
    }
   
    for(int i = start; i < v.getN(); i++)
    {
      int temp = v.getVal(i);
      v.setVal(i, v.getVal(start));
      v.setVal(start,  temp);
      permute(new Permutation(v), start+1);
    }
  }
}     
