For given an integer $n$, print all permutations of $\\{1, 2, ..., n\\}$ in lexicographic order.

Constraints

* $1 \leq n \leq 9$

Input

An integer $n$ is given in a line.

Output

Print each permutation in a line in order. Separate adjacency elements by a space character.

Examples

Input

2


Output

1 2
2 1


Input

3


Output

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

int main() {
 UL N;scanf("%u",&N);
 UL A[9]; rep(i,N) A[i]=i+1;
 rep(j,N){if(j)printf(" "); printf("%u",A[j]);}
 printf("\n");
 bool stop=false;
 while(!stop){
  stop=true;
  for(UL i=N-1; i!=0; i--){
   if(A[i-1]<A[i]){
    for(UL j=i+1; j<N; j++) if(A[i-1]<A[j] && A[i]>A[j]) swap(A[i],A[j]);
    swap(A[i-1],A[i]);
    sort(A+i,A+N);
    rep(j,N){if(j)printf(" "); printf("%u",A[j]);}
    printf("\n");
    stop=false;
    break;
   }
  }
 }
 return 0;
}


