#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0)
#define forr(i,p,n) for(ll i=p;i<n;i++)
typedef long long ll;
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

int main(){
	bolt;
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cout<<i<<" ";
	}
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0)
#define forr(i,p,n) for(ll i=p;i<n;i++)
typedef long long ll;
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

ll a[20];
ll mm[5000][5000];
ll fin[5000][200];
ll cnt[5000];
vector<ll>st[5000];

int main(){
	bolt;
	cin.tie(0);
	cout.tie(0);
	ll n,m,q;
	cin>>n>>m>>q;
	forr(i,0,n){
		cin>>a[i];
	}
	forr(i,0,m){
		string lol;
		cin>>lol;
		ll p=0;
		reverse(all(lol));
		ll u=1;
		for(ll i=0;i<n;i++){
			p+=((lol[i]-'0')*u);
			u=u*2;
		}
		cnt[p]++;
	}
	ll wt=(1<<n);
	for(ll i=0;i<wt;i++){
		ll p=i;
		while(p){
			if(p&1){
				st[i].pb(1);
			}else st[i].pb(0);
			p=p/2;
		}
		while(st[i].size()<n){
			st[i].pb(0);
		}
		reverse(all(st[i]));
	}
	for(ll i=0;i<wt;i++){
		for(ll j=i;j<wt;j++){
			ll p=i^j;
			ll cost=0;
			for(ll i=0;i<st[p].size();i++){
				if(st[p][i]==0)
					cost+=a[i];
			}
			mm[i][j]=cost;
			mm[j][i]=cost;
		}
	}
	for(ll i=0;i<wt;i++){
		for(ll j=0;j<wt;j++){
			if(cnt[j]>0 && mm[i][j]<110){
				fin[i][mm[i][j]]+=cnt[j];
			}
		}
	}
	for(ll i=0;i<wt;i++){
		for(ll j=1;j<=100;j++){
			fin[i][j]+=fin[i][j-1];
		}
	}
	forr(i,0,q){
		string lol;
		ll k;
		cin>>lol>>k;
		ll p=0;
		reverse(all(lol));
		ll u=1;
		for(ll i=0;i<n;i++){
			p+=((lol[i]-'0')*u);
			u=u*2;
		}
		cout<<fin[p][k]<<"\n";
	}
}


#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int sizu;
  cin>>sizu;
  for(int i=sizu/2+1; i<=sizu; ++i){
    cout<<i<<" ";
  }
  for(int i=1; i<=sizu/2; ++i){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;
}


#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int sizu;
  cin>>sizu;
  for(int i=sizu/2+1; i<=sizu; ++i){
    cout<<i<<" ";
  }
  for(int i=sizu/2; i>0; --i){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int sizu;
  cin>>sizu;
  int it=sqrt(sizu);
  int i=sizu;
  i-=it-1;
  while(i>0){
    for(int j=0; j<it; ++j, ++i){
      cout<<i<<" ";
    }
    i-=it+it;
  }
  cout<<endl;
  return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int sizu;
  cin>>sizu;
  int it=sqrt(sizu);
  int i=sizu;
  i-=it-1;
  int gen_count=0;
  while(i>0){
    for(int j=0; j<it; ++j){
      cout<<i<<" ";
      if(j!=it-1){
        ++i;
      }
      gen_count++;
    }
    i-=it+it-1;
  }
  while(gen_count<sizu){
    cout<<sizu-gen_count<<" ";
    ++gen_count;
  }
  cout<<endl;
  return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int sizu;
  cin>>sizu;
  int it=sqrt(sizu);
  int i=sizu;
  i-=it-1;
  int gen_count=0;
  while(i>0){
    for(int j=0; j<it; ++j){
      cout<<i<<" ";
      if(j!=it-1){
        ++i;
      }
      gen_count++;
    }
    i-=it+it-1;
  }
  int temp=gen_count-1;
  while(gen_count<sizu){
    cout<<gen_count-temp<<" ";
    ++gen_count;
  }
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, a[100001];
int lis, lds, ans = 1000000 + 1;

void writeAns(int val, int pos) {
    if (val > n) return;
    //cout << "* " << val <<  " " << pos << endl;
    a[pos] = val;
    if (val % lis) writeAns(val + 1, pos + 1);
    else writeAns(val + 1, max(pos - lis * 2 + 1, 1));
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        if ((n % i > 0) + i + n / i < ans) {
            ans = (n % i > 0) + i + n / i;
            lis = i;
            lds = n / i;
        }
    //cout << ans << " " << lis << " " << lds << endl;
    writeAns(1, n - lis + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include <bits/stdc++.h>

using namespace std;

int n, a[100001];
int lis, lds, ans = 1000000 + 1;

void writeAns(int val, int pos) {
    if (val > n) return;
    a[pos] = val;
    if (val % lis) writeAns(val + 1, pos + 1);
    else writeAns(val + 1, pos - lis * 2 + 1);
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        if (i + n / i < ans) {
            ans = i + n / i;
            lis = i;
            lds = n / i;
        }
    writeAns(1, n - lis + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include <bits/stdc++.h>

using namespace std;

int n, a[100001];
int lis, lds, ans = 1000000 + 1;

void writeAns(int val, int pos) {
    if (val > n) return;
    // cout << "* " << val <<  " " << pos << endl;
    a[pos] = val;
    if (val % lis) writeAns(val + 1, pos + 1);
    else writeAns(val + 1, max(pos - lis * 2 + 1, 1));
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        if (i + n / i < ans) {
            ans = i + n / i;
            lis = i;
            lds = n / i;
        }
    // cout << ans << " " << lis << " " << lds << endl;
    writeAns(1, n - lis + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include <bits/stdc++.h>

using namespace std;

int n, a[100001];
int lis, lds, ans = 1000000 + 1;

void writeAns(int val, int pos) {
    if (val > n) return;
    cout << "* " << val <<  " " << pos << endl;
    a[pos] = val;
    if (val % lis) writeAns(val + 1, pos + 1);
    else writeAns(val + 1, max(pos - lis * 2 + 1, 1));
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        if ((n % i > 0) + i + n / i < ans) {
            ans = (n % i > 0) + i + n / i;
            lis = i;
            lds = n / i;
        }
    cout << ans << " " << lis << " " << lds << endl;
    writeAns(1, n - lis + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include <bits/stdc++.h>

using namespace std;

int n, a[100001];
int lis, lds, ans = 1000000 + 1;

void writeAns(int val, int pos) {
    if (val > n) return;
    // cout << "* " << val <<  " " << pos << endl;
    a[pos] = val;
    if (val % lis) writeAns(val + 1, pos + 1);
    else writeAns(val + 1, max(pos - lis * 2 + 1, 1));
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        if ((n % i > 0) + i + n / i < ans) {
            ans = i + n / i;
            lis = i;
            lds = n / i;
        }
    // cout << ans << " " << lis << " " << lds << endl;
    writeAns(1, n - lis + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 100001
using namespace std;
bool v[maxn];
int m[maxn];
int main()
{  int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
   	cout<<i<<" ";
   }
   return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 100001
using namespace std;
bool v[maxn];
int m[maxn];
int main()
{
   for(int i=1;i<=n;i++)
   {
   	cout<<i<<" "
   }
   return 0;
}


#include<bits/stdc++.h>
#define maxn 100001
using namespace std;
int main()
{
	int n;
	cin>>n;
	int m=sqrt(n);
	int top=n/m;
	for (int i = m*top+1; i <= n; i++) {
		cout << i << " ";
	}
	for (int s = m*top-m; s >= 0; s-=m) {
		for (int i = 1; i <= m; i++) {
			cout << s+i << " ";
		}
	}
	cout << "\n";
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 100001
using namespace std;
bool v[maxn];
int m[maxn];
int main()
{  int n;
   cin>>n;
   for(int i=n;i>=1;i--)
   {
   	cout<<i<<" ";
   }
   return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 100001
using namespace std;
bool v[maxn];
int m[maxn];
int main()
{  int n;
   cin>>n;
   for(int i=n;i>=1;i--)
   { if(i!=1)
   	   cout<<i<<" ";
   	else
	   cout<<i;

   }
   return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 100001
using namespace std;
bool v[maxn];
int m[maxn];
int main()
{  int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
   	cout<<i<<" "
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++)a[i] = i;

                    int tmp = sqrt(n);
                    if(tmp*tmp == n)tmp--;
                    int l = 1;
                    while(l + tmp<= n){
                        swap(a[l],a[l+tmp]);
                        l+=tmp+1;
                    }
                    if(l<n){
                        swap(a[l], a[n]);
                    }
                    for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++)a[i] = i;

                    int tmp = sqrt(n);
                    // if(tmp*tmp < n)tmp++;
                    int l = 1;
                    while(l + tmp<= n){
                        swap(a[l],a[l+tmp]);
                        l+=tmp+1;
                    }
                    if(l<n){
                        swap(a[l], a[n]);
                    }
                    for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++)a[i] = i;

                    int tmp = sqrt(n);
                    if(tmp*tmp == n)tmp--;
                    int l = 1;
                    while(l + tmp<= n){
                        for(int i=l+tmp; i>=l; i--){
                            a[i] = l+tmp+l-a[i];
                        }
                        l+=tmp+1;
                    }
                    // debug(l);
                    if(l<n){
                        swap(a[l], a[n]);
                    }
                    for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    string s1,s2;
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++){
                        cout<<i<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    string s1,s2;
int main(){
                    cin>>n;
                    int w = n/2+1;
                    for(int i=w; i<=n; i++){
                        cout<<i<<" ";
                    }
                    for(int i=1; i<w; i++){
                        cout<<i<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++)a[i] = i;

                    int tmp = sqrt(n);
                    // if(tmp*tmp == n)tmp--;
                    int l = 1;
                    while(l + tmp<= n){
                        for(int i=l+tmp; i>=l; i--){
                            a[i] = l+tmp+l-a[i];
                        }
                        l+=tmp+1;
                    }
                    int sum = a[n] + a[l];
                    for(int i=n; i>=l; i--){
                        a[i] = sum - a[i];
                    }
                    for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++)a[i] = i;

                    int tmp = sqrt(n);
                    if(tmp*tmp == n)tmp--;
                    int l = 1;
                    while(l + tmp<= n){
                        for(int i=l+tmp; i>=l; i--){
                            a[i] = l+tmp+l-a[i];
                        }
                        l+=tmp+1;
                    }
                    int sum = a[n] + a[l];
                    for(int i=n; i>=l; i--){
                        a[i] = sum - a[i];
                    }
                    for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    for(int i=1; i<=n; i++)a[i] = i;
                    int le = 1,ri = 4;
                    while(ri<=n){
                        swap(a[le],a[le+2]);
                        swap(a[le+1],a[le+3]);
                        le +=4;
                        ri+=4;
                    }

                    if(ri==n+2){
                        swap(a[le],a[le+1]);
                    }

                    if(ri==n+1){
                        swap(a[le+1],a[le+2]);
                    }
                     for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }

                    cout<<endl;
                   return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
                    int n;
                    const int maxn = 1e5+9;
                    int a[maxn];
int main(){
                    cin>>n;
                    int w = n/2+1;
                    int id = 1;
                    for(int i=w; i<=n; i++){
                        a[id] = i;
                        id+=2;
                    }
                    id = 2;
                    for(int i=1; i<w; i++){
                        a[id] = i;
                        id+=2;
                    }
                    for(int i=1; i<=n; i++){
                        cout<<a[i]<<" ";
                    }
                    cout<<endl;
                   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main()
{
    int n;
    cin>>n;
    int arr[n],x=n/2;
    arr[x]=n;
    int d=1;
    if(n<=3)
    {
        for(int i=1;i<=n;i++)
            cout<<i<<" ";
        return 0;
    }
    else if(n%2==1)
    {
        for(int i=1;i<=x;i++)
        {
            arr[x+i]=d++;
            arr[x-i]=d++;
        }
    }
    else
    {
        d=1;
        for (int i = 1; i < x; ++i)
        {
            arr[x+i]=d;
            d+=2;
        }
        d=2;
        for(int i = x-1; i >= 0; i--)
        {
            arr[i]=d;
            if(i!=1)
            d+=2;
            if(i==1)
            d+=1;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        cout<<arr[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void arrange1(int *arr,int l,int r)
{
    int mid=(l+r)/2,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    int u=0;
    p[mi]=arr[r];
    for(int i=1;i<=mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if((r-l+1)/2>4)
    {
        arrange1(arr,l,mid-1);
        arrange1(arr,mid+1,r);
    }
}
void arrange2(int *arr,int l,int r)
{
    cout<<l<<" "<<r<<endl;
    int mid = (l+r)/2+1,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    p[mi]=arr[r];
    int u=0;
    for(int i=1;i<mi;i++)
    {
        p[mi-i]=arr[l+u];
        u++;
        p[mi+i]=arr[l+u];
        u++;
    }
    p[0]=arr[l+u];
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if(mi>4)
    {
        arrange2(arr,l,mid-1);
    }
    if(r-l+1-mi>4)
    {
        arrange1(arr,mid+1,r);
    }
}
int main()
{
    int n;
    cin>>n;
    int arr[n+1],x=n/2;
    arr[x]=n;
    int d=1;
    if(n<=3)
    {
        for(int i=1;i<=n;i++)
            cout<<i<<" ";
        return 0;
    }
    else if(n%2==1)
    {
        for(int i=1;i<=x;i++)
        {
            arr[x+i]=d++;
            arr[x-i]=d++;
        }
        if(x>4)
        {
            arrange1(arr,0,x-1);
            arrange1(arr,x+1,n-1);
        }
    }
    else
    {
        d=2;
        for (int i = 1; i < x; ++i)
        {
            arr[x+i]=d;
            d+=2;
        }
        d=1;
        for(int i = x-1; i >= 0; i--)
        {
            arr[i]=d;
            // if(i!=1)
            d+=2;
            // if(i==1)
            // d+=1;
        }
        if(n-x-1>=4)
        {
           arrange1(arr,0,x-1);
        }
        if(x>=4)
        {
            arrange1(arr,x+1,n-1);
        }

    }
    for (int i = 0; i < n; ++i)
    {
        cout<<arr[i]<<" ";
    }
}


// #include<bits/stdc++.h>
// using namespace std;
// int main()
// {
//     ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     int n,m,q;
//     cin>>n>>m>>q;
//     unordered_map<string,int>mp;
//     unordered_map<string,unordered_map<int,int>>fin;
//     pair<string,int> ans[q];
//     unordered_map<string,vector<int>>gp;
//     int w[n];
//     for (int i = 0; i < n; ++i)
//     {
//         cin>>w[i];
//     }
//     for (int i = 0; i < m; ++i)
//     {
//         string s;
//         cin>>s;
//         mp[s]++;
//     }
//     for (int i = 0; i < q; ++i)
//     {
//         int k;
//         string s;
//         cin>>s>>k;
//         ans[i]=pair<string,int>(s,k);
//         gp[s].push_back(k);
//     }
//     for(auto x:gp)
//     {
//         int ss[101]={0};
//         for(auto y:mp)
//         {
//             int a=0;
//             for (int i = 0; i < n; ++i)
//             {

//                 if(y.first[i]==x.first[i])
//                 {
//                     a+=w[i];
//                 }
//             }
//             ss[a]+=y.second;
//         }
//         for (int i = 0; i < 101; ++i)
//         {
//             if(i>0)
//             ss[i]+=ss[i-1];
//         }
//         for(auto l:x.second)
//         {
//             fin[x.first][l]=ss[l];
//         }
//     }
//      for (int i = 0; i < q; ++i)
//         {
//             cout<<fin[ans[i].first][ans[i].second]<<"\n";
//         }

// }

#include<bits/stdc++.h>
using namespace std;
void rev(std::vector<int> &v,int l,int r)
{
    // cout<<
    for (int i = l,j=0; i < l+(r-l)/2; ++i,j++)
    {
        int temp = v[i];
        v[i]=v[r-1-j];
        v[r-1-j]=temp;
    }
}
int main()
{
    int n;
    cin>>n;
    vector<int> v;
    for (int i = 0; i < n; ++i)
    {
        v.push_back(i+1);
    }
    int x=sqrt(n);
    for(int i=0;i<n;i+=x)
    {
        if(n-i<=x)
        {
            rev(v,i,n);
            break;
        }
        else
        rev(v,i,i+x);
    }
    for(auto x:v)
    {
        cout<<x<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void arrange1(int *arr,int l,int r)
{
    int mid=(l+r)/2,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    int u=0;
    p[mi]=arr[r];
    for(int i=1;i<=mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if((r-l+1)/2>4)
    {
        arrange1(arr,l,mid-1);
        arrange1(arr,mid+1,r);
    }
}
void arrange2(int *arr,int l,int r)
{
    //cout<<l<<" "<<r<<endl;
    int mid = (l+r)/2+1,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    p[mi]=arr[r];
    int u=0;
    for(int i=1;i<mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    p[0]=arr[l+u];
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if(mi>4)
    {
        arrange1(arr,l,mid-1);
    }
    if(r-l+1-mi>4)
    {
        arrange2(arr,mid+1,r);
    }
}
int main()
{
    int n;
    cin>>n;
    int arr[n+1],x=n/2;
    arr[x]=n;
    int d=1;
    if(n<=3)
    {
        for(int i=1;i<=n;i++)
            cout<<i<<" ";
        return 0;
    }
    else if(n%2==1)
    {
        for(int i=1;i<=x;i++)
        {
            arr[x+i]=d++;
            arr[x-i]=d++;
        }
        if(x>4)
        {
            arrange1(arr,0,x-1);
            arrange1(arr,x+1,n-1);
        }
    }
    else
    {
        d=1;
        for (int i = 1; i < x; ++i)
        {
            arr[x+i]=d;
            d+=2;
        }
        d=2;
        for(int i = x-1; i >= 0; i--)
        {
            arr[i]=d;
            if(i!=1)
            d+=2;
            if(i==1)
            d+=1;
        }
        if(n-x-1>4)
        {
           arrange1(arr,0,x-1);
        }
        if(x>4)
        {
            arrange2(arr,x+1,n-1);
        }

    }
    for (int i = 0; i < n; ++i)
    {
        cout<<arr[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void arrange1(int *arr,int l,int r)
{
    int mid=(l+r)/2,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    int u=0;
    p[mi]=arr[r];
    for(int i=1;i<=mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if((r-l+1)/2>4)
    {
        arrange1(arr,l,mid-1);
        arrange1(arr,mid+1,r);
    }
}
void arrange2(int *arr,int l,int r)
{
    //cout<<l<<" "<<r<<endl;
    int mid = (l+r)/2+1,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    p[mi]=arr[r];
    int u=0;
    for(int i=1;i<mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    p[0]=arr[l+u];
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if(mi>4)
    {
        arrange2(arr,l,mid-1);
    }
    if(r-l+1-mi>4)
    {
        arrange1(arr,mid+1,r);
    }
}
int main()
{
    int n;
    cin>>n;
    int arr[n+1],x=n/2;
    arr[x]=n;
    int d=1;
    if(n<=3)
    {
        for(int i=1;i<=n;i++)
            cout<<i<<" ";
        return 0;
    }
    else if(n%2==1)
    {
        for(int i=1;i<=x;i++)
        {
            arr[x+i]=d++;
            arr[x-i]=d++;
        }
        if(x>4)
        {
            arrange1(arr,0,x-1);
            arrange1(arr,x+1,n-1);
        }
    }
    else
    {
        d=1;
        for (int i = 1; i < x; ++i)
        {
            arr[x+i]=d;
            d+=2;
        }
        d=2;
        for(int i = x-1; i >= 0; i--)
        {
            arr[i]=d;
            if(i!=1)
            d+=2;
            if(i==1)
            d+=1;
        }
        if(n-x-1>4)
        {
           arrange1(arr,0,x-1);
        }
        if(x>4)
        {
            arrange2(arr,x+1,n-1);
        }

    }
    for (int i = 0; i < n; ++i)
    {
        cout<<arr[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
void rev(std::vector<int> &v,int l,int r)
{
    // cout<<
    for (int i = l,j=0; i < l+(r-l)/2; ++i,j++)
    {
        int temp = v[i];
        v[i]=v[r-1-j];
        v[r-1-j]=temp;
    }
}
int main()
{
    int n;
    cin>>n;
    vector<int> v;
    for (int i = 0; i < n; ++i)
    {
        v.push_back(i+1);
    }
    int x=sqrt(n);
    for(int i=0;i<n;i+=x)
    {
        if(n-i<=2*x)
        {
            rev(v,i,n);
            break;
        }
        else
        rev(v,i,i+x);
    }
    for(auto x:v)
    {
        cout<<x<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void arrange1(int *arr,int l,int r)
{
    int mid=(l+r)/2,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    int u=0;
    p[mi]=arr[r];
    for(int i=1;i<=mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if((r-l+1)/2>4)
    {
        arrange1(arr,l,mid-1);
        arrange1(arr,mid+1,r);
    }
}
void arrange2(int *arr,int l,int r)
{
    //cout<<l<<" "<<r<<endl;
    int mid = (l+r)/2+1,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    p[mi]=arr[r];
    int u=0;
    for(int i=1;i<mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    p[0]=arr[l+u];
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if(mi>4)
    {
        arrange1(arr,l,mid-1);
    }
    if(r-l+1-mi>4)
    {
        arrange2(arr,mid+1,r);
    }
}
int main()
{
    int n;
    cin>>n;
    int arr[n+1],x=n/2;
    arr[x]=n;
    int d=1;
    if(n<=4)
    {
        for(int i=1;i<=n;i++)
            cout<<i<<" ";
        return 0;
    }
    else if(n%2==1)
    {
        for(int i=1;i<=x;i++)
        {
            arr[x+i]=d++;
            arr[x-i]=d++;
        }
        if(x>4)
        {
            arrange1(arr,0,x-1);
            arrange1(arr,x+1,n-1);
        }
    }
    else
    {
        d=1;
        for (int i = 1; i < x; ++i)
        {
            arr[x+i]=d;
            d+=2;
        }
        d=2;
        for(int i = x-1; i >= 0; i--)
        {
            arr[i]=d;
            if(i!=1)
            d+=2;
            if(i==1)
            d+=1;
        }
        if(n-x-1>4)
        {
           arrange1(arr,0,x-1);
        }
        if(x>4)
        {
            arrange2(arr,x+1,n-1);
        }

    }
    for (int i = 0; i < n; ++i)
    {
        cout<<arr[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void arrange1(int *arr,int l,int r)
{
    int mid=(l+r)/2,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    int u=0;
    p[mi]=arr[r];
    for(int i=1;i<=mi;i++)
    {
        p[mi+i]=arr[l+u];
        u++;
        p[mi-i]=arr[l+u];
        u++;
    }
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if((r-l+1)/2>4)
    {
        arrange1(arr,l,mid-1);
        arrange1(arr,mid+1,r);
    }
}
void arrange2(int *arr,int l,int r)
{
    //cout<<l<<" "<<r<<endl;
    int mid = (l+r)/2+1,mi=(r-l+1)/2;
    sort(&arr[l],&arr[r+1]);
    int p[r-l+1];
    p[mi]=arr[r];
    int u=0;
    for(int i=1;i<mi;i++)
    {
        p[mi-i]=arr[l+u];
        u++;
        p[mi+i]=arr[l+u];
        u++;
    }
    p[0]=arr[l+u];
    u=l;
    for(int i=0;i<(r-l+1);i++)
    {
        arr[u++]=p[i];
    }
    if(mi>4)
    {
        arrange1(arr,l,mid-1);
    }
    if(r-l+1-mi>4)
    {
        arrange2(arr,mid+1,r);
    }
}
int main()
{
    int n;
    cin>>n;
    int arr[n+1],x=n/2;
    arr[x]=n;
    int d=1;
    if(n<=3)
    {
        for(int i=1;i<=n;i++)
            cout<<i<<" ";
        return 0;
    }
    else if(n%2==1)
    {
        for(int i=1;i<=x;i++)
        {
            arr[x+i]=d++;
            arr[x-i]=d++;
        }
        if(x>4)
        {
            arrange1(arr,0,x-1);
            arrange1(arr,x+1,n-1);
        }
    }
    else
    {
        d=2;
        for (int i = 1; i < x; ++i)
        {
            arr[x+i]=d;
            d+=2;
        }
        d=1;
        for(int i = x-1; i >= 0; i--)
        {
            arr[i]=d;
            // if(i!=1)
            d+=2;
            // if(i==1)
            // d+=1;
        }
        if(n-x-1>4)
        {
           arrange1(arr,0,x-1);
        }
        if(x>4)
        {
            arrange2(arr,x+1,n-1);
        }

    }
    for (int i = 0; i < n; ++i)
    {
        cout<<arr[i]<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    int cnt = sqrt(n);
    int res = n - cnt * cnt;
    int sing = res / cnt + (res % cnt > 0 ? 1 : 0);
    int tril = res % cnt > 0 ? (res % cnt - 1) : 0;
    int l = n - sing - cnt + 1;
    int r = n;
    for(int i = cnt; i >= 1; i--)
    {
        for(int j = l; j <= r; j++)
        {
            printf("%d ", j);
        }
        r = l - 1;
        l = l - cnt - (tril > 0 ? sing : (res / cnt));
        tril--;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;

int main()
{
    int n; scanf("%d", &n);
    for(int i = n / 2 + 1; i <= n; i++)
    {
        printf("%d ", i);
    }
    for(int i = 1; i <= n / 2; i++)
    {
        printf("%d ", i);
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    if(n <= 4)
    {
        for(int i = n / 2 + 1; i <= n; i++)
        {
            printf("%d", i);
            if(n != 1) printf(" ");
        }
        for(int i = 1; i <= n / 2; i++)
        {
            printf("%d", i);
            if(i != n / 2) printf(" ");
        }
        printf("\n");
    }
    else
    {
        int cnt = sqrt(n);
        int res = n - cnt * cnt;
        int sing = res / cnt + (res % cnt > 0 ? 1 : 0);
        int tril = res % cnt > 0 ? (res % cnt - 1) : 0;
        int l = n - sing - cnt + 1;
        int r = n;
        for(int i = cnt; i >= 1; i--)
        {
            for(int j = l; j <= r; j++)
            {
                printf("%d ", j);
            }
            r = l - 1;
            l = l - cnt - (tril > 0 ? sing : (res / cnt));
            tril--;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    for(int i = n / 2 + 1; i <= n; i++)
    {
        printf("%d", i);
        if(n != 1) printf(" ");
    }
    for(int i = 1; i <= n / 2; i++)
    {
        printf("%d", i);
        if(i != n / 2) printf(" ");
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    if(n <= 4)
    {
        for(int i = n / 2 + 1; i <= n; i++)
        {
            printf("%d", i);
            if(n != 1) printf(" ");
        }
        for(int i = 1; i <= n / 2; i++)
        {
            printf("%d", i);
            if(i != n / 2) printf(" ");
        }
        printf("\n");
    }
    else
    {
        int res = n % 3;
        int b1 = n / 3 + (res > 0 ? 1 : 0);
        res--;
        int b2 = n / 3 + (res > 0 ? 1 : 0);
        res--;
        int b3 = n / 3 + (res > 0 ? 1 : 0);
        for(int i = n - b1 + 1; i <= n; i++)
        {
            printf("%d ", i);
        }
        for(int i = n - b1 - b2 + 1; i <= n - b1 ; i++)
        {
            printf("%d ", i);
        }
        for(int i = 1; i <= b3; i++)
        {
            printf("%d ", i);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#define R register
#define ll long long
#define eps 1e-8
#define maxn 1100
#define rep(i,s,n) for(R int i=s;i<=n;i++)
#define down(i,s,n) for(R int i=s;i>=n;i--)
using namespace std;
template <typename T>inline void in(R T&a)
{
	R char c=getchar();R T x=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	a=x*f;
}
int n;
int main()
{
	in(n);int len=(int)sqrt(n),k=n/len;
	if(k*len!=n)k++;
	while(k){rep(i,max(1,n-len+1),n)printf("%d ",i);n-=len;k--;}
	return 0;
}


#include<cstring>
#include<queue>
#include<iostream>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int inf = 0x3f3f3f3f;
int n,m;

int main()
{
    scanf("%d",&n);
    int k = ceil(sqrt(n));
    for(int i = 1;i<=k;i++)
    {
        for(int j = k;j>=1;j--)
        {
            if(n-j+1<=0) continue;
            printf("%d ",n-j+1);
        }
        n-=k;
    }
    return 0;
}


#include <stdio.h>
int main()
{
 int n;
 scanf("%d",&n);
 for(int i=1;i<=n/2;i++)
  printf("%d ",(n+1)/2+i);
 for(int i=1;i<=n-n/2;i++)
  printf("%d ",i);
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int block=sqrt(n);
    while(n){
        for(int i=n-block+1;i<=n;i++){
            if(i>0)cout<<i<<' ';
        }
        n-=block;
    }
    return 0;
}


#define _CRT_SBCURE_NO_DEPRECATE
#include<stdio.h>
#include <set>
#include<map>
#include<string.h>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define REP(i,a,b) for (int i=(a);i<=(b);i++)
#define in(a) scanf("%d",&(a))
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD=1000000007;
typedef long long ll;
int i,j,k,l,n,m,sum,maxx,minn,ans,x,y,flag;
int main()
{
    cin>>n;
    for(i=1;i<=n/2;i++)
    {
        cout<<i<<" ";
        cout<<n-i+1<<" ";
    }
    if(n%2==1)
        cout<<(n/2)+1;
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define lson pos<<1
#define rson pos<<1|1
#define lowbit(x) (x&(-x))
#define y1 y_1
#define id(x,y) ((x-1)*m+y)
#define left left_1
#define right right_1
#define g 9.8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
map<int, int> mp;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll maxx = 1e6 + 10;
const int MOD = 1e9+7;
//int v[maxn],ans[maxn];
//int a[maxn]={0,6 ,5 ,7, 2, 1, 4 ,3};
//int solve(int n){
//    ans[1]=v[1];
////    path[1]=1;
//    int len=1;
//    for(int i=2;i<=n;i++)
//    {
//        if(v[i]>ans[len])
//        {
//            ans[++len]=v[i];
////            path[i]=len;
//        }
//        else
//        {
//            int pos=lower_bound(ans+1,ans+1+len,v[i])-ans;
//            ans[pos]=v[i];
////            path[i]=pos;
//        }
//    }
//    return len;
//}
int n;
void dfs(int l,int r,int f){
    if(l==r){
        cout<<l<<" ";
        return;
    }
//    if(l+1==r){
//        if(f==1) cout<<r<<" "<<l<<" ";
//        else cout<<l<<" "<<r<<" ";
//        return;
//    }
    int mid=(l+r)/2;
    if(f==1){
        dfs(mid+1,r,0);
        dfs(l,mid,0);
    }
    else{
        dfs(l,mid,1);
        dfs(mid+1,r,1);
    }
}
int main()
{
    cin>>n;
    dfs(1,n,1);
    cout<<endl;

//    for(int i=1;i<=n;i++) cout<<a[i]<<endl;
//    for(int i=1;i<=n;i++){
//            v[i]=a[n+1-i];
//        }
//        int ans1=solve(n);
//        for(int i=1;i<=n;i++){
//            v[i]=a[i];
//        }
//        int ans2=solve(n);
//        cout<<ans1<<" "<<ans2<<" "<<ans1+ans2<<endl;
////    for(int i=1;i<=n;i++) a[i]=i;
//    int minv=100;
//    do{
//        for(int i=1;i<=n;i++){
//            v[i]=a[n+1-i];
//        }
//        int ans1=solve(n);
//        for(int i=1;i<=n;i++){
//            v[i]=a[i];
//        }
//        int ans2=solve(n);
//        minv=min(minv,ans1+ans2);
//    }while(next_permutation(a+1,a+1+n));
//    cout<<minv<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define lson pos<<1
#define rson pos<<1|1
#define lowbit(x) (x&(-x))
#define y1 y_1
#define id(x,y) ((x-1)*m+y)
#define left left_1
#define right right_1
#define g 9.8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
map<int, int> mp;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll maxx = 1e6 + 10;
const int MOD = 1e9+7;
int v[maxn],ans[maxn];
//int a[maxn]={0,6 ,5 ,7, 2, 1, 4 ,3};
int solve(int n){
    ans[1]=v[1];
//    path[1]=1;
    int len=1;
    for(int i=2;i<=n;i++)
    {
        if(v[i]>ans[len])
        {
            ans[++len]=v[i];
//            path[i]=len;
        }
        else
        {
            int pos=lower_bound(ans+1,ans+1+len,v[i])-ans;
            ans[pos]=v[i];
//            path[i]=pos;
        }
    }
    return len;
}
int n;
int cnt,tmp1[maxn],tmp2[maxn],tmp3[maxn];
void dfs1(int l,int r,int f){
    if(l==r){
        tmp1[++cnt]=l;
//        cout<<cnt<<" "<<tmp[cnt]<<" "<<l<<" emmm "<<endl;
//        cout<<l<<" ";
        return;
    }
    int len=floor(sqrt(r-l+1-1)*1.0);
//    cout<<len<<endl;
    if(f==1){
        for(int i=r;i>=l;i-=len){
            dfs1(max(i-len+1,l),i,0);
        }
    }
    else{
        for(int i=l;i<=r;i+=len){
            dfs1(i,min(i+len-1,r),1);
        }
    }
}
void dfs2(int l,int r,int f){
    if(l==r){
        tmp2[++cnt]=l;
//        cout<<cnt<<" "<<tmp[cnt]<<" "<<l<<" emmm "<<endl;
//        cout<<l<<" ";
        return;
    }
    int len=floor(sqrt(r-l+1)*1.0);
//    cout<<len<<endl;
    if(f==1){
        for(int i=r;i>=l;i-=len){
            dfs2(max(i-len+1,l),i,0);
        }
    }
    else{
        for(int i=l;i<=r;i+=len){
            dfs2(i,min(i+len-1,r),1);
        }
    }
}
void dfs3(int l,int r,int f){
    if(l==r){
        tmp3[++cnt]=l;
//        cout<<cnt<<" "<<tmp[cnt]<<" "<<l<<" emmm "<<endl;
//        cout<<l<<" ";
        return;
    }
    int len=floor(sqrt(r-l+1+1)*1.0);
//    cout<<len<<endl;
    if(f==1){
        for(int i=r;i>=l;i-=len){
            dfs3(max(i-len+1,l),i,0);
        }
    }
    else{
        for(int i=l;i<=r;i+=len){
            dfs3(i,min(i+len-1,r),1);
        }
    }
}
int main()
{
    while(cin>>n){
        cnt=0;
        dfs1(1,n,1);
        cnt=0;
        dfs2(1,n,1);
        cnt=0;
        dfs3(1,n,1);
//        cout<<endl;

//        for(int i=1;i<=n;i++) cout<<tmp[i]<<" ";
//        cout<<endl;
        int ans1=0,ans2=0,ans3=0;
        for(int i=1;i<=n;i++){
            v[i]=tmp1[i];
        }
        ans1+=solve(n);
        for(int i=1;i<=n;i++){
            v[i]=tmp1[n+1-i];
        }
        ans1+=solve(n);

        for(int i=1;i<=n;i++){
            v[i]=tmp2[i];
        }
        ans2+=solve(n);
        for(int i=1;i<=n;i++){
            v[i]=tmp2[n+1-i];
        }
        ans2+=solve(n);

        for(int i=1;i<=n;i++){
            v[i]=tmp3[i];
        }
        ans3+=solve(n);
        for(int i=1;i<=n;i++){
            v[i]=tmp3[n+1-i];
        }
        ans3+=solve(n);

        int minv=min(ans1,min(ans2,ans3));
        if(minv==ans1){
            for(int i=1;i<=cnt;i++) cout<<tmp1[i]<<" ";
            cout<<endl;
         }
        else if(minv==ans2){
            for(int i=1;i<=cnt;i++) cout<<tmp2[i]<<" ";
            cout<<endl;
        }
        else{
            for(int i=1;i<=cnt;i++) cout<<tmp3[i]<<" ";
            cout<<endl;
        }

//        cout<<ans1<<" "<<ans2<<" "<<ans1+ans2<<endl;
//
//
//        vector<int> vec(n);
//        iota(vec.begin(),vec.end(),1);
//        int minv=100;
//        do{
//            for(int i=1;i<=n;i++){
//                v[i]=vec[n+1-i-1];
//            }
//            int ans1=solve(n);
//            for(int i=1;i<=n;i++){
//                v[i]=vec[i-1];
//            }
//            int ans2=solve(n);
//            minv=min(minv,ans1+ans2);
//        }while(next_permutation(vec.begin(),vec.end()));
//        cout<<minv<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define lson pos<<1
#define rson pos<<1|1
#define lowbit(x) (x&(-x))
#define y1 y_1
#define id(x,y) ((x-1)*m+y)
#define left left_1
#define right right_1
#define g 9.8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
map<int, int> mp;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll maxx = 1e6 + 10;
const int MOD = 1e9+7;
//int v[maxn],ans[maxn];
////int a[maxn]={0,6 ,5 ,7, 2, 1, 4 ,3};
//int solve(int n){
//    ans[1]=v[1];
////    path[1]=1;
//    int len=1;
//    for(int i=2;i<=n;i++)
//    {
//        if(v[i]>ans[len])
//        {
//            ans[++len]=v[i];
////            path[i]=len;
//        }
//        else
//        {
//            int pos=lower_bound(ans+1,ans+1+len,v[i])-ans;
//            ans[pos]=v[i];
////            path[i]=pos;
//        }
//    }
//    return len;
//}
int n;
int cnt,tmp[maxn];
void dfs(int l,int r,int f){
    if(l==r){
        tmp[++cnt]=l;
//        cout<<cnt<<" "<<tmp[cnt]<<" "<<l<<" emmm "<<endl;
        cout<<l<<" ";
        return;
    }
    int len=floor(sqrt(r-l+1)*1.0);
//    cout<<len<<endl;
    if(f==1){
        for(int i=r;i>=l;i-=len){
            dfs(max(i-len+1,l),i,0);
        }
    }
    else{
        for(int i=l;i<=r;i+=len){
            dfs(i,min(i+len-1,r),1);
        }
    }
}
int main()
{
    while(cin>>n){
        cnt=0;
        dfs(1,n,1);
        cout<<endl;

//        for(int i=1;i<=n;i++) cout<<tmp[i]<<" ";
//        cout<<endl;
//
//        for(int i=1;i<=n;i++){
//            v[i]=tmp[i];
//        }
//        int ans1=solve(n);
//        for(int i=1;i<=n;i++){
//            v[i]=tmp[n+1-i];
//        }
//        int ans2=solve(n);
//        cout<<ans1<<" "<<ans2<<" "<<ans1+ans2<<endl;
//
//
//        vector<int> vec(n);
//        iota(vec.begin(),vec.end(),1);
//        int minv=100;
//        do{
//            for(int i=1;i<=n;i++){
//                v[i]=vec[n+1-i-1];
//            }
//            int ans1=solve(n);
//            for(int i=1;i<=n;i++){
//                v[i]=vec[i-1];
//            }
//            int ans2=solve(n);
//            minv=min(minv,ans1+ans2);
//        }while(next_permutation(vec.begin(),vec.end()));
//        cout<<minv<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define lson pos<<1
#define rson pos<<1|1
#define lowbit(x) (x&(-x))
#define y1 y_1
#define id(x,y) ((x-1)*m+y)
#define left left_1
#define right right_1
#define g 9.8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
map<int, int> mp;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll maxx = 1e6 + 10;
const int MOD = 1e9+7;
//int v[maxn],ans[maxn];
//int a[maxn]={0,6, 5, 7, 2, 1, 4, 3};
//int solve(int n){
//    ans[1]=v[1];
////    path[1]=1;
//    int len=1;
//    for(int i=2;i<=n;i++)
//    {
//        if(v[i]>ans[len])
//        {
//            ans[++len]=v[i];
////            path[i]=len;
//        }
//        else
//        {
//            int pos=lower_bound(ans+1,ans+1+len,v[i])-ans;
//            ans[pos]=v[i];
////            path[i]=pos;
//        }
//    }
//    return len;
//}
int n;
void dfs(int l,int r,int f){
    if(l==r){
        cout<<l<<" ";
        return;
    }
    if(l+1==r){
        if(f==1) cout<<r<<" "<<l<<" ";
        else cout<<l<<" "<<r<<" ";
        return;
    }
    int mid=(l+r)/2;
    if(f==1){
        dfs(mid+1,r,0);
        dfs(l,mid,0);
    }
    else{
        dfs(l,mid,1);
        dfs(mid+1,r,1);
    }
}
int main()
{
    cin>>n;
    dfs(1,n,1);
    cout<<endl;

//    for(int i=1;i<=n;i++){
//            v[i]=a[n+1-i];
//        }
//        int ans1=solve(n);
//        for(int i=1;i<=n;i++){
//            v[i]=a[i];
//        }
//        int ans2=solve(n);
//        cout<<ans1<<" "<<ans2<<endl;
//    int minv=100;
//    do{
//        for(int i=1;i<=n;i++){
//            v[i]=a[n+1-i];
//        }
//        int ans1=solve(n);
//        for(int i=1;i<=n;i++){
//            v[i]=a[i];
//        }
//        int ans2=solve(n);
//        minv=min(minv,ans1+ans2);
//    }while(next_permutation(a+1,a+1+n));
//    cout<<minv<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define lson pos<<1
#define rson pos<<1|1
#define lowbit(x) (x&(-x))
#define y1 y_1
#define id(x,y) ((x-1)*m+y)
#define left left_1
#define right right_1
#define g 9.8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
map<int, int> mp;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll maxx = 1e6 + 10;
const int MOD = 1e9+7;

int n;
int main()
{
    cin>>n;
    int unit=floor(sqrt(n));
    for(int i=n;i>=1;i-=unit){
        for(int j=max(1,i-unit+1);j<=i;j++){
            cout<<j<<" ";
        }
    }
    cout<<endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
#define MAXN 100005
using namespace std;
template <typename T>
inline void read(T &a)
{
    T ret(0),f(1);char ch(getchar());
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){ret = (ret << 2) + ret,ret += ret + (ch ^ 48);ch = getchar();}
    a = ret * f;
}
inline int Max(int x,int y){return x > y ? x : y;}
inline int Min(int x,int y){return x < y ? x : y;}
//lis长度为L,则lds个数为L,长度为n/L
//均值不等式
int ans[MAXN];
int main()
{
	int n,x,num,e;
	read(n),num = n,x = sqrt(n);//watch this
	for(int i(1);i <= n;i += x)//避免不完整的块
	{
		e = Min(n,i + x - 1);
		for(int j(e);j >= i;j--) ans[j] = num--;
	}
	for(int i(1);i <= n;i++) printf("%d ",ans[i]);
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
#define MAXN 100005
using namespace std;
template <typename T>
inline void read(T &a)
{
    T ret(0),f(1);char ch(getchar());
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){ret = (ret << 2) + ret,ret += ret + (ch ^ 48);ch = getchar();}
    a = ret * f;
}
inline int Max(int x,int y){return x > y ? x : y;}
inline int Min(int x,int y){return x < y ? x : y;}
int main()
{
	int n,x,l,e;
	read(n),x = sqrt(n);
	for(int bl(1);bl <= x;bl++)
	{
		l = n - bl * x + 1,e = n - (bl - 1) * x;
		for(int i(l);i <= e;i++) printf("%d ",i);
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
#define MAXN 100005
using namespace std;
template <typename T>
inline void read(T &a)
{
    T ret(0),f(1);char ch(getchar());
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){ret = (ret << 2) + ret,ret += ret + (ch ^ 48);ch = getchar();}
    a = ret * f;
}
inline int Max(int x,int y){return x > y ? x : y;}
inline int Min(int x,int y){return x < y ? x : y;}
int main()
{
	int n,x,l,e,b,cnt(0);
	read(n),x = sqrt(n),b = n / x;//watch this
	for(int bl(1);bl <= b;bl++)
	{
		l = n - bl * x + 1,e = n - (bl - 1) * x;
		for(int i(l);i <= e;i++) ++cnt,printf("%d ",i);
	}
	if(n - cnt) printf("1");
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define ll long long
#pragma comment(linker, "/STACK:64000000")

const int maxn = 1 << 10;

int ans, n;
vector<int> e[maxn];

void rec(int x, int l, int r) {
	if (l == r) return;
	if (l + 1 == r) {
		e[x].push_back(l);
		ans = max(ans, x + 1);
		return;
	}
	int m = (l + r) >> 1;
	for (int i = l; i <= m; i++)
		e[x].push_back(i);
	rec(x + 1, l, m);
	rec(x + 1, m + 1, r);
}

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin >> n;
	rec(0, 1, n);
	printf("%d\n", ans);
	for (int i = 0; i < ans; i++) {
		printf("%d ", (int)e[i].size());
		for (int j = 0; j < e[i].size(); j++)
			printf("%d ", e[i][j]);
		printf("\n");
	}
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define ll long long
#pragma comment(linker, "/STACK:64000000")

const int maxn = 1 << 10;

int ans, n;
vector<int> e[maxn];

void rec(int x, int l, int r) {
	if (l == r) return;
	if (l + 1 == r) {
		e[x].push_back(l);
		ans = max(ans, x + 1);
		return;
	}
	int m = (l + r) >> 1;
	for (int i = l; i <= m; i++)
		e[x].push_back(i);
	rec(x + 1, l, m);
	rec(x + 1, m + 1, r);
}

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin >> n;
	rec(0, 1, n);
	printf("%d\n", ans);
	for (int i = 0; i < ans; i++) {
		for (int j = 0; j < e[i].size(); j++)
			printf("%d ", e[i][j]);
		printf("\n");
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <map>
#include <functional>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
//#pragma comment (linker, "/STACK:167177216")
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
const int MAXN = 210;
const int MAX = 2147483647;
typedef long long LL;

bool fav[101];

int main() {
#ifdef MY_SOL
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n;
	int cur = 1;
	vector<vector<int> > ans;
	cin >> n;
	while (cur < n)
	{
		int u = 1;
		ans.push_back(vector<int>());
		for (int i = 0; i < n; i += 2 * cur)
		{
			for (int j = 0; j < cur; ++j)
			{
				if (i + j >= n) break;
				ans.back().push_back(i + j + 1);
			}

		}
		cur *= 2;
	}

	cout << ans.size() << endl;
	forn(i, 0, ans.size())
	{
		cout << ans[i].size() << " ";
		forn(j, 0, ans[i].size())
			cout << ans[i][j] << " ";
		cout << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <map>
#include <functional>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
//#pragma comment (linker, "/STACK:167177216")
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
const int MAXN = 210;
const int MAX = 2147483647;
typedef long long LL;

bool fav[101];

int main() {
#ifdef MY_SOL
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n;
	int cur = 1;
	vector<vector<int> > ans;
	cin >> n;
	while (cur < n)
	{
		int u = 1;
		ans.push_back(vector<int>());
		for (int i = 0; i < n; i += 2 * cur)
		{
			for (int j = 0; j < cur; ++j)
			{
				ans.back().push_back(i + j + 1);
			}

		}
		cur *= 2;
	}

	cout << ans.size() << endl;
	forn(i, 0, ans.size())
	{
		cout << ans[i].size() << " ";
		forn(j, 0, ans[i].size())
			cout << ans[i][j] << " ";
		cout << endl;
	}

	return 0;
}


#include <stdio.h>
#include <math.h>
#include <iostream>
#include <sstream>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <string>

using namespace std;

int n,p,ans,i,j;
vector<int>v;

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&n);
    for(p=1,ans=0;p<n;p+=p,ans++);
    printf("%d\n",ans);
    for(i=0;i<ans;i++)
    {
        v.clear();
        for(j=0;j<n;j++)
            if(j&(1<<i))
                v.push_back(j);
        printf("%d",v.size());
        for(j=0;j<v.size();j++)
            printf(" %d",v[j]+1);
        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<iomanip>
#include<sstream>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<utility>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<bitset>
using namespace std;

typedef pair<int, int> pii;
typedef long long LLL;
typedef unsigned long long HL;
#define PB(X) push_back(X)
#define ALL(X) (X).begin(),(X).end()
const int INF = 1e9;

const int MAXN = 1010;

int n;
vector<int> t[MAXN];

int main()
{
//#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
//#endif

	cin>>n;
	int p = 1;
	int cnt = 0;
	while(p<n)
	{
		for(int i=0;i<n;i++)
		{
			if((i/p)%2==0)
				t[cnt].PB(i+1);
		}
		p*=2;
		cnt++;
	}
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++)
	{
		cout<<t[i].size();
		for(int j=0;j<t[i].size();j++)
			cout<<' '<<t[i][j];
		cout<<endl;
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<iomanip>
#include<sstream>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<utility>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<bitset>
using namespace std;

typedef pair<int, int> pii;
typedef long long LLL;
typedef unsigned long long HL;
#define PB(X) push_back(X)
#define ALL(X) (X).begin(),(X).end()
const int INF = 1e9;

const int MAXN = 1010;

int n;
int a[MAXN];

int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	cin>>n;

	for(int i=0;i<n;i++)
		a[i] = i+1;

	int first = n/2+n%2;
	int last = n-first+n%2;
	a[n] = n-1;

	cout<<n/2+n%2<<endl;
	for(int i=0;i<n/2+n%2;i++)
	{
		cout<<first;
		for(int j=0;j<first;j++)
			cout<<' '<<a[j];
		cout<<endl;
		for(int j=0;j<last-i-1;j++)
			swap(a[n-j-1], a[first-j-1]);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<iomanip>
#include<sstream>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<utility>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<bitset>
using namespace std;

typedef pair<int, int> pii;
typedef long long LLL;
typedef unsigned long long HL;
#define PB(X) push_back(X)
#define ALL(X) (X).begin(),(X).end()
const int INF = 1e9;

int n;

int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	cin>>n;
	cout<<n-1<<endl;
	for(int i=n-1;i>=1;i--)
	{
		cout<<i;
		for(int j=1;j<=i;j++)
			cout<<' '<<j;
		cout<<endl;
	}
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
using namespace std;

#define MP make_pair
#define ALL(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define sqr(x) ((x)*(x))

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int p = 1;
	int sz = 1;
	while (p * 2 < n)
	{
		p *= 2;
		sz++;
	}
	printf("%i\n", sz);
	for (int i=0; i<sz; i++)
	{
		vector < int > ans;
		for (int i=0; i<n; i++)
			if ((i / p) % 2 == 0)
				ans.push_back(i + 1);
		printf("%i ", SZ(ans));
		for (int j=0; j<SZ(ans); j++)
			printf("%i ", ans[j]);
		printf("\n");
		p /= 2;
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

#pragma comment(linker,"/STACK:100000000")

vector <int> ans[100];

int solve(int l, int r, int k)
{
//  printf("%d %d\n", l, r);
//  fflush(stdout);
    if (l == r)
        return k;
    int m = (l + r)/2;
    for (int i = l; i <= m; ++i)
        ans[k].push_back(i);
    int res = solve(l, m, k + 1);
    res = max(res, solve(m + 1, r, k + 1));
    return res;
}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int i, j;
    int n;
    scanf("%d", &n);
    int k = solve(0, n - 1, 0);
    printf("%d\n", k);
    for (i = 0; i < k; ++i)
    {
        printf("%d ", ans[i].size());
        for (j = 0; j < ans[i].size(); ++j)
            printf("%d ", ans[i][j] + 1);
        printf("\n");
    }
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define PI acos(-1.0)
#define eps 1e-9
#define MOD 1000000007
#define INF 1000000000
using namespace std;
template<class T> T f_min(T x,T y){return x<y?x:y;}
template<class T> T f_max(T x,T y){return x>y?x:y;}
template<class T> T f_abs(T x){return x<0?-x:x;}
int N;
void get_data(){
    scanf("%d",&N);
}
void run(){
    int i,j,bt,l;
    i=N;l=0;
    while(i){
        i>>=1;l++;
    }
    if(N==(1<<(l-1)))l--;
    printf("%d\n",l);
    vector<int>v;
    for(i=0,bt=1;i<l;bt<<=1,i++){
        v.clear();
        for(j=1;j<=N;j++){
            if(j&bt)v.push_back(j);
        }
        printf("%d",v.size());
        for(j=0;j<v.size();j++)printf(" %d",v[j]);
        printf("\n");
    }
}
int main(){
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    get_data();
    run();
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define PI acos(-1.0)
#define eps 1e-9
#define MOD 1000000007
#define INF 1000000000
using namespace std;
template<class T> T f_min(T x,T y){return x<y?x:y;}
template<class T> T f_max(T x,T y){return x>y?x:y;}
template<class T> T f_abs(T x){return x<0?-x:x;}
int N;
void get_data(){
    scanf("%d",&N);
}
void run(){
    int i,j,bt,l;
    i=N;l=0;
    while(i){
        i>>=1;l++;
    }
    if(N==(1<<(l-1)))l--;
    printf("%d\n",l);
    vector<int>v;
    for(i=0,bt=1;i<l;bt<<=1,i++){
        v.clear();
        for(j=1;j<=N;j++){
            if(j&bt)v.push_back(j);
        }
        printf("%d",v.size());
        for(j=0;j<v.size();j++)printf(" %d",v[j]);
        printf("\n");
    }
}
int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    get_data();
    run();
    return 0;
}


#pragma warning(disable:4786)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdio>
#include <ctime>

using namespace std;

#define MEM(a,b) memset(a,(b),sizeof(a))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b)  ((a) < (b) ? (a) : (b))
#define istr(S) istringstream sin(S)
#define MP make_pair
#define pb push_back
#define M 1000000007
#define maxn 1000000

//typedef long long  LL;
typedef __int64 LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;

int f[1085];

int main()
{
    int i,j,k,tests,cs=0,n,K;

    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    f[2]=1;
    for(i=3;i<=1085;i++)
    {
        f[i] = 1+ f[(i+1)/2];
        //if(i<=10) printf("%d\n",f[i]);

    }

    scanf("%d",&n);

    int ans=f[n],x=n;

    for(;;x++)
    {
        if(!(x&(x-1))) break;
    }

    int y=1,z=x;

    printf("%d\n",ans);

    while(ans--)
    {
        MEM(f,0);

        int t=y;

        for(i=1;t;i+=z,t--)
        {
            int sz=z/2;
            //printf("=%d %d %d\n",i,z,y);

            for(j=i;sz;sz--,j++)
            {
                f[j]=1;
            }

        }
        y*=2;
        z/=2;

        int cnt=0;
        for(i=1;i<=n;i++)
        {
            if(f[i]==1) cnt++;
        }

        printf("%d",cnt);
        for(i=1;i<=n;i++)
            if(f[i]) printf(" %d",i);
        puts("");

    }

    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int INF = 1000*1000*1000;
const long long INF64 = ((long long)INF)*INF;
const double PI = acos(-1.0);

template<typename T> inline T sqr(T x){ return x*x; }

int dp[2000];
int n;
vector<int> team[2000];

void rec(int s, int k, int d)
{
    if (k < 2)
        return;
    int p;
    for(int i = 1; i < k; ++i)
        if (dp[k] == 1+max(dp[i], dp[k-i]))
        {
            p = i;
            break;
        }
    for(int i = s; i < s+p; ++i)
        team[d].push_back(i);
    rec(s, p, d+1);
    rec(s+p, k-p, d+1);
}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> n;
    dp[2] = 1;
    for(int i = 3; i <= n; ++i)
    {
        dp[i] = i;
        for(int j = 1; j < i; ++j)
            dp[i] = min(dp[i], max(dp[j], dp[i-j])+1);
    }
    rec(1, n, 1);
    cout << dp[n] << endl;
    for(int i = 1; i <= dp[n]; ++i)
    {
        cout << team[i].size();
        for(int j = 0; j < (int)team[i].size(); ++j)
            cout << " " << team[i][j];
        cout << endl;
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

vector<pair<int,int> > allpairs[1002];

int main()
{
    ifstream input;
    input.open("input.txt");
    ofstream output;
    output.open("output.txt");
    int n;
    input>>n;

    for(int i=0;i<=15;i++)
    {
        if((1<<i)>=n)
        {
            output << i << endl;
            break;
        }
    }

    allpairs[0].push_back(make_pair(1,n));

    for(int iters=1;iters<=100;iters++)
    {
        bool needsplit=false;
        for(int j=0;j<allpairs[iters-1].size();j++)
        {
            int st = allpairs[iters-1][j].first;
            int en = allpairs[iters-1][j].second;
            if(st<en)
                needsplit=true;
        }

        if(!needsplit)
            break;
        for(int j=0;j<allpairs[iters-1].size();j++)
        {
            int st = allpairs[iters-1][j].first;
            int en = allpairs[iters-1][j].second;
            if(st==en)
                allpairs[iters].push_back(make_pair(st,en));
            else
            {
                allpairs[iters].push_back(make_pair(st,st+(en-st)/2));
                allpairs[iters].push_back(make_pair(st+(en-st)/2+1,en));
            }
        }

        int sz = 0;
        for(int i=0;i<allpairs[iters].size();i+=2)
        {
            sz+=allpairs[iters][i].second-allpairs[iters][i].first+1;
        }

        output << sz << " ";
        for(int i=0;i<allpairs[iters].size();i+=2)
            for(int j=allpairs[iters][i].first;j<=allpairs[iters][i].second;j++)
                output << j << " ";
        output << endl;
    }
    input.close();
    output.close();

}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <list>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <map>
#include <iterator>
#include <sstream>
#include <fstream>
#include <list>
#include <set>
#include <stack>
#include <bitset>
#include <ctime>

#pragma comment(linker, "/STACK:256000000")

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define EPS 1e-7
#define PI 3.1415926535897932384626433832795

using namespace std;

int aabs(int a){
	if (a<0) return -a;
	return a;
}

vector < pair<vector<int>,vector<int> > > games;

void solve(int l, int r){
	if (l==r){
		return;
	}
	int m=(l+r)/2;
	vector <int> a, b;
	for (int i=l;i<=m;i++){
		a.push_back(i);
	}
	for (int i=m+1;i<=r;i++){
		b.push_back(i);
	}
	games.push_back(make_pair(a,b));
	solve(l,m);
	solve(m+1,r);
}

int main(){
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	int n;
	cin>>n;
	solve(0,n-1);
	vector < pair<set<int>,set<int> > > ans(1000);
	for (int i=0;i<games.size();i++){
		for (int j=0;;j++){
			bool pp=1;
			for (int k=0;k<games[i].first.size();k++){
				if (ans[j].first.find(games[i].first[k])!=ans[j].first.end() || ans[j].second.find(games[i].first[k])!=ans[j].second.end()){
					pp=0;
					break;
				}
			}
			for (int k=0;k<games[i].second.size();k++){
				if (ans[j].first.find(games[i].second[k])!=ans[j].first.end() || ans[j].second.find(games[i].second[k])!=ans[j].second.end()){
					pp=0;
					break;
				}
			}
			if (pp){
				for (int k=0;k<games[i].first.size();k++){
					ans[j].first.insert(games[i].first[k]);
				}
				for (int k=0;k<games[i].second.size();k++){
					ans[j].second.insert(games[i].second[k]);
				}
				break;
			}
		}
	}
	int aans=0;
	for (int i=0;;i++){
		if (ans[i].first.size()==0){
			aans=i;
			break;
		}
	}
	cout<<aans<<'\n';
	for (int i=0;i<aans;i++){
		cout<<ans[i].first.size()<<' ';
		for (set<int>::iterator it=ans[i].first.begin();it!=ans[i].first.end();it++){
			cout<<(*it)+1<<' ';
		}
		cout<<'\n';
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector <vector <int> > ans;
	vector <vector <int> > now(1), tmp;
	for (int i = 0; i < n; i++)
		now[0].push_back(i);
	while (true) {
		bool ok = false;
		ans.push_back(vector <int> ());
		for (int i = 0; i < now.size(); i++)
		{
			if (now[i].size() <= 1)
				continue;
			ok = true;
			int s = now[i].size() / 2;
			for (int j = 0; j < s; j++)
				ans.back().push_back(now[i][j]);
			tmp.push_back(vector <int> ());
			for (int j = 0; j < s; j++)
				tmp.back().push_back(now[i][j]);
			tmp.push_back(vector <int> ());
			for (int j = s; j < now[i].size(); j++)
				tmp.back().push_back(now[i][j]);
		}
		now = tmp;
		tmp.clear();
		if (!ok)
		{
			ans.pop_back();
			break;
		}
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i].size() << " ";
		for (int j = 0; j < ans[i].size(); j++)
			cout << ans[i][j] + 1 << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector <vector <int> > ans;
	vector <vector <int> > now(1), tmp;
	for (int i = 0; i < n; i++)
		now[0].push_back(i);
	while (true) {
		bool ok = false;
		for (int i = 0; i < now.size(); i++)
		{
			if (now[i].size() <= 1)
				continue;
			ok = true;
			int s = now[i].size() / 2;
			ans.push_back(vector <int> ());
			for (int j = 0; j < s; j++)
				ans.back().push_back(now[i][j]);
			tmp.push_back(vector <int> ());
			for (int j = 0; j < s; j++)
				tmp.back().push_back(now[i][j]);
			tmp.push_back(vector <int> ());
			for (int j = s; j < now[i].size(); j++)
				tmp.back().push_back(now[i][j]);
		}
		now = tmp;
		tmp.clear();
		if (!ok)
			break;
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i].size() << " ";
		for (int j = 0; j < ans[i].size(); j++)
			cout << ans[i][j] + 1 << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector <vector <int> > ans;
	vector <vector <int> > now(1), tmp;
	for (int i = 0; i < n; i++)
		now[0].push_back(i);
	while (true) {
		bool ok = false;
		ans.push_back(vector <int> ());
		for (int i = 0; i < now.size(); i++)
		{
			if (now[i].size() <= 1)
				continue;
			ok = true;
			int s = now[i].size() / 2;
			for (int j = 0; j < s; j++)
				ans.back().push_back(now[i][j]);
			tmp.push_back(vector <int> ());
			for (int j = 0; j < s; j++)
				tmp.back().push_back(now[i][j]);
			tmp.push_back(vector <int> ());
			for (int j = s; j < now[i].size(); j++)
				tmp.back().push_back(now[i][j]);
		}
		now = tmp;
		tmp.clear();
		if (!ok)
			break;
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)
	{
		if (ans[i].size() == 0)
			continue;
		cout << ans[i].size() << " ";
		for (int j = 0; j < ans[i].size(); j++)
			cout << ans[i][j] + 1 << " ";
		cout << endl;
	}
	return 0;
}


#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stack>
using namespace std;

int main() {

    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    int n;
    cin>>n;
    cout<<n-1<<endl;
    for (int i=0;i<n-1;i++) {
        cout<<i+1<<" ";
        for (int k=0;k<=i;k++) {
            cout<<k+1<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stack>
using namespace std;

int mas[1001];

int main() {

    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    int n;
    cin>>n;
    int k=(n+1)/2;
    cout<<k<<endl;
    for (int i=0;i<n;i++)
        mas[i]=i+1;
    for (int i=0;i<k;i++) {
        cout<<k<<" ";
        for (int j=0;j<k;j++) {
            if (mas[j]!=0)
                cout<<mas[j]<<" ";
        }
        cout<<endl;
        swap(mas[i],mas[i+k]);
    }
    return 0;
}


#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stack>
using namespace std;

int mas[1001];
int mas1[1001];

int main() {

    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    int n;
    cin>>n;
    int mul=1,cnt=0;
    while(mul<n) {
        mul*=2;
        cnt++;
    }
    cout<<cnt<<endl;
    for (int i=0;i<n;i++)
        mas[i]=i+1;
    for (int i=0;i<cnt;i++) {
        cout<<(n+1)/2<<" ";
        for (int j=0;j<(n+1)/2;j++) {
            cout<<mas[j]<<" ";
        }
        cout<<endl;
        for (int i=0;i<n;i+=2)
            mas1[i/2]=mas[i];
        for (int i=1;i<n;i+=2)
            mas1[(n+1)/2+i/2]=mas[i];
        for (int i=0;i<n;i++)
            mas[i]=mas1[i];
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.);

int N;
int ans = 0;
vector<int> n[10050];

void solve(int d, int l, int r)
{
	if (r - l < 2) return;
	int m = (l + r) / 2;
	ans = max(d + 1, ans);
	for (int i = l; i < m; ++i)
	{
		n[d].push_back(i);
	}
	solve(d + 1, l, m);
	solve(d + 1, m, r);
}

int main()
{
freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	scanf("%d", &N);
	solve(0, 0, N);
	printf("%d\n", ans);
	for (int i = 0; i < ans; ++i)
	{
		printf("%d ", n[i].size());
		for (int j = 0; j < n[i].size(); ++j)
		{
			printf("%d ", n[i][j] + 1);
		}
		puts("");
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int N;

int main(void){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%d", &N);
    int x = N - 1, ans = 0;
    while (x) {
        x /= 2;
        ans ++;
    }
    printf("%d\n", ans);
    for (int i = 0; i < ans; i ++) {
        int cnt = 0;
        for (int j = 0; j < N; j ++) {
            if (((j >> i) & 1) == 0) ++ cnt;
        }
        printf("%d", cnt);
        for (int j = 0; j < N; j ++) {
            if (((j >> i) & 1) == 0) printf(" %d", j + 1);
        }
        printf("\n");
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define MAXN 1005

int N;
vector <int> K;

int main(void){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%d", &N);
    if (N == 2) {
        printf("1\n");
        printf("1 1\n");
        return 0;
    }
    if (N == 3) {
        printf("2\n");
        printf("2 1 2\n");
        printf("1 1\n");
        return 0;
    }
    if (N == 4) {
        printf("2\n");
        printf("2 1 2\n");
        printf("2 1 3\n");
        return 0;
    }
    printf("3\n");
    printf("%d", N/2 + ((N&1)? 1 : 0));
    for (int i = 1; i <= (N+1)/2; i ++) {
        printf(" %d", i);
    } printf("\n");
    for (int i = 1; i <= N; i += 4) {
        K.push_back(i);
        if (i + 1 <= N) K.push_back(i + 1);
    }
    printf("%d", K.size());
    for (int i = 0; i < K.size(); i ++) printf(" %d", K[i]);
    printf("\n");
    K.clear();
    for (int i = 1; i <= N; i += 2) {
        K.push_back(i);
    }
    printf("%d", K.size());
    for (int i = 0; i < K.size(); i ++) printf(" %d", K[i]);
    printf("\n");
    return 0;
}


#pragma comment(linker, "/STACK:65777216")
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef long double ld;

const ld EPS = 1e-11;
//const int INF = 2147483647;
const int INF = 2000000000;
const li lINF = 9223372036854775807;
const ld PI = 3.14159265358979323846;

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	vector <int> ans[30];
	int n, i, s[20], x, j = 0, k;
	cin >> n;
	s[0] = 1;
	i = 0;
	while (s[i] < n) {
		i++;
		s[i] = s[i-1] * 2;
	}
	x = s[i];
	cout << i << "\n";
	while (x != 1) {
		for (i = 0; i < n; i++)
			if (i % x < x / 2)
				ans[j].pb(i+1);
		j++;
		x /= 2;
	}
	for (i = 0; i < j; i++) {
		cout << ans[i].size() << ' ';
		for (k = 0; k < ans[i].size(); k++)
			cout << ans[i][k] << ' ';
		cout << "\n";
	}
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
#define N 100
using namespace std;
int main()
{
    int n, k, l, i, j;
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    for(scanf("%d", &n), l=0, k=1; k<n; l++, k*=2);
    for(printf("%d\n", l), i=0; i<l; i++)
    {
        for(k=0, j=0; j<n; k+=(j>>i)&1, j++);
        for(printf("%d", k), j=0; j<n; j++)
            if((j>>i)&1) printf(" %d", j+1);
        printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<vector>
using namespace std;
vector<int>lef[12];
int n;

int dfs(int x,int y,int k)
{
    if(y<=x)    return k-1;
    int m=(x+y)/2;
    for(int i=x;i<=m;++i)
        lef[k].push_back(i);
    return max(dfs(x,m,k+1),dfs(m+1,y,k+1));
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&n);
    int k=dfs(1,n,1);
    printf("%d\n",k);
    for(int i=1;i<=k;++i)
    {
        printf("%d",lef[i].size());
        for(int j=0;j<lef[i].size();++j)
            printf(" %d",lef[i][j]);
        puts("");
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 1100
int n;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int i,j;
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",n-1);
		for(i=1;i<n;i++)
		{
			printf("%d ",i);
			for(j=1;j<=i;j++)
			{
				printf("%d ",j);
			}
			puts("");
		}
	}
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

int n;
vvi a;
vvi b;
vvi *cur;
vvi *old;

void LoAd()
{
    cin >> n;
    a.resize(1);
    a[0].resize(n);
    for (int i = 0; i < n; i++)
        a[0][i] = i + 1;
    cur = &b;
    old = &a;
}

vvi q;

void SoLvE()
{
    for (int t = 0; ; t++)
    {
        q.push_back(vi());
        for (int i = 0; i < (int) old->size(); i++)
        {
            int k = (int) (*old)[i].size();
            int k2 = k / 2;
            cur->resize(2 * old->size(), vi());
            for (int j = 0; j < k2; j++)
            {
                (*cur)[2 * i].push_back((*old)[i][j]);

            }
            for (int j = k2; j < k; j++)
            {
                (*cur)[2 * i + 1].push_back((*old)[i][j]);
                q[t].push_back((*old)[i][j]);
            }
        }
        old = cur;
        bool ok = false;
        for (int i = 0; i < (int) old->size(); i++)
        {
            if ((*old)[i].size() > 1)
            {
                ok = true;
                break;
            }
        }
        if (!ok)
            break;
        cur = new vvi();
    }
    cout << q.size();
    for (int i = 0; i < (int) q.size(); i++)
    {
        puts("");
        cout << q[i].size();
        for (int j = 0; j < (int) q[i].size(); j++)
            printf(" %d", q[i][j]);
    }
}

int main()
{
    srand( (int) time(NULL));
freopen("input.txt","r",stdin);   freopen("output.txt","w",stdout);
    LoAd();
    SoLvE();
    return 0;
}


#include <stdio.h>
int chk[1050];
int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int N, t=2, i, ans;
	scanf("%d", &N);
	for(i = 1;;i++) {
		if(N <= t) {
			printf("%d\n", i);
			break;
		}
		t *= 2;
	}
	t = 2;
	while(1) {
		ans = 0;
		for(i = 0; i < N; i++) {
			if((i*2/t)%2 == 0) chk[i] = 0;
			else chk[i] = 1;
			ans += chk[i];
		}
		printf("%d ", ans);
		for(i = 0; i < N; i++) {
			if(chk[i] == 0) continue;
			printf("%d ", i+1);
		}
		if(t >= N) break;
		printf("\n");
		t *= 2;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string.h>

#pragma comment(linker, "/STACK:100000000")

using namespace std;

//#ifdef _DEBUG
//#include <fstream>
//std::ifstream fcin( "D:\\input.txt" );
////#define cin fcin
//#endif
#ifndef _DEBUG
#include <fstream>
std::ifstream fcin( "input.txt" );
#define cin fcin
std::ofstream fcout( "output.txt" );
#define cout fcout
#endif

//#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
//#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
//typedef long long ll;
//#define MOD 1000000007ll

int placement[1025];

void setFirstRound( int nn )
{
    for( int i = 0; i < nn; i++ ) {
        placement[i] = i+1;
    }
}

void swapPlacement( int nn, int swapSize )
{
    for( int i = 0; i < nn/2; i++ ) {
        int j = i + nn/2;
        if( (i / swapSize) % 2 == 1 ) {
            swap( placement[i], placement[j] );
        }
    }
}

void printFullPlacement( int nn )
{
    for( int i = 0; i < nn; i++ ) {
        cout << placement[i] << " ";
        if( i == nn/2 - 1 ) cout << "| ";
    }
    cout << endl;
}

void printPartialPlacement( int nn, int n )
{
    int firstTeamCount = 0;
    for( int i = 0; i < nn / 2; i++ ) {
        if( placement[i] <= n ) firstTeamCount++;
    }
    cout << firstTeamCount << " ";
    for( int i = 0; i < nn / 2; i++ ) {
        if( placement[i] <= n ) {
            cout << placement[i] << " ";
        }
    }
    cout << endl;
}

int main()
{
    int n = 0;
    cin >> n;
    int nn = 2;
    int totalRounds= 1;
    while ( nn < n ) {
        nn = nn * 2;
        totalRounds++;
    }

    cout << totalRounds << endl;
    setFirstRound( nn );
    //printFullPlacement( nn );
    printPartialPlacement( nn, n );
    int swapSize = 1;
    for( int i = 0; i < totalRounds - 1; i++ ) {
        swapPlacement( nn, swapSize );
        //printFullPlacement( nn );
        printPartialPlacement( nn, n );
        swapSize *= 2;
    }

    return 0;
}


fin = open('input.txt', 'r')
fout = open('output.txt', 'w')

n = int(fin.readline()) - 1

def log(x):
    r = 0
    while x:
        x //= 2
        r += 1
    return r

logn = log(n)
print log(n)

for i in range(logn):
    team = [x + 1 for x in range(n + 1) if x & (1 << i)]
    team = [len(team)] + team
    fout.write(' '.join(map(str, team)) + '\n')


fin = open('input.txt', 'r')
fout = open('output.txt', 'w')

n = int(fin.readline()) - 1

def log(x):
    r = 0
    while x:
        x //= 2
        r += 1
    return r

logn = log(n)
print log(n)

for i in range(logn):
    team = [x + 1 for x in range(n + 1) if x & (1 << i)]
    team = [len(team)] + team
    print ' '.join(map(str, team))


fin = open('input.txt', 'r')
fout = open('output.txt', 'w')

n = int(fin.readline()) - 1

def log(x):
    r = 0
    while x:
        x //= 2
        r += 1
    return r

logn = log(n)
fout.write(str(log(n)) + '\n')

for i in range(logn):
    team = [x + 1 for x in range(n + 1) if x & (1 << i)]
    team = [len(team)] + team
    fout.write(' '.join(map(str, team)) + '\n')


import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = input()
r = []
for i in range(11):
	r.append([j for j in range(n) if j >> i & 1])
r = [x for x in r if len(x)]
print len(r)
for x in r:
	print len(x), ' '.join(map(str, x))


import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = input()
r = []
for i in range(11):
	r.append([j for j in range(n) if j >> i & 1])
r = [x for x in r if len(x)]
print len(r)
for x in r:
	print len(r), ' '.join(map(str, x))


import sys
from itertools import izip_longest
sys.stdin = open("input.txt"); sys.stdout = open("output.txt", "w")

N, = map(int, sys.stdin.readline().strip().split())

def shift(it, k):
  return [tuple(a+k for a in t) for t in it]

def solve(n):
  if n < 2:
    return
  if n == 2:
    yield (0,)
    return

  a, b = (n+1)//2, n//2
  yield tuple(range(a))
  for solve1, solve2 in izip_longest(solve(a), shift(solve(b),a)):
    if solve2 is None: solve2 = ()
    yield solve1+solve2

res = list(solve(N))
print len(res)
for team in res:
  print len(team),
  print " ".join(str(a+1) for a in team)


#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF = 1000000007;

vector<vector<int>> ans;

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    vector<vector<int>> ans;
    for(int i=2;i<2*n;i*=2){
        ans.push_back({});
        for(int x=0;x<n;x++) if(x%i<i/2) ans.back().push_back(x+1);
    }
    printf("%d\n",ans.size());
    for(auto& u:ans){
        printf("%d",u.size());
        for(auto x:u) printf(" %d",x);
        puts("");
    }
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF = 1000000007;

vector<vector<int>> ans;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    vector<vector<int>> ans;
    for(int i=2;i<2*n;i*=2){
        ans.push_back({});
        for(int x=0;x<n;x++) if(x%i<i/2) ans.back().push_back(x+1);
    }
    printf("%d\n",ans.size());
    for(auto& u:ans){
        printf("%d",u.size());
        for(auto x:u) printf(" %d",x);
        puts("");
    }
}