#include<bits/stdc++.h>
#define For(i,j,k)  for(int i=j;i<=k;++i)
#define Dow(i,j,k)  for(int i=k;i>=j;--i)
#define ll long long
#define pb push_back
#define fir first
#define sec second
#define pb push_back
#define pa pair<int,int>
#define mk make_pair
 
using namespace std;
 
inline ll read()
{
    ll t=0,dp=1;char c=getchar();
    while(!isdigit(c))  {if(c=='-') dp=-1;c=getchar();}
    while(isdigit(c))   t=t*10+c-48,c=getchar();
    return t*dp;
}
inline void write(ll x){if(x<0)  {putchar('-');x=-x;}    if(x>=10)    write(x/10);putchar(x%10+48);}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
int main()
{
	ll N=read();
	ll f[233];
	ll x=0,y=0;
	f[0]=1;f[1]=2;
	int tot=1;
	For(i,2,100)
	{
		f[i]=f[i-1]+f[i-2];
		if(f[i]>N)	break;
		tot=i;
	}
	int top=0;
	int q[233];
	Dow(i,0,tot)
	{
		if(f[i]<=N)	q[++top]=i,N-=f[i];
	}
	reverse(q+1,q+top+1);
	int now=3;
	int tep=1;
	int ans[233],top_ans=0;
	For(i,1,tot+1)
	{
		ans[++top_ans]=now;
		if(now==3)	x=x+y;
		if(now==4)	y=x+y;
		if(q[tep]==i-1)
		{
			if(now==4)	ans[++top_ans]=1;
			else	ans[++top_ans]=2;
			++tep;
		}
		now=7-now;
	}	
	writeln(top_ans);
	x=y=0;
	Dow(i,1,top_ans)
	{
		writeln(ans[i]);
		if(ans[i]==1)	x++;
		if(ans[i]==2)	y++;
		if(ans[i]==3)	x=x+y;
		if(ans[i]==4)	y=x+y;
	}
	// cout<<tot<<' '<<f[tot]<<endl;
	// cout<<x<<"=="<<y<<endl;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
	-- Benq
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> t(n);
    vector<ll> l(n);
    vector<ll> r(n);
    rep(i,n) cin >> t[i] >> l[i] >> r[i];

    vector<pair<double, double>> h(n);
    rep(i,n) {
        if(t[i]==1 || t[i]==2) {
            h[i].first = l[i];
        } else {
            h[i].first = l[i] + 0.1;
        } 
        if(t[i]==1 || t[i]==3) {
            h[i].second = r[i];
        } else {
            h[i].second = r[i] - 0.1;
        }
    }
    //debug(h[0].first); 
    //debug(h[0].second);
    int ans=0;

    rep(i,n-1) {
        for(int j=i+1; j<n; j++) {
            if(h[i].first <= h[j].first && h[j].first <= h[i].second) {
                ans++; //debug(i); debug(j);
            }
            else if(h[i].first <= h[j].second && h[j].second <= h[i].second) {
                ans++; //debug(i); debug(j);
            }
            else if(h[j].first <= h[i].first && h[i].first <= h[j].second) {
                ans++; //debug(i); debug(j);
            }
            else if(h[j].first <= h[i].second && h[i].second <= h[j].second) {
                ans++; //debug(i); debug(j);
            }
        }
    }

    cout << ans << endl;
}