#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a, b[1050], c,  l, r, q,n,m,sum,ans,g;
string s;
const int inf = 999999999;
int main()
{
	while (cin>>n) {
	    getline(cin, s);
	    getline(cin, s);
		sum=g=c= 0;
		ans = inf;
		memset(b, 0, sizeof(b));
		for (int i = 0; i <s.size(); ++i)
			if ((s[i]>='A'&&s[i] <= 'Z')||(s[i] >= 'a'&&s[i] <= 'z'))
			if (b[int(s[i])]==0) {
				++sum;
				b[int(s[i])] = 1;
			}
		memset(b, 0, sizeof(b));
		for (int i = 0; i < s.size(); ++i)
			if ((s[i] >= 'A'&&s[i] <= 'Z') || (s[i] >= 'a'&&s[i] <= 'z')){
			if (b[int(s[i])] == 0) ++g;
			if (g == sum&&c+1 <ans) ans = c+1;

			++b[int(s[i])];
			while (b[int(s[i - c])] > 1) {
				--b[int(s[i - c])];
				--c;
			}
			++c;
		}
		if (ans == inf) ans = 0;
		cout << ans << endl;

	}

}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a, b[1050], c, l, r, q, n, m, sum, ans, g;
string s;
const int inf = 999999999;
int main()
{
	while (cin >> n) {
		getline(cin, s);
		getline(cin, s);
		sum = g = c = 0;
		ans = 99999999;
		memset(b, 0, sizeof(b));
		for (int i = 0; i <s.size(); ++i)
			if ((s[i] >= 'A'&&s[i] <= 'Z') || (s[i] >= 'a'&&s[i] <= 'z'))
				if (b[int(s[i])] == 0) {
					++sum;
					b[int(s[i])] = 1;
				}
		memset(b, 0, sizeof(b));
		for (int i = 0; i < s.size(); ++i)
			if ((s[i] >= 'A'&&s[i] <= 'Z') || (s[i] >= 'a'&&s[i] <= 'z')) {
				if (b[int(s[i])] == 0) ++g;

				++b[int(s[i])];
				while (b[int(s[i - c])] > 1) {
					--b[int(s[i - c])];
					--c;
				}
				++c;
				if (g == sum&&c  <ans) ans = c ;
			}

		cout << ans << endl;

	}

}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a, b[1050], c, l, r, q, n, m, sum, ans, g;
string s;
const int inf = 999999999;
int main()
{
	while (cin >> n) {
		getline(cin, s);
		getline(cin, s);
		sum = g = c = 0;
		ans = 99999999;
		memset(b, 0, sizeof(b));
		for (int i = 0; i <s.size(); ++i)
			if (b[int(s[i])] == 0) {
				++sum;
				b[int(s[i])] = 1;
			}
		memset(b, 0, sizeof(b));
		for (int i = 0; i < s.size(); ++i){
			if (b[int(s[i])] == 0) ++g;
            ++b[int(s[i])];
			while (b[int(s[i - c])] > 1) {
				--b[int(s[i - c])];
				--c;
			}
			++c;
			if (g == sum&&c  <ans) ans = c ;
		}
		cout << ans << endl;
	}
}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a, b[1050], c,  l, r, q,n,m,sum,ans,g;
char s[105000];
const int inf = 999999999;
int main()
{
	while (~scanf("%d%", &n)) {
		scanf("%s", &s);
		sum=g=c= 0;
		ans = 99999999;
		memset(b, 0, sizeof(b));
		for (int i = 0; i < n; ++i)
			if (!b[int(s[i])]) {
				++sum;
				b[int(s[i])] = 1;
			}
		memset(b, 0, sizeof(b));
		for (int i = 0; i < n; ++i){
			if (b[int(s[i])] == 0) ++g;
			if (g == sum&&c+1 <ans) ans = c+1;

			++b[int(s[i])];
			while (b[int(s[i - c])] > 1) {
				--b[int(s[i - c])];
				--c;
			}
			++c;
		}
		cout << ans << endl;

	}

}


#pragma comment (linker, "/STACK:22222222")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<vector>
#include<cstring>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<sstream>
#include<algorithm>
#include<iomanip>
#include<stack>
using namespace std;
typedef unsigned long long ll;
typedef double db;
typedef pair<int, int> P;
#define next sdfda
int n, res=0;
char s[100111], used[3333], last[100111];
bool fun(int m, int v){
	int kol=0;
	for(int i=0; i<n; i++){
		if(used[s[i]]!=v)
			kol++;
		used[s[i]]=v;
		last[s[i]]=i;
		if(i-m>=0){
			if(last[s[i-m]]==i-m){
				used[s[i-m]]=0;
				kol--;
			}
		}
		if(kol==res) return 1;
	}
	return 0;
}
int main(){
	cin>>n;
	scanf("%s", &s);
	for(int i=0; i<n; i++){
		if(used[s[i]]!=-1) res++;
		used[s[i]]=-1;
	}
	int ans=0, l=0, r=0, kol=INT_MAX;
	for(; r<n; r++){
		if(used[s[r]]!=1)
			ans++;
		used[s[r]]=1;
		last[s[r]]=r;
		while(ans==res){
			if(last[s[l]]==l) break;
			l++;
		}
		if(ans==res)
		kol=min(kol, r-l+1);
	}
	cout<<kol;
}


#pragma comment (linker, "/STACK:22222222")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<vector>
#include<cstring>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<sstream>
#include<algorithm>
#include<iomanip>
#include<stack>
using namespace std;
typedef unsigned long long ll;
typedef double db;
typedef pair<int, int> P;
#define next sdfda
int n, res=0;
char s[100111], used[3333], last[3333];
bool fun(int m, int v){
	int kol=0;
	for(int i=0; i<n; i++){
		if(used[s[i]]!=v)
			kol++;
		used[s[i]]=v;
		last[s[i]]=i;
		if(i-m>=0){
			if(last[s[i-m]]==i-m){
				used[s[i-m]]=0;
				kol--;
			}
		}
		if(kol==res) return 1;
	}
	return 0;
}
int main(){
	cin>>n;
	scanf("%s", &s);
	for(int i=0; i<n; i++){
		if(used[s[i]]!=-1) res++;
		used[s[i]]=-1;
	}
	int l=0, r=n, num=1;
	while(l<r){
		int m=(l+r)/2;
		if(fun(m, num++)) r=m;
		else l=m+1;
	}
	cout<<l;
}


#pragma comment (linker, "/STACK:22222222")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<vector>
#include<cstring>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<sstream>
#include<algorithm>
#include<iomanip>
#include<stack>
using namespace std;
typedef unsigned long long ll;
typedef double db;
typedef pair<int, int> P;
#define next sdfda
int n, res=0;
char s[100111], used[3333];
int last[100111];
bool fun(int m, int v){
	int kol=0;
	for(int i=0; i<n; i++){
		if(used[s[i]]!=v)
			kol++;
		used[s[i]]=v;
		last[s[i]]=i;
		if(i-m>=0){
			if(last[s[i-m]]==i-m){
				used[s[i-m]]=0;
				kol--;
			}
		}
		if(kol==res) return 1;
	}
	return 0;
}
int main(){
	cin>>n;
	scanf("%s", &s);
	for(int i=0; i<n; i++){
		if(used[s[i]]!=-1) res++;
		used[s[i]]=-1;
	}
	int ans=0, l=0, r=0, kol=INT_MAX;
	for(; r<n; r++){
		if(used[s[r]]!=1)
			ans++;
		used[s[r]]=1;
		last[s[r]]=r;
		while(ans==res){
			if(last[s[l]]==l) break;
			l++;
		}
		if(ans==res)
		kol=min(kol, r-l+1);
	}
	cout<<kol;
}


#pragma comment (linker, "/STACK:22222222")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<vector>
#include<cstring>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<sstream>
#include<algorithm>
#include<iomanip>
#include<stack>
using namespace std;
typedef unsigned long long ll;
typedef double db;
typedef pair<int, int> P;
#define next sdfda
int n, res=0;
char s[100111], used[3333], last[3333];
bool fun(int m, int v){
	int kol=0;
	for(int i=0; i<n; i++){
		if(used[s[i]]!=v)
			kol++;
		used[s[i]]=v;
		last[s[i]]=i;
		if(i-m>=0){
			if(last[s[i-m]]==i-m){
				used[s[i-m]]=0;
				kol--;
			}
		}
		if(kol==res) return 1;
	}
	return 0;
}
int main(){
	cin>>n;
	scanf("%s", &s);
	for(int i=0; i<n; i++){
		if(used[s[i]]!=-1) res++;
		used[s[i]]=-1;
	}
	int ans=0, l=0, r=0, kol=INT_MAX;
	for(; r<n; r++){
		if(used[s[r]]!=1)
			ans++;
		used[s[r]]=1;
		last[s[r]]=r;
		while(ans==res){
			if(last[s[l]]==l) break;
			l++;
		}
		if(ans==res)
		kol=min(kol, r-l+1);
	}
	cout<<kol;
}


#include<stdio.h>
#include<conio.h>
#include<cctype>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<cstdlib>
using namespace std;

int main()
{

	string s1, s2, s;
	int n,min;

	cin >> n;

	cin >> s1;
	min = n;

	map<char, int> chars;

	for (int i = 0; i < n; i++)
		chars[s1[i]] = 0;

	if (s1 == s2)
		min = s1.size();

	int l=0, r = 0, count=1;
	chars[s1[0]]++;
	while (true)
	{
		r++;
		if (r == s1.size())
			break;

		if (chars[s1[r]] == 0)
			count++;
		chars[s1[r]]++;

		while (count == (int)chars.size())
		{
			min =_ALGORITHM_::min(min, r - l + 1);
			chars[s1[l]]--;
			if (chars[s1[l]] == 0)
				count--;
			l++;
		}
	}

	cout << min;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

bool t[256];

bool check(vector <long long> &a, vector <long long> &b)
{
	for (char i = 'A'; i <= 'z'; i++)
		if (t[i] == true && a[i] - b[i] < 1)
			return false;
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	long long n, min = 1000000007;
	char c;
	cin >> n;
	vector <vector<long long>> f(n + 1);
	getchar();
	for (int i = 0; i < n + 1; i++)
		f[i].resize(256);
	for (int j = 0; j < 256; j++)
	{
		t[j] = false;
		f[0][j] = 0;
	}
	for (int i = 1; i <= n; i++)
	{
		c = getchar();
		for (int j = 'A'; j <= 'z'; j++)
			f[i][j] = f[i - 1][j];
		f[i][c]++;
		t[c] = true;
	}
	for (int i = 1; i <= n; i++)
	{
		int l = -1, r = i + 1;
		while (r - l > 1)
		{
			if (check(f[i], f[(l + r) / 2]))
				l = (l + r) / 2;
			else
				r = (l + r) / 2;
		}
		if (l > -1 && i - l < min)
			min = i - l;
		if (check(f[0], f[i]) && i < min)
			min = i;
	}
	cout << min;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

bool t[256];

bool check(long long (&a) [256], long long (&b) [256])
{
	for (char i = 'A'; i <= 'z'; i++)
		if (t[i] == true && a[i] - b[i] < 1)
			return false;
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	long long n, min = 1000000007;
	char c;
	cin >> n;
	vector <long long [256]> f(n + 1);
	getchar();
	for (int j = 0; j < 256; j++)
	{
		t[j] = false;
		f[0][j] = 0;
	}
	for (int i = 1; i <= n; i++)
	{
		c = getchar();
		for(int j = 'A'; j <= 'z'; j++)
			f[i][j] = f[i - 1][j];
		f[i][c]++;
		t[c] = true;
	}
	for (int i = 1; i <= n; i++)
	{
		int l = -1, r = i + 1;
		while (r - l > 1)
		{
			if (check(f[i], f[(l + r) / 2]))
				l = (l + r) / 2;
			else
				r = (l + r) / 2;
		}
		if (l > -1 && i - l < min)
			min = i - l;
		if (check(f[0], f[i]) && i < min)
			min = i;
	}
	cout << min;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

bool t[256];

bool check(long long a [256], long long b [256])
{
	for (char i = 'A'; i <= 'z'; i++)
		if (t[i] == true && a[i] - b[i] < 1)
			return false;
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	long long n, min = 1000000007;
	char c;
	cin >> n;
	vector <long long [256]> f(n + 1);
	getchar();
	for (int j = 0; j < 256; j++)
	{
		t[j] = false;
		f[0][j] = 0;
	}
	for (int i = 1; i <= n; i++)
	{
		c = getchar();
		for (int j = 'A'; j <= 'z'; j++)
			f[i][j] = f[i - 1][j];
		f[i][c]++;
		t[c] = true;
	}
	for (int i = 1; i <= n; i++)
	{
		int l = -1, r = i + 1;
		while (r - l > 1)
		{
			if (check(f[i], f[(l + r) / 2]))
				l = (l + r) / 2;
			else
				r = (l + r) / 2;
		}
		if (l > -1 && i - l < min)
			min = i - l;
		if (check(f[0], f[i]) && i < min)
			min = i;
	}
	cout << min;
	return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <set>
#include <map>
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define F(i,n) for(int i = 0; i < n; i++)
using namespace std;
ll power(ll a,ll b) {
	if (b == 0)return 1;
	if (b % 2 == 0)return power(a*a%mod, b / 2);
	return a * power(a, b - 1) % mod;
}
int var = 0;
int q[52];
int main() {
	int n;
	string a;
	cin >> n >> a;
	F(i, n) {
		int z;
		if (a[i] >= 'a')z = a[i] - 'a';
		else z = a[i] - 'A' + 26;
		if (q[z] == 0)var++;
		q[z] = 1;
	}
	F(i, 52)q[i] = 0;
	int i = 0, j = 0;
	int c = 1;
	int w;
	if (a[j] >= 'a')w = a[j] - 'a';
	else w = a[j] - 'A' + 26;
	q[w] = 1;
	int ans = a.size();
	while (j < a.size()) {
		j++;
		int z;
		if (a[j] >= 'a')z = a[j] - 'a';
		else z = a[j] - 'A' + 26;
		if (q[z] == 0)c++;
		q[z]++;
		if (a[i] >= 'a')z = a[i] - 'a';
		else z = a[i] - 'A' + 26;
		while (i <= j && c == var && q[z]>=1) {
			q[z]--;
			ans = min(ans, j - i+1);
			i++;
		}
	}
	cout << ans;
	return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <set>
#include <map>
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define F(i,n) for(int i = 0; i < n; i++)
using namespace std;
ll power(ll a,ll b) {
	if (b == 0)return 1;
	if (b % 2 == 0)return power(a*a%mod, b / 2);
	return a * power(a, b - 1) % mod;
}
int var = 0;
int q[52];
int main() {
	int n;
	string a;
	cin >> n >> a;
	F(i, n) {
		int z;
		if (a[i] >= 'a')z = a[i] - 'a';
		else z = a[i] - 'A' + 26;
		if (q[z] == 0)var++;
		q[z] = 1;
	}
	F(i, 52)q[i] = 0;
	int i = 0, j = 0;
	int c = 0;
	int ans = a.size();
	while (j < a.size()) {
		int z;
		if (a[j] >= 'a')z = a[j] - 'a';
		else z = a[j] - 'A' + 26;
		if (q[z] == 0)c++;
		q[z]++;
		if (a[i] >= 'a')z = a[i] - 'a';
		else z = a[i] - 'A' + 26;
		while (c == var) {
			if (a[i] >= 'a')z = a[i] - 'a';
			else z = a[i] - 'A' + 26;
			q[z]--;
			if (q[z] == 0)c--;
			ans = min(ans, j - i + 1);
			i++;
		}
		j++;
	}
	cout << ans;
	return 0;
}


#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<utility>
//five elements
#include<iomanip>
#include <cstdlib>
#define ll long long
#define ef else if
#define rep(i,s,n) for(ll i=s;i<n;i=i+1)
#define rev(i,s,n) for(int i=s;i>n;i=i-1)
using namespace std;
#define fr first
#define se second
#define pb push_back
#define mp make_pair
#define mv vector<ll>
#define vv vector< vector<ll> >
#define vii vector< pair <ll,ll> >
#include <queue>
#include<map>
#include<set>
#include<functional>
//akane_psycho
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define c1( a )  cout<<a<<endl;
#define c2( a, b) cout<<a<<" "<<b<<endl;
#define c4 (k,x,b,c) printf( " %d %d %d %d ", &k,&x,&b,&c )
#define db double
#define inf 1e18
#define sinf 1e7
int main()
{
    freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll n;cin>>n;
	mv l,r;
	rep(i,1, (n+1)/2 +1 )l.pb(i);

	rep(i, (n+1)/2 +1  ,  n+1 )r.pb(i);

	cout<< (ll)(ceil(log(n)))<<endl;
	ll k =l.size() ;
	cout<<k<<" ";
	rep(i,0,k)cout<<l[i]<<" ";
	cout<<endl;
	k=k/2;

	while(k!=0)
	{
		ll j=0;
		rep(i,l.size()-k , l.size() )
		{
			ll t=l[i];
			l[i]=r[j];
			r[j]=t;
			j++;
		}
		cout<<l.size()<<" ";
		rep(i,0,l.size() )cout<<l[i]<<" ";
		cout<<endl;
		k=k/2;
	}
}


#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<utility>
//five elements
#include<iomanip>
#include <cstdlib>
#define ll long long
#define ef else if
#define rep(i,s,n) for(ll i=s;i<n;i=i+1)
#define rev(i,s,n) for(int i=s;i>n;i=i-1)
using namespace std;
#define fr first
#define se second
#define pb push_back
#define mp make_pair
#define mv vector<ll>
#define vv vector< vector<ll> >
#define vii vector< pair <ll,ll> >
#include <queue>
#include<map>
#include<set>
#include<functional>
//akane_psycho
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define c1( a )  cout<<a<<endl;
#define c2( a, b) cout<<a<<" "<<b<<endl;
#define c4 (k,x,b,c) printf( " %d %d %d %d ", &k,&x,&b,&c )
#define db double
#define inf 1e18
#define sinf 1e7
ll n;
void rec(vector<mv > v )
{

	/*cout<<"new "<<v.size()<<endl;
	rep(i,0,v.size() )
	{
		rep(j,0,v[i].size() )cout<<v[i][j]<<" ";
		cout<<endl;
	}*/
	if(v.size()==n)return ;

	vector<mv> t;
	mv ans;
	ll s=0;
	rep(i,0,v.size() )
	{

		mv h;
		rep(j,0, (v[i].size() + 1)/2  )
		{
			h.pb( v[i][j] );
			ans.pb(v[i][j]);
			s++;
		}
		if(h.size()>0)t.pb(h);
		mv k;

		rep(j, (v[i].size() + 1)/2  , v[i].size() )k.pb( v[i][j] );

		if(k.size()>0)t.pb(k);

	}
	cout<<s<<" ";
	rep(i,0,ans.size() )
	{
		cout<<ans[i]<<" ";
	}cout<<endl;
	rec(t);
	return;
}
int main()
{
	freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin>>n;
	vector< mv > v;
	mv t;
	rep(i,0,n)t.pb(i+1);
	v.pb(t);
	cout<< (ll)(ceil(log2(n)))<<endl;
	cout<<endl;
	rec(v);
}


#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;

int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
vector<int> tem[105];
void rec(int d, vector<int> v)
{
    if(v.size() <= 1)
        return;
    vector<int> xx;
    vector<int> yy;
    for(int i = 0; i < v.size(); ++i)
    {
        if(i % 2 == 0)
            tem[d].pb(v[i]), xx.pb(v[i]);
        else
            yy.pb(v[i]);
    }
    rec(d+1, xx);
    rec(d+1, yy);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ifstream f("input.txt");
    ofstream g("output.txt");
    int n;
    f >> n;
    vector<int> v;
    for(int i = 1; i <= n; ++i)
        v.pb(i);
    rec(1, v);
    int mx = 0;
    for(int i = 1; i <= 102; ++i)
        if(tem[i].size())
            mx = i;
    g << mx << '\n';
    for(int i = 1; i <= mx; ++i)
    {
        g << tem[i].size() << " ";
        for(int j = 0; j < tem[i].size(); ++j)
           g << tem[i][j] << " ";
        g << '\n';
    }
    return 0;
}


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

int main() {
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0xFFFFFFFF;
	int count = (n+1)/2;
	for(int b=0;b<bits;b++) {
		printf("%d", count);
		for(int i=0;i<count;i++) {
			int left = i & mask, right = i & ~mask;
			int res = (left << 1) | right;
			printf(" %d", res+1);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


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

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0x1;
	int count = (n+1)/2;
	printf("%d\n", bits);
	for(int b=0;b<bits;b++) {
		int count = 0;
		for(int i=1;i<=n;i++) {
			if(i & mask) count++;
		}
		printf("%d", count);
		for(int i=1;i<=n;i++) {
			if(i & mask) printf(" %d", i);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


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

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0x1;
	printf("%d\n", bits);
	for(int b=0;b<bits;b++) {
		int count = b == bits-1 ? 1 << b : (n+1)/2;
		printf("%d", count);
		for(int i=1;i<=n;i++) {
			if(i & mask) printf(" %d", i);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


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

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0xFFFFFFFF;
	int count = (n+1)/2;
	printf("%d\n", bits);
	for(int b=0;b<bits;b++) {
		printf("%d", count);
		for(int i=0;i<count;i++) {
			int left = i & mask, right = i & ~mask;
			int res = (left << 1) | right;
			printf(" %d", res+1);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


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

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0x1;
	int count = (n+1)/2;
	printf("%d\n", bits);
	for(int b=0;b<bits;b++) {
		printf("%d", count);
		for(int i=1;i<=n;i++) {
			if(i & mask) printf(" %d", i);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


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

int main() {
	freopen(stdin, "input.txt", "r");
	freopen(stdout, "output.txt", "w");
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0xFFFFFFFF;
	int count = (n+1)/2;
	for(int b=0;b<bits;b++) {
		printf("%d", count);
		for(int i=0;i<count;i++) {
			int left = i & mask, right = i & ~mask;
			int res = (left << 1) | right;
			printf(" %d", res+1);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


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

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n; scanf("%d",&n);
	int bits = 32 - __builtin_clz(n-1);
	int mask = 0xFFFFFFFF;
	int count = (n+1)/2;
	for(int b=0;b<bits;b++) {
		printf("%d", count);
		for(int i=0;i<count;i++) {
			int left = i & mask, right = i & ~mask;
			int res = (left << 1) | right;
			printf(" %d", res+1);
		}
		putchar('\n');
		mask <<= 1;
	}
	return 0;
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	vi v1(n/2);
	vi v2(n/2);
	rep(i,n/2){
		v1[i] = i+1;
		v2[i] = i+n/2+1;
	}
	vector<vector<int> > ans(0);
	ans.pb(v1);
	int cur = 1;
	rep(i,n/2-1){
		repa(j,cur,n/2){
			swap(v1[j],v2[j]);
		}
		ans.pb(v1);
	}
	if(n % 2){
		vector<int> v(1,n);
		ans.pb(v);
	}
	int sz = s(ans);
	cout<<sz<<"\n";
	rep(i,sz){
		cout<<s(ans[i])<<" ";
		rep(j,s(ans[i])){
			cout<<ans[i][j]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
int c;
vector<vector<int> > ans(1001);
void recur(int l,int r,int id){
	if(l == r)return;
	c = max(c,id);
	int mid = (l+r)/2;
	repa(i,l,mid+1)ans[id].pb(i);
	recur(l,mid,id+1);
	recur(mid+1,r,id+1);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	recur(1,n,1);
	cout<<c<<"\n";
	repa(i,1,c+1){
		cout<<s(ans[i])<<' ';
		rep(j,s(ans[i])){
			cout<<ans[i][j]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	vi v1(n/2);
	vi v2(n/2);
	rep(i,n/2){
		v1[i] = i+1;
		v2[i] = i+n/2+1;
	}
	vector<vector<int> > ans(0);
	ans.pb(v1);
	int cur = 1;
	rep(i,n/2-1){
		repa(j,cur,n/2){
			swap(v1[j],v2[j]);
		}
		ans.pb(v1);
		cur++;
	}
	if(n % 2){
		vector<int> v(1,n);
		ans.pb(v);
	}
	int sz = s(ans);
	cout<<sz<<"\n";
	rep(i,sz){
		cout<<s(ans[i])<<" ";
		rep(j,s(ans[i])){
			cout<<ans[i][j]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#include<ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define int long long
#define ld long double
#define pb push_back
#define pa pair<int,int>
#define v1d vector<int>
#define v2d vector<vector<int>>
#define v1p vector<pa>
#define INF 1000000007
#define M 998244353
#define mp make_pair
#define RS(v)    sort(v.rbegin(),v.rend())
#define PI 3.14159265
#define ff first
#define ss second
#define endl "\n"
#define v1s vector<string>
#define S(v) sort(v.begin(),v.end())
#define mxpq priority_queue <int>
#define mnpq priority_queue<int,vector<int>,greater<int>>

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
pbds;

void solve(){

    int n;
    cin>>n;;

    v2d ans;

    int k = 1;

    while(k <n){

        int bln = 1;
        v1d v;
        for(int j = 1 ;  j <= n ; j++){

            if(bln){
                v.pb(j);
            }

            if(j % k == 0){
                bln = !bln;
            }
        }

        k*=2;

        ans.pb(v);
    }

    cout<<ans.size()<<endl;

    for(auto i : ans){
        cout<<i.size()<<" ";
        for(auto j : i){
            cout<<j<<" ";
        }cout<<endl;
    }

}

int32_t main(){

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

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

    int tc = 1;
    // cin>>tc;

    while(tc--){
        solve();
    }

}


#include<bits/stdc++.h>

using namespace std;

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, len;
    cin >> n;
    int x = ceil(log(n) / log(2));
    cout << x << endl;
    for (int i = 0; i < x; ++i) {
        len = 0;
        for (int j = 0; j < n; ++j)
            if (j >> i & 1)
                ++len;
        cout << len << " ";
        for (int j = 0; j < n; ++j)
            if (j >> i & 1)
                cout << j + 1 << " ";
        cout << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main() {
    int n, len;
    cin >> n;
    int x = ceil(log(n) / log(2));
    cout << x << endl;
    for (int i = 0; i < x; ++i) {
        len = 0;
        for (int j = 0; j < n; ++j)
            if (j >> i & 1)
                ++len;
        cout << len << " ";
        for (int j = 0; j < n; ++j)
            if (j >> i & 1)
                cout << j + 1 << " ";
        cout << endl;
    }
}


#include <fstream>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int main()
{
    int n,l=0,p=1,i,j,nr;
    in>> n;
    while (p < n)
    {
        p <<= 1;
        l++;
    }
    out  << l << "\n";
    for (i = 0; i < l; i++)
    {
        nr = 0;
        for (j = 0; j < n; j++)
        {
            if (j & (1 << i))
            {
                nr++;
            }
        }
        out << nr << " ";
        for (j = 0; j < n; j++)
        {
            if (j & (1 << i))
            {
                out << j + 1 << " ";
            }
        }
        out << "\n";
    }
    return 0;
}


// G. Practice
// http://codeforces.com/problemset/problem/234/G
// rsampaths16
// 1 September 2018

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

int n;
int logN;
vector<int> a, b;

void part() {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 1; i < a.size(); i += 2) {
        swap(a[i], b[i]);
    }
}

void print() {
    int x = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] <= n) x++;
    }
    cout << x;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] <= n) {
            cout << ' ' << a[i];
        }
    }
    cout << endl;
}

int main() {
    cin >> n;
    logN = ceil(log2(n));
    cout << logN << endl;
    int tmp = 1 << (logN-1);
    for (int i = 0; i < tmp; i++) {
        a.push_back(i+1);
        b.push_back(i+tmp+1);
    }
    while (logN--) {
        print();
        part();
    }
    return 0;
}


// G. Practice
// http://codeforces.com/problemset/problem/234/G
// rsampaths16
// 1 September 2018

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

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int logN = ceil(log2(n));
    int w = 1 << logN;
    cout << logN << endl;
    while (logN--) {
        int m = 1 << logN;
        int cnt = 0;
        for (int i = 0; i < w; i++)
            if (i&m && i < n) cnt++;
        cout << cnt;
        for (int i = 0; i < w; i++)
            if (i&m && i < n) cout << ' ' << (i+1);
        cout << endl;
    }
    return 0;
}


// G. Practice
// http://codeforces.com/problemset/problem/234/G
// rsampaths16
// 1 September 2018

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

int n;
int logN;
vector<int> a, b;

void part() {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 1; i < a.size(); i += 2) {
        swap(a[i], b[i]);
    }
}

void print() {
    int x = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] <= n) x++;
    }
    cout << x;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] <= n) {
            cout << ' ' << a[i];
        }
    }
    cout << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> n;
    logN = ceil(log2(n));
    cout << logN << endl;
    int tmp = 1 << (logN-1);
    for (int i = 0; i < tmp; i++) {
        a.push_back(i+1);
        b.push_back(i+tmp+1);
    }
    while (logN--) {
        print();
        part();
    }
    return 0;
}


// G. Practice
// http://codeforces.com/problemset/problem/234/G
// rsampaths16
// 1 September 2018

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

int n;
int logN, m;
vector<int> a;

bool cmp(const int x, const int y) {
    return ((x >> logN)&1) < ((y >> logN)&1);
}

void print() {
    int x = 0;
    for (int i = 0; i < m; i++) {
        if (a[i] < n) x++;
    }
    cout << x;
    for (int i = 0; i < m; i++) {
        if (a[i] < n) {
            cout << ' ' << (a[i]+1);
        }
    }
    cout << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> n;
    logN = ceil(log2(n));
    cout << logN << endl;
    m = (1 << (logN-1));
    for (int i = 0; i < (1 << logN); i++) {
        a.push_back(i);
    }
    while (logN--) {
        sort(a.begin(), a.end(), cmp);
        print();
    }
    return 0;
}


// G. Practice
// http://codeforces.com/problemset/problem/234/G
// rsampaths16
// 1 September 2018

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

int n;
int logN, m;
vector<int> a, b;

void print() {
    int x = 0;
    for (int i = 0; i < m; i++) {
        int v = (a[i] & m) != 0;
        a[i] = a[i] & (m - 1);
        a[i] <<= 1;
        a[i] |= v;
        if (a[i] < n) x++;
    }
    cout << x;
    for (int i = 0; i < m; i++) {
        if (a[i] < n) {
            cout << ' ' << (a[i]+1);
        }
    }
    cout << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> n;
    logN = ceil(log2(n));
    cout << logN << endl;
    m = (1 << (logN-1));
    for (int i = 0; i < (1 << logN); i++) {
        a.push_back(i);
    }
    while (logN--) {
        print();
    }
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define all(v) v.begin(), v.end()

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

const int INF = INT_MAX;
const ll LLINF = LLONG_MAX;
const double EPS = 1.0e-9;
const double PI = atan(1.0) * 4.0;

typedef vector<int> vi;

pair<vi, vi> divide(const vi &v) {
    pair<vi, vi> res;
    for(int i = 0;i < v.size() / 2;i++)
        res.X.push_back(v[i]);
    for(int i = v.size() / 2;i < v.size();i++)
        res.Y.push_back(v[i]);
    return res;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    freopen("electro.in", "r", stdin);
//    freopen("electro.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n;
    cin >> n;
    vi s;
    for(int i = 0;i < n;i++)
        s.push_back(i);
    vector<vi> v;
    v.push_back(s);
    vector<vi> ans;
    while(!v.empty()) {
        ans.push_back(vi());
        vector<vi> com1, com2;
        while(!v.empty()) {
            if(v.back().size() == 1) {
                v.pop_back();
                continue;
            }
            auto seq = divide(v.back());
            v.pop_back();
            com1.push_back(seq.X);
            com2.push_back(seq.Y);
        }
        for(const vi &vv : com1) {
            for(const int &m : vv)
                ans.back().push_back(m);
        }
        for(const vi &e : com1) {
            if(e.size() > 1)
                v.push_back(e);
        }
        for(const vi &e : com2) {
            if(e.size() > 1)
                v.push_back(e);
        }
    }
    cout << ans.size() << '\n';
    for(const vi &vv : ans) {
        cout << vv.size() << ' ';
        for(const int &e : vv) {
            cout << e + 1 << ' ';
        }
        cout << '\n';
    }
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define all(v) v.begin(), v.end()

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

const int INF = INT_MAX;
const ll LLINF = LLONG_MAX;
const double EPS = 1.0e-9;
const double PI = atan(1.0) * 4.0;

typedef vector<int> vi;

pair<vi, vi> divide(const vi &v) {
    pair<vi, vi> res;
    for(int i = 0;i < v.size() / 2;i++)
        res.X.push_back(v[i]);
    for(int i = v.size() / 2;i < v.size();i++)
        res.Y.push_back(v[i]);
    return res;
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    freopen("electro.in", "r", stdin);
//    freopen("electro.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n;
    cin >> n;
    vi s;
    for(int i = 0;i < n;i++)
        s.push_back(i);
    vector<vi> v;
    v.push_back(s);
    vector<vi> ans;
    while(!v.empty()) {
        ans.push_back(vi());
        vector<vi> com1, com2;
        while(!v.empty()) {
            if(v.back().size() == 1) {
                v.pop_back();
                continue;
            }
            auto seq = divide(v.back());
            v.pop_back();
            com1.push_back(seq.X);
            com2.push_back(seq.Y);
        }
        for(const vi &vv : com1) {
            for(const int &m : vv)
                ans.back().push_back(m);
        }
        for(const vi &e : com1) {
            if(e.size() > 1)
                v.push_back(e);
        }
        for(const vi &e : com2) {
            if(e.size() > 1)
                v.push_back(e);
        }
    }
    cout << ans.size() << '\n';
    for(const vi &vv : ans) {
        cout << vv.size() << ' ';
        for(const int &e : vv) {
            cout << e + 1 << ' ';
        }
        cout << '\n';
    }
    return 0;
}


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

public class Main {

    private static PrintWriter pw;
    private static int n;

    private static void decomp(int[] left, int[] right, int count)
    {
        int cor = ((count %2) == 0) ?  0 : 1;
        count += cor;
        count >>= 1;

        if (count > 0)
        {
            ArrayList <Integer> left2 = new ArrayList <Integer> ();
            ArrayList <Integer> right2 = new ArrayList <Integer> ();
            int i = 0;
            while (true)
            {
                for (int j = i; j < Math.min(i+count, left.length); j++)
                    left2.add(left[j]);

                for (int j = i; j < Math.min(i+count, right.length); j++)
                    left2.add(right[j]);

                i += count-cor;
                if (count == 2)
                    i+= cor;

                if (i >= left.length)
                    break;

                for (int j = i; j < Math.min(i+count, left.length); j++)
                    right2.add(left[j]);

                for (int j = i; j < Math.min(i+count, right.length); j++)
                    right2.add(right[j]);

                i += count-cor;
                if (count == 1)
                    i+= cor;

                if (i >= left.length)
                    break;
            }

            int[] left22 = new int[left2.size()];
            for (int l = 0; l < left2.size(); ++l)
                left22[l] = left2.get(l);

            int[] right22 = new int[right2.size()];
            for (int l = 0; l < right2.size(); ++l)
                right22[l] = right2.get(l);

            if (left.length == n/2 || left.length == n/2 +1)
                decomp(left, right, count == 1 ? 0:count);
            else
                decomp(left22, right22, count == 1 ? 0:count);

            pw.print(left2.size()+ " ");
            for (int j : left2)
                pw.print(j+" ");
            pw.println();
        }
        else
        {
            int temp = count+1;
            int ans = 0;
            while (temp < n)
            {
                temp<<=1;
                ans++;
            }
            pw.println(ans);
        }
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner (new FileInputStream("input.txt"));
        pw = new PrintWriter(new FileOutputStream("output.txt"));

        n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; ++i)
            arr[i] = i+1;

        decomp(arr,new int[0],n);

        pw.close();
    }
}


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

public class Main {

    private static PrintWriter pw;
    private static int n;

    private static void decomp(int[] left, int[] right, int count)
    {
        count += ((count %2) == 0) ?  0 : 1;
        count >>= 1;

        if (count > 0)
        {
            ArrayList <Integer> left2 = new ArrayList <Integer> ();
            ArrayList <Integer> right2 = new ArrayList <Integer> ();
            int i = 0;
            while (true)
            {
                for (int j = i; j < Math.min(i+count, left.length); j++)
                    left2.add(left[j]);

                for (int j = i; j < Math.min(i+count, right.length); j++)
                    left2.add(right[j]);

                i += count;

                if (i >= left.length)
                    break;

                for (int j = i; j < Math.min(i+count, left.length); j++)
                    right2.add(left[j]);

                for (int j = i; j < Math.min(i+count, right.length); j++)
                    right2.add(right[j]);

                i += count;

                if (i >= left.length)
                    break;
            }

            int[] left22 = new int[left2.size()];
            for (int l = 0; l < left2.size(); ++l)
                left22[l] = left2.get(l);

            int[] right22 = new int[right2.size()];
            for (int l = 0; l < right2.size(); ++l)
                right22[l] = right2.get(l);

            decomp(left22, right22, count == 1 ? 0:count);

            pw.print(left2.size()+ " ");
            for (int j : left2)
                pw.print(j+" ");
            pw.println();
        }
        else
        {
            int temp = count+1;
            int ans = 0;
            while (temp < n)
            {
                temp<<=1;
                ans++;
            }
            pw.println(ans);
        }
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner (new FileInputStream("input.txt"));
        pw = new PrintWriter(new FileOutputStream("output.txt"));

        n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; ++i)
            arr[i] = i+1;

        decomp(arr,new int[0],n);

        pw.close();
    }
}


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

public class Main {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner (new FileInputStream("input.txt"));
        PrintWriter pw = new PrintWriter(new FileOutputStream("output.txt"));

        int n = sc.nextInt();

        int tempN = 1, ans = 0;
        while (tempN < n)
        {
            tempN <<= 1;
            ans++;
        }

        pw.println(ans);

        int count = 1;
        for(int i = 0; i < ans; ++i)
        {
            ArrayList <Integer> ret = new ArrayList <Integer> ();
            for (int l = 0; l < n; l+=2*count)
                for (int j = l; j<Math.min(l+count,n); j++)
                    ret.add(j+1);

            pw.print(ret.size()+ " ");
            for (int r : ret)
                pw.print(r + " ");
            pw.println();

            count <<= 1;
        }

        pw.close();
    }
}


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

public class Main {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner (new FileInputStream("input.txt"));
        PrintWriter pw = new PrintWriter(new FileOutputStream("output.txt"));

        int n = sc.nextInt();

        int tempN = n, ans = 0;
        while (tempN > 0)
        {
            tempN >>= 1;
            ans++;
        }

        pw.println(ans);

        int count = 1;
        for(int i = 0; i < ans; ++i)
        {
            ArrayList <Integer> ret = new ArrayList <Integer> ();
            for (int l = 0; l < n; l+=2*count)
                for (int j = l; j<Math.min(l+count,n); j++)
                    ret.add(j+1);

            pw.print(ret.size()+ " ");
            for (int r : ret)
                pw.print(r + " ");
            pw.println();

            count <<= 1;
        }

        pw.close();
    }
}


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

public class Main {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner (new FileInputStream("input.txt"));
        PrintWriter pw = new PrintWriter(new FileOutputStream("output.txt"));

        int n = sc.nextInt();

        int tempN = n;
        int ans1 = 0;
        while (tempN > 1)
        {
            if (tempN % 2 != 0)
                tempN++;

            tempN >>= 1;
            ans1++;
        }

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

        pw.println(ans1);
        tempN = n;
        while (tempN>1)
        {
            ArrayList <Integer> ans = new ArrayList <Integer> ();
            if (tempN % 2 != 0)
                tempN++;
            tempN>>=1;
            for (int i = 0; i < n; i+=tempN)
            {

                int[] temp = Arrays.copyOfRange(arr, i, i+tempN > n ? n: i+tempN);
                for (int j : temp)
                    ans.add(j);
                i+=tempN;
            }
            pw.print(ans.size()+" ");
            for (int j : ans)
                pw.print(j+" ");

            pw.println();
        }

        pw.close();
    }
}


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

public class Main {

    private static PrintWriter pw;
    private static int n;

    private static void decomp(int[] left, int[] right, int count)
    {
        count += ((count %2) == 0) ?  0 : 1;
        count >>= 1;

        if (count > 0)
        {
            ArrayList <Integer> left2 = new ArrayList <Integer> ();
            ArrayList <Integer> right2 = new ArrayList <Integer> ();
            int i = 0;
            while (true)
            {
                for (int j = i; j < Math.min(i+count, left.length); j++)
                    left2.add(left[j]);

                for (int j = i; j < Math.min(i+count, right.length); j++)
                    left2.add(right[j]);

                i += count;

                if (i >= left.length)
                    break;

                for (int j = i; j < Math.min(i+count, left.length); j++)
                    right2.add(left[j]);

                for (int j = i; j < Math.min(i+count, right.length); j++)
                    right2.add(right[j]);

                i += count;

                if (i >= left.length)
                    break;
            }

            int[] left22 = new int[left2.size()];
            for (int l = 0; l < left2.size(); ++l)
                left22[l] = left2.get(l);

            int[] right22 = new int[right2.size()];
            for (int l = 0; l < right2.size(); ++l)
                right22[l] = right2.get(l);

            if (left.length == n/2 || left.length == n/2 +1)
                decomp(left, right, count == 1 ? 0:count);
            else
                decomp(left22, right22, count == 1 ? 0:count);

            pw.print(left2.size()+ " ");
            for (int j : left2)
                pw.print(j+" ");
            pw.println();
        }
        else
        {
            int temp = count+1;
            int ans = 0;
            while (temp < n)
            {
                temp<<=1;
                ans++;
            }
            pw.println(ans);
        }
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner (new FileInputStream("input.txt"));
        pw = new PrintWriter(new FileOutputStream("output.txt"));

        n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; ++i)
            arr[i] = i+1;

        decomp(arr,new int[0],n);

        pw.close();
    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;

public class G {
    static PrintWriter out;

    public static void rec(int cnt, LinkedList<Point> E) {
        if (cnt == 0)
            return;
        LinkedList<Point> E2 = new LinkedList<Point>();
        for (Point p : E) {
            if (p.x == p.y)
                E2.add(p);
            else {
                int mid = (p.x + p.y) / 2;
                Point p1 = new Point(p.x, mid);
                Point p2 = new Point(mid + 1, p.y);
                E2.add(p1);
                E2.add(p2);
            }
        }
        int ans = 0;
        for (int i = 0; i < E2.size(); i += 2) {
            Point p = E2.get(i);
            ans += p.y - p.x + 1;
        }
        out.print(ans);
        for (int i = 0; i < E2.size(); i += 2) {
            Point p = E2.get(i);
            for (int j = p.x; j <= p.y; j++)
                out.print(" " + j);
        }
        out.println();
        rec(cnt - 1, E2);
    }

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new FileReader(new File(
                "input.txt")));
        out = new PrintWriter(new File("output.txt"));
        int n = Integer.parseInt(in.readLine());
        int cnt = 0;
        for (int i = 1; i < n; i <<= 1, cnt++)
            ;
        System.out.println(cnt);
        LinkedList<Point> E = new LinkedList<Point>();
        E.add(new Point(1, n));
        rec(cnt, E);
        out.flush();
        out.close();
    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;

public class G {
    static PrintWriter out;

    public static void rec(int cnt, LinkedList<Point> E) {
        if (cnt == 0)
            return;
        LinkedList<Point> E2 = new LinkedList<Point>();
        for (Point p : E) {
            if (p.x == p.y)
                E2.add(p);
            else {
                int mid = (p.x + p.y) / 2;
                Point p1 = new Point(p.x, mid);
                Point p2 = new Point(mid + 1, p.y);
                E2.add(p1);
                E2.add(p2);
            }
        }
        int ans = 0;
        for (int i = 0; i < E2.size(); i += 2) {
            Point p = E2.get(i);
            ans += p.y - p.x + 1;
        }
        out.print(ans);
        for (int i = 0; i < E2.size(); i += 2) {
            Point p = E2.get(i);
            for (int j = p.x; j <= p.y; j++)
                out.print(" " + j);
        }
        out.println();
        rec(cnt - 1, E2);
    }

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new FileReader(new File(
                "input.txt")));
        out = new PrintWriter(new File("output.txt"));
        int n = Integer.parseInt(in.readLine());
        int cnt = 0;
        for (int i = 1; i < n; i <<= 1, cnt++)
            ;
        out.println(cnt);
        LinkedList<Point> E = new LinkedList<Point>();
        E.add(new Point(1, n));
        rec(cnt, E);
        out.flush();
        out.close();
    }
}


import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class G {
    static StringBuilder sb;
    static int countt = 0;

    public static void solve(int st, int end) throws IOException {
        if (st == end)
            return;
        int mid = (st + end) / 2;
        int count = mid - st + 1;
        sb.append(count + " ");
        for (int i = st; i <= mid; i++) {
            sb.append(i + " ");
        }
        sb.append("\n");
        countt++;
        solve(st, mid);
        solve(mid + 1, end);
    }

    public static void main(String[] args) throws IOException {
     //Scanner sc = new Scanner(System.in);
      Scanner sc = new Scanner(new FileReader("input.txt"));
        FileWriter fw = new FileWriter("output.txt");
        sb = new StringBuilder();
        solve(1, sc.nextInt());
        System.out.println(countt);
        System.out.println(sb);
        fw.write(countt + "\n" + sb.toString() + "\n");
        fw.flush();
        fw.close();
        sc.close();
    }
}


import java.awt.Point;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class G {
    static StringBuilder sb;
    static int countt = 0;

    public static void solve(ArrayList<Point> fir, ArrayList<Point> sec) {
        int sum = 0;
        StringBuilder sb1=new StringBuilder();
        if (fir.size() > 0)
            for (int i = 0; i < fir.size(); i++) {
                sum+=(fir.get(i).y-fir.get(i).x+1);
                for (int j = fir.get(i).x; j <= fir.get(i).y; j++)
                    sb1.append(j + " ");
            }
        else if (sec.size() > 0)
            for (int i = 0; i <sec.size(); i++) {
                sum+=(fir.get(i).y-fir.get(i).x+1);
                for (int j = sec.get(i).x; j <= sec.get(i).y; j++)
                    sb1.append(j + " ");
            }
        else
            return;
        sb.append(sum+" "+sb1+"\n");
        countt++;
        ArrayList<Point> newFir = new ArrayList<Point>();
        ArrayList<Point> newSec = new ArrayList<Point>();
        for (Point f : fir) {
            if (f.y - f.x >= 1) {
                int mid = (f.x + f.y) / 2;
                newFir.add(new Point(f.x, mid));
                newSec.add(new Point(mid + 1, f.y));
            }
        }
        for (Point f : sec) {
            if (f.y - f.x >= 1) {
                int mid = (f.x + f.y) / 2;
                newSec.add(new Point(f.x, mid));
                newFir.add(new Point(mid + 1, f.y));
            }
        }
        solve(newFir, newSec);
    }

    public static void main(String[] args) throws IOException {
        //Scanner sc = new Scanner(System.in);
         Scanner sc = new Scanner(new FileReader("input.txt"));
        FileWriter fw = new FileWriter("output.txt");
        int n=sc.nextInt();
        sb = new StringBuilder();
        ArrayList<Point> fir=new ArrayList<Point>();
        ArrayList<Point> sec=new ArrayList<Point>();
        int mid=(1+n)/2;
        fir.add(new Point(1,mid));
        sec.add(new Point(mid+1,n));
        solve(fir,sec);
        System.out.println(countt);
        System.out.println(sb);
        fw.write(countt + "\n" + sb.toString() + "\n");
        fw.flush();
        fw.close();
        sc.close();
    }
}


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

public class P234G
{
    public static StringTokenizer st;
    public static void nextLine(BufferedReader br) throws IOException
    {
        st = new StringTokenizer(br.readLine());
    }

    public static String next()
    {
        return st.nextToken();
    }

    public static int nextInt()
    {
        return Integer.parseInt(st.nextToken());
    }

    public static long nextLong()
    {
        return Long.parseLong(st.nextToken());
    }

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new FileReader("input.txt"));
        nextLine(br);
        PrintWriter pw = new PrintWriter("output.txt");
        int n = nextInt();
        int k = 1;
        while ((1 << k) < n) k++;
        ArrayList<Integer>[] list = new ArrayList[k];
        for (int i = 0; i < k; i++) list[i] = new ArrayList<Integer>();
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < k; j++)
            {
                if (((i >> j) & 1) == 0)
                {
                    list[j].add(i);
                }
            }
        }
        pw.println(k);
        for (int i = 0; i < k; i++)
        {
            pw.print(list[i].size());
            for (int j = 0; j < list[i].size(); j++)
            {
                pw.print(" " + String.valueOf(list[i].get(j)+1));
            }
            pw.println();
        }
        pw.close();
    }
}


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

public class P234G
{
    public static StringTokenizer st;
    public static void nextLine(BufferedReader br) throws IOException
    {
        st = new StringTokenizer(br.readLine());
    }

    public static String next()
    {
        return st.nextToken();
    }

    public static int nextInt()
    {
        return Integer.parseInt(st.nextToken());
    }

    public static long nextLong()
    {
        return Long.parseLong(st.nextToken());
    }

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new FileReader("input.txt"));
        nextLine(br);
        PrintWriter pw = new PrintWriter("output.txt");
        int n = nextInt();
        int k = 1;
        while ((1 << k) < n) k++;
        ArrayList<Integer>[] list = new ArrayList[k];
        for (int i = 0; i < k; i++) list[i] = new ArrayList<Integer>();
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < k; j++)
            {
                if (((i >> j) & 1) == 0)
                {
                    list[j].add(i);
                }
            }
        }
        pw.println(k);
        for (int i = 0; i < k; i++)
        {
            for (int j = 0; j < list[i].size(); j++)
            {
                if (j != 0) pw.print(" ");
                pw.print(list[i].get(j));
            }
            pw.println();
        }
        pw.close();
    }
}


/**
 * Created with IntelliJ IDEA.
 * User: Jovfer_S
 * Date: 11.10.12
 * Time: 14:57
 * To change this template use File | Settings | File Templates.
 */

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

public class taskG {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        taskG solver = new taskG();
        solver.open();
        long time = System.currentTimeMillis();
        solver.solve();
        if (!"true".equals(System.getProperty("ONLINE_JUDGE"))) {
            System.out.println("Spent time: "
                    + (System.currentTimeMillis() - time));
        }
        solver.close();
    }

    public void open() throws IOException {
        // TODO
//        in = new BufferedReader(new InputStreamReader(System.in));
//        out = new PrintWriter(System.out);
        in = new BufferedReader(new FileReader("input.txt"));
        out = new PrintWriter(new FileWriter("output.txt"));
    }

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null)
                return null;
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    boolean free[], ms[][];
    ArrayList<Integer> team;
    Set<Integer> teamSet;

    public void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        int answ = 1, tmp = 2;
        while (tmp < n) {
            answ++;
            tmp *= 2;
        }
        out.println(answ);
        ms = new boolean[n][n];
        free = new boolean[n];
        teamSet = new TreeSet<Integer>();
        team = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                ms[i][j] = i != j;
            }
        }

        for (int step = 0; step < answ; step++) {
            Arrays.fill(free, true);
            team.clear();
            teamSet.clear();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (free[i] && free[j] && ms[i][j]) {
                        team.add(i);
                        teamSet.add(i);
                        ms[i][j] = false;
                        ms[j][i] = false;
                        free[i] = false;
                        free[j] = false;
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                if (free[i])  {
                    team.add(i);
                    teamSet.add(i);
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    ms[i][j] &= (teamSet.contains(i) == teamSet.contains(j));
                }
            }
            int sz = team.size();
            out.print(sz);
            for (int i = 0; i < sz; i++) {
                out.print(" "+(team.get(i)+1));
            }
            out.println();
        }

    }

    public void close() {
        out.flush();
        out.close();
    }
}


/**
 * Created with IntelliJ IDEA.
 * User: Jovfer_S
 * Date: 11.10.12
 * Time: 14:57
 * To change this template use File | Settings | File Templates.
 */

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

public class taskG {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        taskG solver = new taskG();
        solver.open();
        long time = System.currentTimeMillis();
        solver.solve();
        if (!"true".equals(System.getProperty("ONLINE_JUDGE"))) {
            System.out.println("Spent time: "
                    + (System.currentTimeMillis() - time));
        }
        solver.close();
    }

    public void open() throws IOException {
        // TODO
//        in = new BufferedReader(new InputStreamReader(System.in));
//        out = new PrintWriter(System.out);
        in = new BufferedReader(new FileReader("input.txt"));
        out = new PrintWriter(new FileWriter("output.txt"));
    }

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null)
                return null;
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    boolean free[], ms[][];
    ArrayList<Integer> team;
    Set<Integer> teamSet;

    public void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        int answ = 1, tmp = 2;
        while (tmp < n) {
            answ++;
            tmp *= 2;
        }
        out.println(answ);
        ms = new boolean[n][n];
        free = new boolean[n];
        teamSet = new HashSet<Integer>();
        team = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                ms[i][j] = i != j;
            }
        }

        for (int step = 0; step < answ; step++) {
            Arrays.fill(free, true);
            team.clear();
            teamSet.clear();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (free[i] && free[j] && ms[i][j]) {
                        team.add(i);
                        teamSet.add(i);
                        ms[i][j] = false;
                        ms[j][i] = false;
                        free[i] = false;
                        free[j] = false;
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                if (free[i])  {
                    team.add(i);
                    teamSet.add(i);
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    ms[i][j] &= (teamSet.contains(i) == teamSet.contains(j));
                }
            }
            int sz = team.size();
            out.print(sz);
            for (int i = 0; i < sz; i++) {
                out.print(" "+(team.get(i)+1));
            }
            out.println();
        }

    }

    public void close() {
        out.flush();
        out.close();
    }
}


#include <cmath>
#include <iostream>
#include <map>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>

using namespace std;

vector < vector <long long> > a(100);
long long ans = 0;

void func(long long l, long long r, long long u)
{
    //cout << l << ' ' << r << endl;
    ans = max(ans, u);
    //cout << ans << endl;
    if (l >= r)
        return;
    for (int i = l; i <= (l + r) / 2; i++)
        {
            a[u].push_back(i);
            cerr << i << endl;
        }
    func(l, (l + r) / 2, u + 1);
    func((l + r) / 2 + 1, r, u + 1);
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    long long n;
    cin >> n;
    //if (n % 2 == 0)
    //  m = n / 2;
    //else
    //     m = n / 2 + 1;

    func(1, n, 0);
    /*
    for (long long i = 0; i < m; i++)
    {
        long long x;
        i % 2 == 0 || n % 2 == 0 ? x = m : x = m - 1;
        printf("%d ", x);
        for (int j = 1; j <= m; j++)
        {
            if (a[j] != n + 1)
                printf("%d ", a[j]);
            if (j > i + 1)
                f == 0 ? a[j] += m : a[j] -= m;
        }
        f = 1 - f;
        cout << endl;
    }*/
    cout << ans << endl;
    for (int i = 0; i < ans; i++)
    {
        long long sz = a[i].size();
        printf("%I64d ", sz);
        for (int j = 0; j < sz; j++)
            printf("%I64d ", a[i][j]);
        printf("\n");
    }
    return 0;
}


#include <cmath>
#include <iostream>
#include <map>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>

using namespace std;

vector <int> a(1000);

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n, m;
    cin >> n;
    if (n % 2 == 0)
        m = n / 2;
    else
        m = n / 2 + 1;
    for (int i = 1; i <= m; i++)
        a[i] = i;
    cout << m << endl;
    int f = 0;
    for (int i = 0; i < m; i++)
    {
        int x;
        i % 2 == 0 || n % 2 == 0 ? x = m : x = m - 1;
        printf("%d ", x);
        for (int j = 1; j <= m; j++)
        {
            if (a[j] != n + 1)
                printf("%d ", a[j]);
            if (j > i + 1)
                f == 0 ? a[j] += m : a[j] -= m;
        }
        f = 1 - f;
        cout << endl;
    }
    return 0;
}


#include <cmath>
#include <iostream>
#include <map>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>

using namespace std;

vector < vector <long long> > a(100);
long long ans = 0;

void func(long long l, long long r, long long u)
{
    //cout << l << ' ' << r << endl;
    ans = max(ans, u);
    //cout << ans << endl;
    if (l >= r)
        return;
    for (int i = l; i <= (l + r) / 2; i++)
        {
            a[u].push_back(i);
            cerr << i << endl;
        }
    func(l, (l + r) / 2, u + 1);
    func((l + r) / 2 + 1, r, u + 1);
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    long long n;
    cin >> n;
    //if (n % 2 == 0)
    //  m = n / 2;
    //else
    //     m = n / 2 + 1;

    func(1, n, 0);
    /*
    for (long long i = 0; i < m; i++)
    {
        long long x;
        i % 2 == 0 || n % 2 == 0 ? x = m : x = m - 1;
        printf("%d ", x);
        for (int j = 1; j <= m; j++)
        {
            if (a[j] != n + 1)
                printf("%d ", a[j]);
            if (j > i + 1)
                f == 0 ? a[j] += m : a[j] -= m;
        }
        f = 1 - f;
        cout << endl;
    }*/
    cout << ans << endl;
    for (int i = 0; i < ans; i++)
    {
        long long sz = a[i].size();
        printf("%I64d ", sz);
        for (int j = 0; j < sz; j++)
            printf("%I64d ", a[i][j]);
        printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<iterator>
using namespace std;
#define Enter putchar(10)
#define Space putchar(32)
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))
#define mp make_pair
#define m0(x) memset((x),0,sizeof(x))
#define mff(x) memset((x),0xff,sizeof(x))
#define sqr(x) ((x)*(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define sqrn(x,n) (int k=1,for(int i=0;i<n;++i){k*=x},k)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
//���ﶨ�峣����
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};//��������ϵ������������
const int MAX_N=3500; //�ύ֮ǰ�ĳ�20020
//������������
void in();
void solve();
//���ﶨ��ȫ�ֱ���
int n;
vector<int> v;
/*��ʽ��������￪ʼ*/
int main()
{
//#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
//#endif
	in();
	solve();
	return 0;
}
void in()
{
	scanf("%d",&n);
}
void solve()
{
	int dv=n-1;
	int cnt=1;
	int pos;
	for(cnt=1,dv=1;dv<n;++cnt,dv<<=1);
	printf("%d\n",cnt-1);
	dv=1;
	do{
		cnt=0;pos=1;
		int i=0;
		v.clear();
		while(pos+i<=n)
		{
			for(i=0;i<dv&&pos+i<=n;++i)
			{
				v.pb(pos+i);++cnt;
			}
			pos+=dv*2;i=0;
		}
		printf("%d %d",cnt,v[0]);
		for(int i=1;i<v.size();++i)
		{
			printf(" %d",v[i]);
		}Enter;
		dv<<=1;
	}while(dv<n);
}


#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

int a[1010];

vector<vector<int> > ans;

int main()
{
    int n;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    //printf("%f", (double)sqrt(3.0));
    for (int i = 1; i < n; i = i << 1)
    {
        int counter = 0, choose = 0;
        for (int j = 0; j < n; j++)
        {
            a[j] = choose;
            counter++;
            if (counter == i)
            {
                choose = 1-choose;
                counter = 0;
            }
        }
        vector<int> temp;
        ans.push_back(temp);
        for (int j = 0; j < n; j++)
        {
            if (a[j] == 0)
            {
                ans[ans.size()-1].push_back(j+1);
            }
        }
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++)
    {
        printf("%d ", ans[i].size());
        for (int j = 0; j < ans[i].size(); j++)
            printf("%d ", ans[i][j]);
        printf("\n");
    }
    //divide(n);
    return 0;
}


#include <bits/stdc++.h> //importa todo
using namespace std; //para no escribir std::

vector<vector <int>> teams;
int n;

void solve(int l, int r){
    // cout << l << ' ' << r << endl;
    if (l == r) return;

    int m = (l + r ) / 2;
    vector<int> new_team;
    for (size_t i = l; i <= m; i++)
    {
        new_team.push_back(i);
    }
    teams.push_back(new_team);
    solve(l,m);
    solve(m + 1,r);
}

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >> n;
    solve(1,n);
    cout << teams.size() << endl;
    for(auto team: teams){
        cout << team.size() << ' ';
        for(auto t: team){
            cout << t << ' ';
        }
        cout << endl;
    }

}


#include <bits/stdc++.h> //importa todo
using namespace std; //para no escribir std::

vector<vector <int>> teams;
int n;

void solve(int l, int r){
    // cout << l << ' ' << r << endl;
    if (l == r) return;

    int m = (l + r ) / 2;
    vector<int> new_team;
    for (size_t i = l; i <= m; i++)
    {
        new_team.push_back(i);
    }
    teams.push_back(new_team);
    solve(l,m);
    solve(m + 1,r);
}

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >> n;
    solve(1,n);
    for(auto team: teams){
        cout << team.size() << ' ';
        for(auto t: team){
            cout << t << ' ';
        }
        cout << endl;
    }

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; ++i)
// -------------------------------
vector<vector<int>> teams;
void search(int l, int r, int i) {
    int m = (l+r) >> 1;
    if (teams.size() == i) teams.resize(i+1);
    rep(k,l,m) teams[i].push_back(k);
    if (m-l > 1) search(l,m,i+1);
    if (r-m > 1) search(m,r,i+1);
}
int main() {
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    search(0,n,0);
    cout << teams.size() << '\n';
    for (auto& team : teams) {
        cout << team.size();
        for (int x : team) cout << ' ' << x+1;
        cout << '\n';
    }
    return 0;
}


#include <bits/stdc++.h> //importa todo
using namespace std; //para no escribir std::

vector<vector <int>> teams;
int n;

void solve(int l, int r, int level){
    // cout << l << ' ' << r << endl;
    if (l == r) return;

    int m = (l + r ) / 2;
    vector<int> new_team;
    if (teams.size() == level) teams.push_back(new_team);
    for (size_t i = l; i <= m; i++)
    {
        teams[level].push_back(i);
    }
    solve(l,m, level + 1);
    solve(m + 1, r, level + 1);
}

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >> n;
    solve(1,n,0);
    cout << teams.size() << endl;
    for(auto team: teams){
        cout << team.size() << ' ';
        for(auto t: team){
            cout << t << ' ';
        }
        cout << endl;
    }

}


#include <cstdio>

FILE *in, *out;

const int N = 1010;
int n, k, a[N];

int main()
{
#ifdef CASA
	in = stdin;
	out = stdout;
#else
	in = fopen("input.txt", "r");
	out = fopen("output.txt", "w");
#endif
	fscanf(in, "%d", &n);
	for (k = 1; 1 << k < n; k++);
	fprintf(out, "%d\n", k);
	for (int i = k; i >= 0; i--)
	{
		int d = 0;
		for (int j = 0; j < n; j++) if (j >> i & 1) a[++d] = j + 1;
		if (d)
		{
			fprintf(out, "%d ", d);
			for (int i = 1; i <= d; i++) fprintf(out, "%d ", a[i]);
			fprintf(out, "\n");
		}
	}
	return 0;
}


/// PELE SAID I'M THE BEST IN THE WORLD
/// I SAY I'M THE BEST IN THE WORLD
/// THAT'S HOW YOU SHOULD DO IT.
/// NEVER LOOK AT AN OPPONENT WITH INFERIORITY!
/// John Best, Balon d'Or
#include <bits/stdc++.h>
#define MOD 1000000007
#define Nmax 1005
#define pb push_back
#define VAL 1000005
#define INF 1000000000
#define eps 0.000000000001

using namespace std;

int n,cnt,v1[Nmax],v2[Nmax];
bool viz[Nmax][Nmax];
vector <int> Solution[50];

int main()
{
    int i,j,l1=0,l2=0,k1,k2,ok;
    /*#ifndef ONLINE_JUDGE
        freopen ("date.in","r",stdin);
        freopen ("date.out","w",stdout);
    #endif*/

    ifstream cin("input.txt");
    ofstream cout("output.txt");

    cin.sync_with_stdio(0);
    cin>>n;
    for(i=0;i<=10;++i)
    {
        l1=l2=ok=0;
        for(j=1;j<=n;++j)
            if((j&(1<<i))) v1[++l1]=j;
            else v2[++l2]=j;
        for(k1=1;k1<=l1 && !ok;++k1)
            for(k2=1;k2<=l2 && !ok;++k2)
                if(!viz[v1[k1]][v2[k2]])
                    ok=1;
        if(ok)
        {
            ++cnt;
            for(k1=1;k1<=l1;++k1)
                for(k2=1;k2<=l2;++k2) viz[v1[k1]][v2[k2]]=viz[v2[k2]][v1[k1]]=true;
            Solution[cnt].pb(l1);
            for(k1=1;k1<=l1;++k1) Solution[cnt].pb(v1[k1]);
        }
    }
    cout<<cnt<<"\n";
    for(i=1;i<=cnt;++i)
    {
        for(auto it : Solution[i]) cout<<it<<" ";
        cout<<"\n";
    }
    return 0;
}


/// PELE SAID I'M THE BEST IN THE WORLD
/// I SAY I'M THE BEST IN THE WORLD
/// THAT'S HOW YOU SHOULD DO IT.
/// NEVER LOOK AT AN OPPONENT WITH INFERIORITY!
/// John Best, Balon d'Or
#include <bits/stdc++.h>
#define MOD 1000000007
#define Nmax 1005
#define pb push_back
#define VAL 1000005
#define INF 1000000000
#define eps 0.000000000001

using namespace std;

int n,cnt,v1[Nmax],v2[Nmax];
bool viz[Nmax][Nmax];
vector <int> Solution[50];

int main()
{
    int i,j,l1=0,l2=0,k1,k2,ok;
    #ifndef ONLINE_JUDGE
        freopen ("date.in","r",stdin);
        freopen ("date.out","w",stdout);
    #endif
    cin.sync_with_stdio(0);
    cin>>n;
    for(i=0;i<=10;++i)
    {
        l1=l2=ok=0;
        for(j=1;j<=n;++j)
            if((j&(1<<i))) v1[++l1]=j;
            else v2[++l2]=j;
        for(k1=1;k1<=l1 && !ok;++k1)
            for(k2=1;k2<=l2 && !ok;++k2)
                if(!viz[v1[k1]][v2[k2]])
                    ok=1;
        if(ok)
        {
            ++cnt;
            for(k1=1;k1<=l1;++k1)
                for(k2=1;k2<=l2;++k2) viz[v1[k1]][v2[k2]]=viz[v2[k2]][v1[k1]]=true;
            Solution[cnt].pb(l1);
            for(k1=1;k1<=l1;++k1) Solution[cnt].pb(v1[k1]);
        }
    }
    cout<<cnt<<"\n";
    for(i=1;i<=cnt;++i)
    {
        for(auto it : Solution[i]) cout<<it<<" ";
        cout<<"\n";
    }
    return 0;
}


// IN THE NAME OF ALLAH
#include <math.h>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include<cstring>
#include <cstdlib>
#include <string>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int , int>

using namespace std;
typedef long long ll;

const int N = 1e3 + 5, Mod = 1e9 + 7, MAXN = 3e5 + 10, LG = 25 , M = 1e7 + 1, P = 727, Sq = 400;
const ll inf = 3e18 + 10;

int n, is[N][N];
vector< int > m, fan;

int main(){
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      ios_base::sync_with_stdio(0); cin.tie(0);
      cin >> n;
      for(int i = 0; i <= LG; i++){
            int t1 = 0, t2 = 0;
            for(int j = 1; j <= n; j++){
                  if(((1 << i) & j) > 0)
                        t1++;
                  else
                        t2++;
            }
            if(!min(t1, t2))
                  continue;
            else
                  m.push_back(i);
      }
      for(int i = 0; i < (int)m.size(); i++){
            vector< int > ret, bad;
            int bt = m[i];
            bool sw = false;
            for(int j = 1; j <= n; j++){
                  if(((1 << bt) & j) > 0)
                        ret.push_back(j);
                  else
                        bad.push_back(j);
            }
            for(int j = 0; j < (int)ret.size(); j++){
                  for(int k = 0; k < (int)bad.size(); k++){
                        if(!is[ret[j]][bad[k]])
                              sw = true;
                        is[ret[j]][bad[k]] = is[bad[k]][ret[j]] = 1;
                  }
            }
            if(sw)
                  fan.push_back(m[i]);
      }
      cout << (int)fan.size() << '\n';
      for(int i = 0; i < (int)fan.size(); i++){
            vector< int > ret;
            int bt = m[i];
            for(int j = 1; j <= n; j++){
                  if(((1 << bt) & j) > 0)
                        ret.push_back(j);
            }
            cout << (int)ret.size() << " ";
            for(int j = 0; j < (int)ret.size(); j++)
                  cout << ret[j] << " ";
            cout << '\n';
      }
      return 0;
}


//there’s light at end of every dark tunnel...keep moving
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);

vector<ll>ans[1000001];
ll rounds,n;
void solve(ll l,ll r,ll no)
{
	if(l>=r)
	return;
	rounds=max(rounds,no);
	ll mid=(l+r)/2;
	for(ll i=l;i<=mid;i++)
	ans[no].pb(i);
	solve(l,mid,no+1);
	solve(mid+1,r,no+1);
}
int main()
{
	ll i,j;
	cin>>n;
	solve(1,n,1);
	cout<<rounds<<endl;
	for(i=1;i<=rounds;i++)
	{
		cout<<ans[i].size()<<" ";
		for(j=0;j<ans[i].size();j++)
		cout<<ans[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}


//there’s light at end of every dark tunnel...keep moving
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);

vector<ll>ans[1000001];
ll rounds,n;
void solve(ll l,ll r,ll no)
{
	if(l>=r)
	return;
	rounds=max(rounds,no);
	ll mid=(l+r)/2;
	for(ll i=l;i<=mid;i++)
	ans[no].pb(i);
	solve(l,mid,no+1);
	solve(mid+1,r,no);
}
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	ll i,j;
	cin>>n;
	solve(1,n,1);
	cout<<rounds<<endl;
	for(i=1;i<=rounds;i++)
	{
		cout<<ans[i].size()<<" ";
		for(j=0;j<ans[i].size();j++)
		cout<<ans[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}


//there’s light at end of every dark tunnel...keep moving
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);

vector<ll>ans[1000001];
ll rounds,n;
void solve(ll l,ll r,ll no)
{
	if(l>=r)
	return;
	rounds=max(rounds,no);
	ll mid=(l+r)/2;
	for(ll i=l;i<=mid;i++)
	ans[no].pb(i);
	solve(l,mid,no+1);
	solve(mid+1,r,no+1);
}
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	ll i,j;
	cin>>n;
	solve(1,n,1);
	cout<<rounds<<endl;
	for(i=1;i<=rounds;i++)
	{
		cout<<ans[i].size()<<" ";
		for(j=0;j<ans[i].size();j++)
		cout<<ans[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}


#include <cstdio>

#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

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

   int N;
   scanf("%d", &N);

   VVI res;
   for (int len = 1; len < N; len *= 2) {
      VI v;
      for (int i = 0; i < N; i += len*2) {
         for (int k = 0; k < len && i+len < N; ++k)
            v.push_back(i+k);
      }

      res.emplace_back(v);
   }

   printf("%d\n", (int) res.size());
   for (const VI& v : res) {
      printf("%d", (int) v.size());
      for (int x : v)
         printf(" %d", x+1);
      putchar('\n');
   }

   return 0;
}


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

typedef long long ll;

typedef pair<int,int> ii;

int n;

void solve() {
    int res = ceil(log(n)/log(2));
    cout << res << '\n';
    for(int i = 0; i < res; i++) {
        vector<int> res;
        for(int j = 0; j <= n; j++) {
            if (j & (1 << i)) res.push_back(j);
        }
        cout << res.size() << ' ';
        for(auto e : res) cout << e << ' ';
        cout << '\n';
    }

}

int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    solve();
}//hello


/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long i64;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <i64, i64> pll;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

template <typename T>
T Max(T a, T b) {
    if(a < b) return b;
    return a;
}

template <typename T>
T Min(T a, T b) {
    if(a < b) return a;
    return b;
}

template <typename T>
T Abs(T a) {
    if(a < 0) return -a;
    return a;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void SetIO() {
#ifdef CP
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // CP
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e3;

vector <int> solst[5 + N];
vector <int> soldr[5 + N];

void Solve(int lev, vector <int> v) {
    if(v.size() < 2) return;

    vector <int> st, dr;
    for(int i = 0; i < v.size(); i++) {
        if(i % 2 == 0) {
            solst[lev].push_back(v[i]);
            st.push_back(v[i]);
        } else {
            soldr[lev].push_back(v[i]);
            dr.push_back(v[i]);
        }
    }
    Solve(lev + 1, st);
    Solve(lev + 1, dr);
}
vector <int> v;

int main() {
    SetIO();

    int n;
    cin >> n;

    int i;
    for(i = 0; (1 << i) < n; i++);
    cout << i << '\n';

    for(int i = 1; i <= n; i++) v.push_back(i);

    Solve(1, v);
    for(int j = 1; j <= i; j++) {
        cout << solst[j].size() << ' ';
        for(auto it : solst[j])
            cout << it << " ";
        cout << '\n';
    }
    return 0;
}


/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long i64;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <i64, i64> pll;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

template <typename T>
T Max(T a, T b) {
    if(a < b) return b;
    return a;
}

template <typename T>
T Min(T a, T b) {
    if(a < b) return a;
    return b;
}

template <typename T>
T Abs(T a) {
    if(a < 0) return -a;
    return a;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void SetIO() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e3;

vector <int> solst[5 + N];
vector <int> soldr[5 + N];

void Solve(int lev, vector <int> v) {
    if(v.size() < 2) return;

    vector <int> st, dr;
    for(int i = 0; i < v.size(); i++) {
        if(i % 2 == 0) {
            solst[lev].push_back(v[i]);
            st.push_back(v[i]);
        } else {
            soldr[lev].push_back(v[i]);
            dr.push_back(v[i]);
        }
    }
    Solve(lev + 1, st);
    Solve(lev + 1, dr);
}
vector <int> v;

int main() {
    SetIO();

    int n;
    cin >> n;

    int i;
    for(i = 0; (1 << i) < n; i++);
    cout << i << '\n';

    for(int i = 1; i <= n; i++) v.push_back(i);

    Solve(1, v);
    for(int j = 1; j <= i; j++) {
        cout << solst[j].size() << ' ';
        for(auto it : solst[j])
            cout << it << " ";
        cout << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
using namespace std;
vector<int> t1[15];
int dep = 0;
void recur (int l, int r, int d) {
	if (l >= r) return;
	dep = max(dep, d);
	int m = (l + r) / 2;
	for (int i = l; i <= m; i++) t1[d].pb(i);
	recur(l, m, d + 1); recur(m + 1, r, d + 1);
	return;
}
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d", &a);
	recur(1, a, 1);
	printf("%d\n", dep);
	cout << dep << endl;
	for (i = 1; i <= dep; i++) {
		printf("%d", int(t1[i].size()));
		cout << " " << t1[i].size();
		for (j = 0; j < t1[i].size(); j++) {
			printf(" %d", t1[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
using namespace std;
vector<int> t1[15];
int dep = 0;
void recur (int l, int r, int d) {
	if (l >= r) return;
	dep = max(dep, d);
	int m = (l + r) / 2;
	for (int i = l; i <= m; i++) t1[d].pb(i);
	recur(l, m, d + 1); recur(m + 1, r, d + 1);
	return;
}
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d", &a);
	recur(1, a, 1);
	printf("%d\n", dep);
	for (i = 1; i <= dep; i++) {
		printf("%d", int(t1[i].size()));
		for (j = 0; j < t1[i].size(); j++) {
			printf(" %d", t1[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
using namespace std;
vector<int> t1[15];
int dep = 0;
void recur (int l, int r, int d) {
	if (l >= r) return;
	dep = max(dep, d);
	int m = (l + r) / 2;
	for (int i = l; i <= m; i++) t1[d].pb(i);
	recur(l, m, d + 1); recur(m + 1, r, d + 1);
	return;
}
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d", &a);
	recur(1, a, 1);
	printf("%d\n", dep);
	return 0;
	for (i = 1; i <= dep; i++) {
		printf("%d ", int(t1[i].size()));
		for (j = 0; j < t1[i].size(); j++) {
			printf("%d%c", t1[i][j], (j + 1 == int(t1[i].size())) ? '\n' : ' ');
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
using namespace std;
vector<int> t1[15];
int dep = 0;
void recur (int l, int r, int d) {
	if (l >= r) return;
	dep = max(dep, d);
	int m = (l + r) / 2;
	for (int i = l; i <= m; i++) t1[d].pb(i);
	recur(l, m, d + 1); recur(m + 1, r, d + 1);
	return;
}
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	scanf("%d", &a);
	recur(1, a, 1);
	printf("%d\n", dep);
	for (i = 1; i <= dep; i++) {
		printf("%d", int(t1[i].size()));
		for (j = 0; j < t1[i].size(); j++) {
			printf(" %d", t1[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
using namespace std;
vector<int> t1[15];
int dep = 0;
void recur (int l, int r, int d) {
	if (l == r) return;
	dep = max(dep, d);
	int m = (l + r) / 2;
	for (int i = l; i <= m; i++) t1[d].pb(i);
	recur(l, m, d + 1); recur(m + 1, r, d + 1);
	return;
}
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d", &a);
	recur(1, a, 1);
	printf("%d\n", dep);
	for (i = 1; i <= dep; i++) {
		printf("%d ", int(t1[i].size()));
		for (j = 0; j < t1[i].size(); j++) {
			printf("%d%c", t1[i][j], (j + 1 == int(t1[i].size())) ? '\n' : ' ');
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int n;
int merg[23];
vector <int> vec[22];

int main()
{
    in >> n;
    if (n == 2)
    {
        out << "1\n1 1";
        return 0;
    }
    int i = (1<<20);
    while (i >= 0)
    {
        int ok = 0;
        for (int j=1; j<=n; j++)
        {
            if (j&i)
            {
                ok++;
            }
        }
        if (ok >= 1) break;
        i /= 2;
    }
    int ok = i;
    int cnt = 0;
    for (int i=0; i<ok; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (j&(1<<i)) vec[i].push_back(j);
        }
        if (vec[i].size() != n) merg[i] = 1,cnt++;
    }
    out << cnt << "\n";
    for (int i=0; i<=ok; i++)
    {
        if (merg[i])
        {
           /// cout << vec[i].size() << " ";
            for (int j=0; j<vec[i].size(); j++) out << vec[i][j] << " ";
            out << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int n;
int merg[23],a[1005][1005];
vector <int> vec1[1000],vec2[1000];

bool Merge()
{
    int sum = 0;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            sum += a[i][j];
        }
    }
    return (sum == n*n - n);
}

int main()
{
    in >> n;
    if (n == 2)
    {
        out << "1\n1 1";
        return 0;
    }
    n--;
    int i = (1<<20);
    while (i >= 0)
    {
        int ok = 0;
        for (int j=1; j<=n; j++)
        {
            if (j&i)
            {
                ok++;
            }
        }
        if (ok >= 1) break;
        i /= 2;
    }
    n++;
    int ok = i;
    int cnt = 0;
    for (int i=0; i<=ok; i++)
    {
        for (int j=1; j<=n; j++)
        {
            //cout << i << " " << j << "\n";
            if (j&i)
            {
                vec1[i].push_back(j);
            }
            else vec2[i].push_back(j);
        }
    }
    for (int i=0; i<=ok; i++)
    {
        if (vec1[i].size() != n && vec1[i].size() > 0)
        {
            for (int j=0; j<vec1[i].size(); j++)
            {
                for (int p=0; p<vec2[i].size(); p++)
                {
                    a[vec1[i][j]][vec2[i][p]] = 1;
                    a[vec2[i][p]][vec1[i][j]] = 1;
                }
            }
            cnt++;
            if (Merge()) break;
        }
    }
    out << cnt << "\n";
    int p = 0;
    for (int i=0; i<=ok; i++)
    {
        if (vec1[i].size() != n && vec1[i].size() > 0)
        {
            out << vec1[i].size() << " ";
            for (int j=0; j<vec1[i].size(); j++) out << vec1[i][j] << " ";
            out << "\n";
            p++;
            if (p == cnt) break;
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int n;
int merg[23];
vector <int> vec[22];

int main()
{
    in >> n;
    if (n == 2)
    {
        out << "1\n1 1";
        return 0;
    }
    n--;
    int i = (1<<20);
    while (i >= 0)
    {
        int ok = 0;
        for (int j=1; j<=n; j++)
        {
            if (j&i)
            {
                ok++;
            }
        }
        if (ok >= 1) break;
        i /= 2;
    }
    n++;
    int ok = i;
    int cnt = 0;
    for (int i=0; i<ok; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (j&(1<<i))
            {
                vec[i].push_back(j);
                ///cout << j << " ";
            }
        }
        if (vec[i].size() != n) merg[i] = 1,cnt++;
    }
    for (int i=0; i<ok; i++) if (vec[i].size() == 0) cnt--;
    out << cnt << "\n";
    for (int i=0; i<ok; i++)
    {
        if (merg[i] && vec[i].size() > 0)
        {
            out << vec[i].size() << " ";
            for (int j=0; j<vec[i].size(); j++)
            {
                out << vec[i][j] << " ";
            }
            out << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int n;
int merg[23];
vector <int> vec[22];

int main()
{
    in >> n;
    if (n == 2)
    {
        out << "1\n1 1";
        return 0;
    }
    int i = (1<<20);
    while (i >= 0)
    {
        int ok = 0;
        for (int j=1; j<=n; j++)
        {
            if (j&i)
            {
                ok++;
            }
        }
        if (ok >= 1) break;
        i /= 2;
    }
    int ok = i;
    int cnt = 0;
    for (int i=0; i<ok; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (j&(1<<i))
            {
                vec[i].push_back(j);
                ///cout << j << " ";
            }
        }
        if (vec[i].size() != n) merg[i] = 1,cnt++;
    }
     out << cnt << "\n";
     for (int i=0; i<ok; i++)
     {
         if (merg[i])
         {
             out << vec[i].size() << " ";
             for (int j=0; j<vec[i].size(); j++)
             {
                 out << vec[i][j];
                 if (j < vec[i].size() - 1) out << " ";
             }
             if (i < ok-1) out << "\n";
         }
     }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int n;
int merg[23];
vector <int> vec[22];

int main()
{
    in >> n;
    if (n == 2)
    {
        out << "1\n1 1";
        return 0;
    }
    int i = (1<<20);
    while (i >= 0)
    {
        int ok = 0;
        for (int j=1; j<=n; j++)
        {
            if (j&i)
            {
                ok++;
            }
        }
        if (ok >= 1) break;
        i /= 2;
    }
    int ok = i;
    int cnt = 0;
    for (int i=0; i<ok; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (j&(1<<i)) vec[i].push_back(j);
        }
        if (vec[i].size() != n) merg[i] = 1,cnt++;
    }
    out << cnt << "\n";
    for (int i=0; i<ok; i++)
    {
        if (merg[i])
        {
           /// cout << vec[i].size() << " ";
            for (int j=0; j<vec[i].size(); j++)
            {
                out << vec[i][j];
                if (j < vec[i].size() - 1) out << " ";
            }
            if (i < ok-1) out << "\n";
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    cout << "toma e verde!";

    return 0;
}


#include <iostream>
#include <fstream>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int n;

int Da_mi(int n)
{
    int rasp = 0;
    while (n > 1)
    {
        n /= 2;
        rasp++;
    }
    return rasp;
}

int main()
{
    in >> n;
    if (n == 2)
    {
        out << "1\n1 1";
        return 0;
    }
    out << Da_mi(n) + 1;
    return 0;
}