#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <set>
#include<regex>
#include <stdio.h>
using namespace std;
struct guest
{
	int t;
	int g;
	int gender;
	guest(int a, int g0,int gen)
	{
		t = a;
		g = g0;
		gender = gen;
	}
	int act() const { return t; }
	int go() const { return g; }
	guest() {};
};
bool operator<(guest const & L, guest const & R) { // The operator takes const references - it can compare const objects
	return (L.act() < R.act()||(L.act()==R.act()&&L.go()<R.go()));
}
int main() {
	//ifstream in("input.txt");
	//ofstream out("output.txt");
	int n;
	char gender;
	int come, go;
	vector<guest > events;
	cin >> n;
	cin >> ws;
	events.resize(2 * n);
	for (int i = 0; i < 2*n; i+=2)
	{
		cin >> gender >> come >> go;
		cin >> ws;
		//scanf("%c%d%d", &gender, &come, &go);
		if (gender == 'M')
		{
			events[i] = guest(come, 0, 1);
			events[i + 1] = guest(go, 1, 1);
		}
		else
		{
			events[i] = guest(come, 0, 2);
			events[i + 1] = guest(go, 1, 2);
		}
	}
	sort(events.begin(), events.end());
	int ans = 0;
	int m, f;
	m = 0;
	f = 0;
	for (int i = 0; i < 2 * n; ++i)
	{
		if (events[i].g == 0)
		{
			if (events[i].gender == 1)
				m++;
			else
				f++;
		}
		else
		{
			if (events[i].gender == 1)
				m--;
			else
				f--;
		}
		ans = max(ans, 2 * min(m, f));
	}
	cout << ans << endl;
	//system("pause");
	//in.close();
	//out.close();
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int cntF[367], cntM[367], n, i, j, l, r, ans = 0;
	char c;
	for (i = 0; i <= 366; ++ i) {
		cntF[i] = 0;
		cntM[i] = 0;
	}
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> c >> l >> r;
		for (j = l; j <= r; ++j) {
			if (c == 'M') {
				++cntM[j];
			}
			else {
				++cntF[j];
			}
		}
	}
	for (i = 1; i <= 366; ++i) {
		ans = max(ans, min(cntF[i], cntM[i]));
	}
	cout << ans * 2;
	return 0;
}


#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,j,a,b;
    char ch;
    int M[367]={},F[367]={};
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin >>ch;
        cin>>a>>b;
        if(ch=='M')
        {
            for(j=a;j<=b;j++)
                M[j]++;
        }
        if(ch=='F')
        {
            for(j=a;j<=b;j++)
                F[j]++;
        }
    }
    int res=0,m;
    for(i=1;i<=366;i++)
    {
        m=min(F[i],M[i]);
        if(m>res)
            res=m;
    }
    cout<<res*2<<endl;
    return 0;
}


#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,j,a,b;
    char ch;
    int M[367]={},F[367]={};
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin >>ch;
        cin>>a>>b;
        if(ch=='M')
        {
            for(j=a;j<=b;j++)
                M[j]++;
        }
        if(ch=='F')
        {
            for(j=a;j<=b;j++)
                F[j]++;
        }
    }
    int res=0,m;
    for(i=1;i<=365;i++)
    {
        m=min(F[i],M[i]);
        if(m>res)
            res=m;
    }
    cout<<res*2<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[380][2];
int main()
{
    int n,b,c;char ch[2];
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    for (int i=0;i<n;i++)
    {
        scanf("%s%d%d",ch,&b,&c);
        if (ch[0]=='M')
        {
            for (int j=b;j<=c;j++)
                a[j][0]++;
        }
        else
        {
            for (int j=b;j<=c;j++)
                a[j][1]++;
        }
    }
    int ans=0;
    for (int i=1;i<=366;i++)
        ans=max(ans,min(a[i][0],a[i][1]));
    printf("%d\n",ans*2);
    return 0;
}


#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int n,ar[366][3];
	clr(ar, 0);
	cin >> n;
	char*v1 = new char[n];
	int**v2 = new int*[n];
	lpn(i, n){ v2[i] = new int[2]; }
	lpn(i, n){ cin >> v1[i]; lpn(j, 2){ cin >> v2[i][j]; } }
	lpn(i, n){ lpn(j, 366){ if (j >= v2[i][0] && j <= v2[i][1])ar[j][0]++; if (v1[i] == 'M')ar[j][1]++; else ar[j][2]++; } }
	int max = 0;
	lpn(i, 366){ if (ar[i][0] > max&&abs(ar[i][1] - ar[i][2])<=1)max = ar[i][0]; }
	if (max%2==0)
	cout << max << endl;
	else cout << max-1 << endl;
	return 0;
}


#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int n,m[366],f[366];
	clr(m, 0);
	clr(f, 0);
	cin >> n;
	char*v1 = new char[n];
	int**v2 = new int*[n];
	lpn(i, n){ v2[i] = new int[2]; }
	lpn(i, n){ cin >> v1[i]; lpn(j, 2){ cin >> v2[i][j]; } }
	lpn(i, n){ lpn(j, 366){ if (j >= v2[i][0] && j <= v2[i][1]) if (v1[i] == 'M')m[j]++; else f[j]++; } }
	int mx = 0;
	lpn(i, 366){ mx = max(mx,min(m[i], f[i]) * 2); }
	cout << mx << endl;
	return 0;
}


#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int n,m[367],f[367];
	clr(m, 0);
	clr(f, 0);
	cin >> n;
	char*v1 = new char[n];
	int**v2 = new int*[n];
	lpn(i, n){ v2[i] = new int[2]; }
	lpn(i, n){ cin >> v1[i]; lpn(j, 2){ cin >> v2[i][j]; } }
	lpn(i, n){ lpn(j, 367){ if (j >= v2[i][0] && j <= v2[i][1]) if (v1[i] == 'M')m[j]++; else f[j]++; } }
	int mx = 0;
	lpn(i, 367){ mx = max(mx,min(m[i], f[i]) * 2); }
	cout << mx << endl;
	return 0;
}


#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int n,ar[366][3];
	clr(ar, 0);
	cin >> n;
	char*v1 = new char[n];
	int**v2 = new int*[n];
	lpn(i, n){ v2[i] = new int[2]; }
	lpn(i, n){ cin >> v1[i]; lpn(j, 2){ cin >> v2[i][j]; } }
	lpn(i, n){ lpn(j, 366){ if (j >= v2[i][0] && j <= v2[i][1])ar[j][0]++; if (v1[i] == 'M')ar[j][1]++; else ar[j][2]++; } }
	int max = 0;
	lpn(i, 366){ if (ar[i][0] > max&&ar[i][1]==ar[i][2])max = ar[i][0]; }
	cout << max << endl;
	return 0;
}


#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int n,ar[366][2];
	clr(ar, 0);
	cin >> n;
	char*v1 = new char[n];
	int**v2 = new int*[n];
	lpn(i, n){ v2[i] = new int[2]; }
	lpn(i, n){ cin >> v1[i]; lpn(j, 2){ cin >> v2[i][j]; } }
	lpn(i, n){ lpn(j, 366){ if (j >= v2[i][0] && j <= v2[i][1]) if (v1[i] == 'M')ar[j][1]++; else ar[j][2]++; } }
	int max = 0;
	lpn(i, 366){ if (min(ar[i][1], ar[i][2]) * 2 > max)max = min(ar[i][1], ar[i][2]) * 2; }
	cout << max << endl;
	return 0;
}


#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int n,m[366],f[366];
	clr(m, 0);
	clr(f, 0);
	cin >> n;
	char*v1 = new char[n];
	int**v2 = new int*[n];
	lpn(i, n){ v2[i] = new int[2]; }
	lpn(i, n){ cin >> v1[i]; lpn(j, 2){ cin >> v2[i][j]; } }
	lpn(i, n){ lpn(j, 366){ if (j >= v2[i][0] && j <= v2[i][1]) if (v1[i] == 'M')m[j]++; else f[j]++; } }
	int max = 0;
	lpn(i, 366){ if (min(m[i], f[i]) * 2 > max)max = min(m[i], f[i]) * 2; }
	cout << max << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int MAX = 5009, D = 367;
int n, a[MAX][2], ans, l, r;
string s;
int main()
{
	cin >> n;
	for (int i = 0; i<n; i++)//判断在这个区间内
	{
		cin >> s >> l >> r;
		for (int j = l; j <= r; j++)
			if (s == "F") a[j][0]++;//如果是男性，那一天+1
			else a[j][1]++;//如果是女性那一天+1
	}
	for (int i = 1; i<D; i++)
		ans = max(ans, min(a[i][0], a[i][1]));//求同一天去的男性和女性的最大值
	cout << (ans << 1);
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int N = 5050, D = 367;
int a[N][2], n, l, r, ans;
char s;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s >> l >> r;
		for (int i = l; i < r; i++)
			if (s == 'F')
				a[i][0]++;
			else
				a[i][1]++;
	}
	for (int i = 1; i < D; i++)
	{
		ans = max(ans, min(a[i][0], a[i][1]));
	}
	cout<< (ans << 1);
}


//#include "stdafx.h"
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, a, b, sum = 0, max = 0;
	char input;
	cin >> n;

	int m[500] = { 0 };
	int f[500] = { 0 };

	for (int i = 0; i < n; i++)
	{
		cin >> input >> a >> b;

		for (int k = a; k <= b; k++)
			if (input == 'M')
				m[k]++;
			else if (input == 'F')
				f[k]++;
	}

	for (int i = 1; i <= 366; i++)
	{
		sum = min(m[i], f[i]);
		if (sum > max)
			max = sum;
	}

	cout << max * 2;

	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, a, b, sum, max = 0;
	char input;
	cin >> n;

	int m[366] = { 0 };
	int f[366] = { 0 };

	for (int i = 0; i < n; i++)
	{
		cin >> input >> a >> b;

		for (int k = a; k <= b; k++)
			if (input == 'M')
				m[k]++;
			else if (input == 'F')
				f[k]++;
	}

	for (int i = 1; i < 366; i++)
	{
		sum = min(m[i], f[i]);
		if (sum > max)
			max = sum;
	}

	cout << max * 2;

	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, a, b, sum = 0, max = 0;
	char input;
	cin >> n;

	int m[500] = { 0 };
	int f[500] = { 0 };

	for (int i = 0; i < n; i++)
	{
		cin >> input >> a >> b;

		for (int k = a; k <= b; k++)
			if (input == 'M')
				m[k]++;
			else if (input == 'F')
				f[k]++;
	}

	for (int i = 1; i < 366; i++)
	{
		sum = min(m[i], f[i]);
		if (sum > max)
			max = sum;
	}

	cout << max * 2;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include<algorithm>
#include <string>
using namespace std;
int mal[400], fem[400];
int main()
{
	int n, b, a,x=0,ans=0, mi=1000;
	cin>>n;
	char s;
	for (int i=0; i<n; ++i)
	{
	    cin>>s>>a>>b;
	    if (s=='M')
	    {   for (int j=a; j<=b; j++)
	        mal[j]++;
	    }
	    else
        {
            for (int j=a; j<=b; j++)
	        fem[j]++;
	    }
	 }
	    int maxa=0, msc=0, fsc=0, day;
    for (int j=1; j<367; j++)
	   {

        day=2*min(fem[j],mal[j]);
	    if (day>=maxa)
	    maxa=day;
	    fsc=msc=0;
	   }

	   cout<<maxa;
	return 0;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include<algorithm>
#include <string>
using namespace std;
int mal[400][2], fem[400][2], para[400][2];
int main()
{
	int n, b, a,x=0,ans=0, mi=1000;
	cin>>n;
	char s;
	for (int i=0; i<n; ++i)
	{
	    cin>>s>>a>>b;
	    if (s=='M')
	    {
	        mal[i][1]=a;
	        mal[i][2]=b;
	    }
	    else
	    {
	        fem[i][1]=a;
	        fem[i][2]=b;
	    }
	 }
	    int maxa=0, msc=0, fsc=0, day;
    for (int j=1; j<367; j++)
	   {
	    for (int i=0; i<n; ++i)
	    {
	        if (mal[i][1]<=j && mal[i][2]>=j)
	        msc++;
	        if (fem[i][1]<=j && fem[i][2]>=j)
	        fsc++;
	    }
            day=2*min(fsc,msc);
	    if (day>=maxa)
	    maxa=day;
	    fsc=msc=0;
	   }

	   cout<<maxa;
	return 0;

}


#include<iostream>
#include<math.h>
#include<map>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main ()
{
	int n;
	cin>>n;
	int s[5001];
	vector < pair<int,int> > v (n);
	for (int i = 0;i<n;i++)
	{
		char c;
		cin>>c;
		cin>>v[i].first>>v[i].second;
		if (c=='F') s[i] = 1;
		else s[i] = 0;
	}
	int best = INT_MIN;
	for (int i = 1;i<=366;i++)
	{
		int m = 0;
		int f = 0;
		for (int j = 0;j<n;j++)
		{
			if (i>=v[j].first && i<=v[j].second && s[j]==0) m++;
			if (i>=v[j].first && i<=v[j].second && s[j]==1) f++;
		}
		if (2*min(m,f) > best) best = 2*min(m,f);
	}
	cout<<best;
	//system("pause");
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main ()
{
	int n;
	cin>>n;
	int s[5001];
	vector < pair<int,int> > v (n);
	for (int i = 0;i<n;i++)
	{
		char c;
		cin>>c;
		cin>>v[i].first>>v[i].second;
		if (c=='F') s[i] = 1;
		else s[i] = 0;
	}
	int best = INT_MIN;
	for (int i = 1;i<=366;i++)
	{
		int m = 0;
		int f = 0;
		for (int j = 0;j<n;j++)
		{
			if (i>=v[j].first && i<=v[j].second && s[j]==0) m++;
			if (i>=v[j].first && i<=v[j].second && s[j]==1) f++;
		}
		if (min(m,f) > best) best = 2*min(m,f);
	}
	cout<<best;
	//system("pause");
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main ()
{
	int n;
	cin>>n;
	int s[5001];
	vector < pair<int,int> > v (n);
	for (int i = 0;i<n;i++)
	{
		char c;
		cin>>c;
		cin>>v[i].first>>v[i].second;
		if (c=='F') s[i] = 1;
		else s[i] = 0;
	}
	int best = INT_MIN;
	for (int i = 1;i<=366;i++)
	{
		int m = 0;
		int f = 0;
		for (int j = 0;j<n;j++)
		{
			if (i>=v[j].first && i<=v[j].second && s[j]==0) m++;
			if (i>=v[j].first && i<=v[j].second && s[j]==1) f++;
		}
		if (m == f && m+f > best) best = m+f;
	}
	cout<<best;
	//system("pause");
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main ()
{
	int n;
	cin>>n;
	int s[5001];
	vector < pair<int,int> > v (n);
	for (int i = 0;i<n;i++)
	{
		char c;
		cin>>c;
		cin>>v[i].first>>v[i].second;
		if (c=='F') s[i] = 1;
		else s[i] = 0;
	}
	int best = INT_MIN;
	for (int i = 1;i<=366;i++)
	{
		int m = 0;
		int f = 0;
		for (int j = 0;j<n;j++)
		{
			if (i>=v[j].first && i<=v[j].second && s[j]==0) m++;
			if (i>=v[j].first && i<=v[j].second && s[j]==1) f++;
		}
		if (min(m,f) > best) best = min(m,f);
	}
	cout<<best;
	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

struct duLieu {
	int a, b, gioitinh;
};
duLieu temp[5000];
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		char x;
		cin >> x >> temp[i].a >> temp[i].b;
		temp[i].gioitinh = (x == 'M') ? 1 : 0;
	}

	int kq = 0;
	for (int i = 1; i <= 366; i++) {
		int m = 0, fm = 0;
		for (int j = 0; j < n; j++) {
			if (temp[j].a <= i && i <= temp[j].b) {
				if (temp[j].gioitinh == 0)
					fm++;
				else
					m++;
			}
		}
		kq = max(kq, 2 * min(m, fm));
	}

	cout << kq << endl;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n = 0, m = 367, a = 0, b = 0, c = 0;
    char z = ' ';
    vector<string> buf(m, "");
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> z >> a >> b;
        for (int j = a; j <= b; j++) {
            buf[j] += z;
        }
    }
    for (int i = 1; i < m; i++) {
        n = buf[i].size();
        a = 0;
        b = 0;
        for (int j = 0; j < n; j++) {
            if (buf[i][j] == 'M') {
                a++;
            }
            else {
                b++;
            }
        }
        n = min(a, b);
        if (c < n) {
            c = n;
        }
    }
    cout << 2 * c;
}


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

using namespace std;

int main()
{
    int n = 0, m = 367, a = 0, b = 0;
    char z = ' ';
    string s = "";
    vector<pair<int, string>> vect;
    for (int i = 0; i < m; i++)
	{
		vect.push_back(make_pair(0, ""));
	}
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> z >> a >> b;
        for (int j = a; j <= b; j++) {
            vect[j].first++;
            vect[j].second += z;
        }
    }
    sort(vect.begin(), vect.end());
    for (int i = m - 1; i > 0; i--) {
        n = vect[i].second.find("FM");
        if (n > -1) {
            cout << vect[i].first;
            return 0;
        }
        n = vect[i].second.find("MF");
        if (n > -1) {
            cout << vect[i].first;
            return 0;
        }
    }
}


n = int(input())

m = [0 for _ in range(366 + 1)]
f = [0 for _ in range(366 + 1)]

for i in range(n):
    g, a, b = input().split()
    a, b = int(a), int(b)
    if g == 'M':
        for j in range(a, b + 1):
            m[j] += 1
    else:
        for j in range(a, b + 1):
            f[j] += 1

answ = 0
for i in range(1, 366 + 1):
    answ = max(answ, min(m[i], f[i]) * 2)

print(answ)


n = int(input())
m = [0]*367; f = [0]*367

for _ in range(n):
    g,a,b = input().split()
    arr = m if g=='M' else f
    a = int(a); b=int(b)
    for i in range(a,b+1):
        arr[i]+=1

r = 2*max([min(m[i],f[i]) for i in range(367)])
print(r)


n=int(input())
ans=0
m=[]
f=[]
for i in range(367):
    m.append(0)
    f.append(0)
for i in range(n):
    data=input().split()
    if data[0]=='M':
        for j in range(int(data[1]),int(data[2])+1):
            m[j]+=1
    else:
        for j in range(int(data[1]),int(data[2])+1):
            f[j]+=1
for i in range(1,367):
    if m[i]==f[i]:
        if m[i]>ans:
            ans=m[i]
    elif m[i]>f[i]:
        if f[i]>ans:
            ans=f[i]
    else:
        if m[i]>ans:
            ans=m[i]
print(ans*2)


n=int(input())
ab=[list(input().split()) for i in range(n)]
man,woman=0,0
day=[]
for i in range(1,367):
    for x in range(len(ab)):
        if int(ab[x][1])<=i<=int(ab[x][2]):
            if ab[x][0]=='M':
                man+=1
            else:
                woman+=1
    day.append(2*min(man,woman))
    man=0
    woman=0
print(max(day))


n = int(input())
day = [[0, 0] for i in range(368)]

for i in range(n):
	a, b, c = (input().split())

	if(a == "M"):
		day[int(b)][0] += 1
		day[int(c)+1][0] -= 1
	else:
		day[int(b)][1] += 1
		day[int(c)+1][1] -= 1

w = 0
m = 0
ans = 0

for i in day:
	w += i[0]
	m += i[1]
	ans = max(2 * min(m, w), ans)

print(ans)


__author__ = 'aste'

DAYS = 366

def main():
    n = int(input())
    g_f = [0] * DAYS
    g_m = [0] * DAYS
    for i in range(0, n):
        g, a, b = input().split()
        a = int(a)
        b = int(b)
        for j in range(1, DAYS + 1):
            if a <= j <= b:
                if g == 'F':
                    g_f[j - 1] += 1
                else:
                    g_m[j - 1] += 1
    res = 0
    for i in range(0, DAYS):
        res = max(res, 2*min(g_f[i], g_m[i]))
    print(res)

main()


#!/usr/bin/python3

import operator as op

class StdReader:
	def read_int(self):
		return int(self.read_string())

	def read_ints(self, sep=None):
		return [int(i) for i in self.read_strings(sep)]

	def read_float(self):
		return float(self.read_string())

	def read_floats(self, sep=None):
		return [float(i) for i in self.read_strings(sep)]

	def read_string(self):
		return input()

	def read_strings(self, sep=None):
		return self.read_string().split(sep)

reader = StdReader()

def main():
	n = reader.read_int()

	# friends = []
	ends = []
	for i in range(n):
		line = reader.read_strings()
		gen, f, t = line[0], int(line[1]), int(line[2])

		# friends.append((f, t, gen))
		ends.append((f, gen, 'f'))
		ends.append((t, gen, 't'))

	ends.sort(key=op.itemgetter(0, 2))

	females = 0
	males = 0
	max_sim = 0
	# print('f', 'm')
	for end in ends:
		x, gen, t = end

		if t == 'f':
			females += gen=='F'
			males += gen=='M'
		else:
			females -= gen=='F'
			males -= gen=='M'

		# print(females, males)

		ppl = min(females, males)
		max_sim = max(max_sim, ppl)

	print(max_sim * 2)

if __name__ == '__main__':
	main()


#!/usr/bin/python3

import operator as op

class StdReader:
	def read_int(self):
		return int(self.read_string())

	def read_ints(self, sep=None):
		return [int(i) for i in self.read_strings(sep)]

	def read_float(self):
		return float(self.read_string())

	def read_floats(self, sep=None):
		return [float(i) for i in self.read_strings(sep)]

	def read_string(self):
		return input()

	def read_strings(self, sep=None):
		return self.read_string().split(sep)

reader = StdReader()

def main():
	n = reader.read_int()

	# friends = []
	ends = []
	for i in range(n):
		line = reader.read_strings()
		gen, f, t = line[0], int(line[1]), int(line[2])

		# friends.append((f, t, gen))
		ends.append((f, gen, 'f'))
		ends.append((t, gen, 't'))

	ends.sort(key=op.itemgetter(0, 2))

	females = 0
	males = 0
	max_sim = 0
	# print('f', 'm')
	for end in ends:
		x, gen, t = end

		if t == 'f':
			females += gen=='F'
			males += gen=='M'
		else:
			females -= gen=='F'
			males -= gen=='M'

		# print(females, males)

		if females == males:
			max_sim = max(max_sim, females)

	print(max_sim * 2)

if __name__ == '__main__':
	main()


n = int(input())
boy = [0] * 1000
girl = [0] * 1000
for i in range(n):
    lst = list(input().split())
    lst[1] = int(lst[1])
    lst[2] = int(lst[2])
    for j in range(lst[1], lst[2] + 1):
        if lst[0] == 'M':
            boy[j] += 1
        else:
            girl[j] += 1
ans = -1
for i in range(1000):
    k = 2 * min(boy[i], girl[i])
    ans = max(ans, k)

print(ans)


n = int(input())
boy = [0] * 1000
girl = [0] * 1000
for i in range(n):
    lst = list(input().split())
    lst[1] = int(lst[1])
    lst[2] = int(lst[2])
    for j in range(lst[1], lst[2] + 1):
        if lst[0] == 'M':
            boy[j] += 1
        else:
            girl[j] += 1
ans = -1
for i in range(1000):
    if boy[i] == girl[i]:
        ans = max(boy[i] + girl[i], ans)

print(ans)


n = int(input())
male,female = [0]*370,[0]*370
for _ in range(n):
    g,l,r = input().split()

    if g =='M':
        for i in range(int(l),int(r)+1):
            male[i]+=1

    else:
        for i in range(int(l),int(r)+1):
            female[i]+=1

ans = 0
for i in range(1,367):

    tans = 2*min(male[i],female[i])
    if tans>ans:
        ans = tans

print(ans)


v = [[0] * 367 for i in range(2)]
for i in range(int(input())):
    c = input().split()
    s = int(c[0] == 'M')
    for j in range(int(c[1]), int(c[2]) + 1):
        v[s][j] += 1
print(2 * max(min(x, y) for x, y in zip(v[0], v[1])))


# Description of the problem can be found at http://codeforces.com/problemset/problem/629/B

n = int(input())

a_g = list([0] * 367 for _ in range(2))
a_b = [0] * 367

for _ in range(n):
    g, s, e = input().split()
    for i in range(int(s), int(e) + 1):
        a_g[1 if g == "F" else 0][i] += 1

m = 0
for i in range(1, 367):
    m = max(m, 2 * min(a_g[0][i], a_g[1][i]))

print(m)


n = int(input())

friends = list()
minDay = 366
maxDay = 0
for i in range(n):
	f = input()
	arr = f.split(" ")
	friends.append(arr)
	if minDay > int(arr[1]):
		minDay = int(arr[1])
	if maxDay < int(arr[2]):
		maxDay = int(arr[2])

days = list()
for day in range(minDay, maxDay+1):
	d = list()
	for f in friends:
		if int(f[1]) <= day and int(f[2]) >= day:
			d.append(f[0])
	m = [f for f in d if f == 'M']
	f = [f for f in d if f == 'F']
	maxPeople = len(m) if len(m)<len(f) else len(f)
	days.append(maxPeople)

print(max(days)*2)


readInts=lambda: list(map(int, input().split()))

n = int(input())
num = [[0,0] for i in range(370)]
for i in range(n):
    s,u,v = (input().split())
    u=int(u)
    v=int(v)
    c=int(s=='F')
    num[u][c]+=1
    num[v+1][c]-=1
x=0;y=0
ret=0
for i in range(367):
    x+=num[i][0]
    y+=num[i][1]
    ret=max(ret,min(x,y))
ret*=2
print(ret)


n=int(input())
l=[list(input().split()) for _ in range(n)]
ans=0
for i in range(1,367):
    b,g=0,0
    for x in l:
        if int(x[1])<=i<=int(x[2]):
            if x[0]=='F': g+=1
            else: b+=1
    if b<g: b,g=g,b
    t=2*g
    if t>ans: ans=t
print(ans)


n = int(input())
friends = [list(map(str,input().split())) for i in range(n)]
days = [[0]*366 for i in range(2)]
for i in range(n):
    if friends[i][0] == "M":
        for j in range(int(friends[i][1])-1,int(friends[i][2])):
            days[0][j] += 1
    else:
        for j in range(int(friends[i][1])-1,int(friends[i][2])):
            days[1][j] += 1
num = 0
for i in range(366):
    if min(days[0][i],days[1][i]) > num:
        num = min(days[0][i],days[1][i])
print(num*2)


n = int(input())

lst = [[0 for x in range(2)] for y in range(366)]

for i in range(n):
    temp = input().split()
    for i in range(int(temp[1])-1, int(temp[2])):
        lst[i][0] += 1
        if(temp[0]=='M'):
            lst[i][1] += 1
        else:
            lst[i][1] -= 1

for i in range(366):
    lst[i][0] = lst[i][0] - abs(lst[i][1])

ans = max(lst)
print (ans[0])


n = int(input())

lst = [[0 for x in range(2)] for y in range(366)]

for i in range(n):
    temp = input().split()
    for i in range(int(temp[1])-1, int(temp[2])):
        lst[i][0] += 1
        if(temp[0]=='M'):
            lst[i][1] += 1
        else:
            lst[i][1] -= 1

for i in range(n):
    lst[i][0] = lst[i][0] - abs(lst[i][1])

ans = max(lst)
print (ans[0])


n =  int(input())
male = [0] * 366
female = [0] * 366
res = 0
for i in range(n):
    g, start, end = map(str, input().split())
    if g == "M":
        for i in range(int(start), int(end) + 1):
            male[i] += 1
    else:
        for i in range(int(start), int(end) + 1):
            female[i] += 1

for m, f in zip(male, female):
    if min(m, f) * 2 > res:
        res = min(m, f) * 2

print(res)


n =  int(input())
male = [0] * 366
female = [0] * 366
res = 0
for i in range(n):
    g, start, end = map(str, input().split())
    if g == "M":
        for i in range(int(start) - 1, int(end)):
            male[i] += 1
    else:
        for i in range(int(start) - 1, int(end)):
            female[i] += 1

for m, f in zip(male, female):
    if min(m, f) * 2 > res:
        res = min(m, f) * 2
print(res)


n =  int(input())
male = [0] * 366
female = [0] * 366
res = 0
for i in range(n):
    g, start, end = map(str, input().split())
    if g == "M":
        for i in range(int(start) - 1, int(end) - 1):
            male[i] += 1
    else:
        for i in range(int(start) - 1, int(end) - 1):
            female[i] += 1

for m, f in zip(male, female):
    if min(m, f) * 2 > res:
        res = min(m, f) * 2

print(res)


n=int(input())
a,b=[[0,0] for i in range(366)],0
for i in range(n):
    x,y,z=map(str,input().split())
    y,z=int(y),int(z)
    if x=='M':
        for i in range(y-1,z):a[i][0]+=1
    else:
        for i in range(y-1,z):a[i][1]+=1
for i in range(366):
    if min(a[i])>b:b=min(a[i])
print(b*2)


n = int(input())

males = [0] * 366
females = [0] * 366

for _ in range(n):
    sex, ai, bi = input().split()
    ai, bi = int(ai), int(bi)
    for i in range(ai, bi + 1):
        if sex == 'M':
            males[i] += 1
        else:
            females[i] += 1

ans = 0
for i, j in zip(males, females):
    ans = max(min(i, j), ans)

print(ans * 2)


n = int(input())

males = [0] * 400
females = [0] * 400

for _ in range(n):
    sex, ai, bi = input().split()
    ai, bi = int(ai), int(bi)
    if sex == 'M':
        for i in range(ai, bi + 1):
            males[i] += 1
    else:
        for i in range(ai, bi + 1):
            females[i] += 1

ans = 0
for i, j in zip(males, females):
    ans = max(min(i, j), ans)

print(ans * 2)


n = int(input())

males_acc = [0] * 367
females_acc = [0] * 367

for _ in range(n):
    sex, ai, bi = input().split()
    ai, bi = int(ai), int(bi)
    if sex == 'M':
        males_acc[ai] += 1
        males_acc[bi+1] -= 1
    else:
        females_acc[ai] += 1
        females_acc[bi+1] -= 1

males = [males_acc[0]]
for i in range(1, 367):
    males.append(males[-1] + males_acc[i])

females = [females_acc[0]]
for i in range(1, 367):
    females.append(females[-1] + females_acc[i])

ans = 0
for m, f in zip(males, females):
    ans = max(min(m, f), ans)

print(ans * 2)


n = int(input())

males_acc = [0] * 400
females_acc = [0] * 400

for _ in range(n):
    sex, ai, bi = input().split()
    ai, bi = int(ai), int(bi)
    if sex == 'M':
        males_acc[ai] += 1
        males_acc[bi+1] -= 1
    else:
        females_acc[ai] += 1
        females_acc[bi+1] -= 1

males = [males_acc[0]]
for e in males_acc[1:]:
    males.append(males[-1] + e)

females = [females_acc[0]]
for e in females_acc[1:]:
    females.append(females[-1] + e)

ans = 0
for m, f in zip(males, females):
    ans = max(min(m, f), ans)

print(ans * 2)


n = int(input())

males_acc = [0] * 367
females_acc = [0] * 367

for _ in range(n):
    sex, ai, bi = input().split()
    ai, bi = int(ai), int(bi)
    if sex == 'M':
        males_acc[ai] += 1
        males_acc[bi+1] -= 1
    else:
        females_acc[ai] += 1
        females_acc[bi+1] -= 1

males = [males_acc[0]]
for e in males_acc[1:]:
    males.append(males[-1] + e)

females = [females_acc[0]]
for e in females_acc[1:]:
    females.append(females[-1] + e)

ans = 0
for m, f in zip(males, females):
    ans = max(min(m, f), ans)

print(ans * 2)


n = int(input())

males = [0] * 366
females = [0] * 366

for _ in range(n):
    sex, ai, bi = input().split()
    ai, bi = int(ai), int(bi)
    for i in range(ai, bi+1):
        if sex == 'M':
            males[i] += 1
        else:
            females[i] += 1

ans = 0
for i, j  in zip(males, females):
    ans = max(min(i, j), ans)

print(ans)


n=int(input())
m=[0]*366
f=[0]*366
for i in range(n):
    g,a,b=input().split()
    a,b=int(a),int(b)
    if g=='F':
        for i in range(a-1,b):
            f[i]+=1
    elif g=='M':
        for i in range(a-1,b):
            m[i]+=1
t=0
for i in range(366):
    temp=min(f[i],m[i])
    t = max(temp,t)

print(t*2)


if __name__=='__main__':
    n = int(input())
    fe = []
    m2 = []
    m1 = []
    cnt = 0
    for _ in range(n):
        gen,a,b=map(str,input().split())
        a,b = int(a),int(b)
        if gen=='M':
            cnt+= 1
            m1.append(a)
            m2.append(b)
        else:
            fe.append([a,b])
    fe = sorted(fe)
    m1= sorted(m1)
    m2 = sorted(m2)
    res = 0
    check1 = 0
    check2 = 0
    fcnt = 0
    for fem in fe:
        a,b = fem[0],fem[1]
        for i in range(0,cnt):
            if a>=m1[i]:
                continue
            else:
                check1 =  max(check1,(cnt)-i)
                check1 = min((len(fe)-fcnt)+1,check1)

        for i in range(0,cnt):
            if b>=m2[i]:
                continue
            else:
                check2 = max(check2,(cnt)-i)
                check2 = min((len(fe)-fcnt)+1,check2)
        fcnt += 1
    res = min(check1,check2)

    print(res*2)


if __name__=='__main__':
    n = int(input())
    fe = []
    ma = []
    for _ in range(n):
        gen,a,b=map(str,input().split())
        a,b = int(a),int(b)
        if gen=='M':
            ma.append([a,b])
        else:
            fe.append([a,b])
    ma = sorted(ma)
    fe = sorted(fe)
    maxcnt1 = 0
    for m in range(0,len(ma)):
        a = ma[m][0]
        #print("a-> ",a)
        cnt = 0
        for f in range(0,len(fe)):
            #print("f ",fe[f])
            if(fe[f][0]<=a and fe[f][1]>=a):
                cnt += 1

        maxcnt1 = max(cnt,maxcnt1)
    maxcnt2 = 0
    for m in range(0,len(fe)):
        a = fe[m][0]
        cnt = 0
        for f in range(0,len(ma)):
            if(ma[f][0]<=a and ma[f][1]>=a):
                cnt += 1

        maxcnt2 = max(cnt,maxcnt2)

    allmaxcnt1 = max(maxcnt2,maxcnt1)

    maxcnt11 = 0
    for m in range(0,len(ma)):
        a = ma[m][1]
        #print("a-> ",a)
        cnt = 0
        for f in range(0,len(fe)):
            #print("f ",fe[f])
            if(fe[f][0]<=a and fe[f][1]>=a):
                cnt += 1

        maxcnt11 = max(cnt,maxcnt11)
    maxcnt22 = 0
    for m in range(0,len(fe)):
        a = fe[m][1]
        cnt = 0
        for f in range(0,len(ma)):
            if(ma[f][0]<=a and ma[f][1]>=a):
                cnt += 1

        maxcnt22 = max(cnt,maxcnt22)
    allmaxcnt2 = max(maxcnt22,maxcnt11)
    print(min(allmaxcnt1,allmaxcnt2)*2)


if __name__=='__main__':
    n = int(input())
    fe = []
    m2 = []
    m1 = []
    cnt = 0
    for _ in range(n):
        gen,a,b=map(str,input().split())
        a,b = int(a),int(b)
        if gen=='M':
            cnt+= 1
            m1.append(a)
            m2.append(b)
        else:
            fe.append([a,b])
    fe = sorted(fe)
    m1= sorted(m1)
    m2 = sorted(m2)
    res = 0
    check1 = 0
    check2 = 0
    fcnt = 0
    for fem in fe:
        a,b = fem[0],fem[1]
        for i in range(0,cnt):
            if a>=m1[i]:
                continue
            else:
                check1 =  max(check1,(cnt)-i)
                check1 = min((len(fe)-fcnt)+1,check1)
                break

        for i in range(0,cnt):
            if b>=m2[i]:
                continue
            else:
                check2 = max(check2,(cnt)-i)
                check2 = min((len(fe)-fcnt)+1,check2)
                break
        fcnt += 1
    res = min(check1,check2)

    print(res*2)


if __name__=='__main__':
    n = int(input())
    fe = []
    ma = []
    m2 = []
    m1 = []
    for _ in range(n):
        gen,a,b=map(str,input().split())
        a,b = int(a),int(b)
        if gen=='M':
            m1.append(a)
            m2.append(b)
        else:
            fe.append([a,b])
    fe = sorted(fe)
    m1= sorted(m1)
    m2 = sorted(m2)
    res = 0
    check1 = 0
    check2 = 0
    for fem in fe:
        a,b = fem[0],fem[1]
        for i in range(0,n//2):
            if a>=m1[i]:
                continue
            else:
                check1 =  max(check1,(n//2)-i)
                #print("ehck1 ",check1)

        for i in range(0,n//2):
            if b>=m2[i]:
                continue
            else:
                check2 = max(check2,(n//2)-i)
               # print("check2 ",check2)
    res = min(check1,check2)

    print(res*2)


if __name__=='__main__':
    n = int(input())
    fe = []
    ma = []
    m2 = []
    m1 = []
    cnt = 0
    for _ in range(n):
        gen,a,b=map(str,input().split())
        a,b = int(a),int(b)
        if gen=='M':
            cnt+= 1
            m1.append(a)
            m2.append(b)
        else:
            fe.append([a,b])
    fe = sorted(fe)
    m1= sorted(m1)
    m2 = sorted(m2)
    res = 0
    check1 = 0
    check2 = 0
    for fem in fe:
        a,b = fem[0],fem[1]
        for i in range(0,cnt):
            if a>=m1[i]:
                continue
            else:
                check1 =  max(check1,(cnt)-i)
                #print("ehck1 ",check1)

        for i in range(0,cnt):
            if b>=m2[i]:
                continue
            else:
                check2 = max(check2,(cnt)-i)
               # print("check2 ",check2)
    res = min(check1,check2)

    print(res*2)


if __name__=='__main__':
    n = int(input())
    fe = []
    ma = []
    m2 = []
    m1 = []
    cnt = 0
    for _ in range(n):
        gen,a,b=map(str,input().split())
        a,b = int(a),int(b)
        if gen=='M':
            cnt+= 1
            m1.append(a)
            m2.append(b)
        else:
            fe.append([a,b])
    fe = sorted(fe)
    m1= sorted(m1)
    m2 = sorted(m2)
    res = 0
    check1 = 0
    check2 = 0
    for fem in fe:
        a,b = fem[0],fem[1]
        for i in range(0,cnt):
            if a>=m1[i]:
                continue
            else:
                check1 =  max(check1,(cnt)-i)
                #print("ehck1 ",check1)

        for i in range(0,cnt):
            if b>=m2[i]:
                continue
            else:
                check2 = max(check2,(cnt)-1)
               # print("check2 ",check2)
    res = min(check1,check2)

    print(res*2)


DayM=[0 for i in range(367)]
DayF=[0 for i in range(367)]
n=int(input())
for i in range(n):
    a,b,c=input().split()
    Begin=int(b)
    End=int(c)
    for j in range(Begin,End+1):
        if a=='M':
            DayM[j]+=1
        else:
            DayF[j]+=1
M=0
for i in range(367):
    m=min(DayM[i],DayF[i])
    if m>M:
        M=m
print(M*2)


n = int(input())
gender, a, b = [], [], []
for x in range(n):
    string = input()
    friend = string.split()
    gender.append(friend[0])
    a.append(int(friend[1]))
    b.append(int(friend[2]))
friends = []
for x in range(min(a), max(b) + 1):
    m = f = 0
    for y in range(n):
        if a[y] <= x and b[y] >= x:
            if gender[y] == "M":
                m += 1
            else:
                f += 1
    friends.append(min([m, f]) * 2)
print(max(friends))


if __name__ == '__main__':
    n = int(input())
    mi = [0] * 366
    fi = [0] * 366
    for _ in range(n):
        fm, s, e = map(str, input().split())
        if fm == 'M':
            for i in range(int(s) - 1, int(e)):
                mi[i] += 1
        elif fm == 'F':
            for i in range(int(s) - 1, int(e)):
                fi[i] += 1
    print(2 * max([min(m, f) for m, f in zip(mi, fi)]))


M = [0 for i in range(367)]
F = [0 for i in range(367)]
n = int(input())
for i in range(n):
    a,b,c = input().split()
    b = int(b)
    c = int(c)
    if a == 'M':
        for j in range(b,c+1):
            M[j] += 1
    else:
        for j in range(b,c+1):
            F[j] += 1
#print(F)
#print(M)

m = 0
for i in range(1,367):
    x = min(M[i],F[i])
    if x > m:
        m = x
print(m*2)


n = int(input())
d = 367
F = [0 for i in range(d)]
M = [0 for i in range(d)]
for i in range(n):
    sex, l, r = input().split()
    l, r = int(l), int(r)
    if sex == 'F':
        for j in range(l, r+1): F[j] += 1
    else:
        for j in range(l, r+1): M[j] += 1
print(2*max(min(F[i], M[i]) for i in range(d)))


a=int(input())
ma=[]
md=[]
fa=[]
fd=[]
for i in range(a):
    y=input().split()
    if y[0]=='M':
        ma.append(int(y[1]))
        md.append(int(y[2])+1)
    else:
        fa.append(int(y[1]))
        fd.append(int(y[2])+1)
ma.sort()
md.sort()
fa.sort()
fd.sort()
m=0
f=0
mx=0
mpa=0
fpa=0
mda=0
fda=0
for i in range(1,366):
    while mpa<len(ma) and ma[mpa]==i:
        mpa+=1
        m+=1
    while mda<len(md) and md[mda]==i:
        mda+=1
        m-=1
    while fpa<len(fa) and fa[fpa]==i:
        fpa+=1
        f+=1
    while fda<len(fd) and fd[fda]==i:
        fda+=1
        f-=1
    mx=max(mx, min(f,m)*2)
print(mx)


a=int(input())
ma=[]
md=[]
fa=[]
fd=[]
for i in range(a):
    y=input().split()
    if y[0]=='M':
        ma.append(int(y[1]))
        md.append(int(y[2])+1)
    else:
        fa.append(int(y[1]))
        fd.append(int(y[2])+1)
ma.sort()
md.sort()
fa.sort()
fd.sort()
m=0
f=0
mx=0
mpa=0
fpa=0
mda=0
fda=0
for i in range(1,367):
    while mpa<len(ma) and ma[mpa]==i:
        mpa+=1
        m+=1
    while mda<len(md) and md[mda]==i:
        mda+=1
        m-=1
    while fpa<len(fa) and fa[fpa]==i:
        fpa+=1
        f+=1
    while fda<len(fd) and fd[fda]==i:
        fda+=1
        f-=1
    mx=max(mx, min(f,m)*2)
print(mx)


a=int(input())
ma=[]
md=[]
fa=[]
fd=[]
for i in range(a):
    y=input().split()
    if y[0]=='M':
        ma.append(int(y[1]))
        md.append(int(y[2])+1)
    else:
        fa.append(int(y[1]))
        fd.append(int(y[2])+1)
ma.sort()
md.sort()
fa.sort()
fd.sort()
m=0
f=0
mx=0
mpa=0
fpa=0
mda=0
fda=0
for i in range(1,141):
    while mpa<len(ma) and ma[mpa]==i:
        mpa+=1
        m+=1
    while mda<len(md) and md[mda]==i:
        mda+=1
        m-=1
    while fpa<len(fa) and fa[fpa]==i:
        fpa+=1
        f+=1
    while fda<len(fd) and fd[fda]==i:
        fda+=1
        f-=1
    mx=max(mx, min(f,m)*2)
print(mx)


n = int(input())
a = [[0, 0] for _ in range(366)]
for _ in range(n):
	g, s, e = input().split(' ')
	s, e = int(s), int(e)
	if g == 'M':
		for i in range(s-1, e):
			a[i][0] += 1
	else:
		for i in range(s-1, e):
			a[i][1] += 1
ans = 0
for i in a:
	ans = max(ans, 2*min(i))
print(ans)


n = int(input())
l = []
yearm = [0] * 366
yearf = [0] * 366
for i in range(n):
    l.append(input().split())
for i in range(366):
    for j in range(n):
        if l[j][0] == 'M':
            if int(l[j][1]) <= i + 1 <= int(l[j][2]):
                yearm[i] += 1
        else:
            if int(l[j][1]) <= i + 1 <= int(l[j][2]):
                yearf[i] += 1
maxp = 0
for i in range(366):
    if min(yearm[i], yearf[i]) > maxp:
        maxp = min(yearm[i], yearf[i])
print(maxp * 2)


n = int(input())
l = []
yearm = [0] * 366
yearf = [0] * 366
for i in range(n):
    l.append(input().split())
for i in range(366):
    for j in range(n):
        if l[j][0] == 'M':
            if int(l[j][1]) <= i <= int(l[j][2]):
                yearm[i] += 1
        else:
            if int(l[j][1]) <= i <= int(l[j][2]):
                yearf[i] += 1
maxp = 0
for i in range(366):
    if min(yearm[i], yearf[i]) > maxp:
        maxp = min(yearm[i], yearf[i])
print(maxp * 2)


data = []
n = int(input())
for i in range(n):
	temp = input().split()
	data.append([temp[0], int(temp[1]), 'A'])
	data.append([temp[0], int(temp[2]), 'B'])
data.sort(key = lambda x : (x[1], x[2]))
Mcnt = 0
Fcnt = 0
ans = 0
for item in data:
	if item[2] == 'A':
		if item[0] == 'F':
			Fcnt += 1
		else:
			Mcnt += 1
	else:
		if item[0] == 'F':
			Fcnt -= 1
		else:
			Mcnt -= 1
	ans = max(ans, min(Mcnt, Fcnt))
print(ans*2)


n=int(input())
a=[0]*367
b=[0]*367
d=[]
for i in range(n):
    c=list(map(str,input().split()))
    if c[0]=='M':
        for i in range(int(c[1]),int(c[2]) + 1):
            a[i]+=1
    else:
        for i in range(int(c[1]),int(c[2]) + 1):
            b[i]+=1
for i in range(367):
    d.append(min(a[i],b[i]))
print(max(d) * 2)


n=int(input())
a=[0]*367
b=[0]*367
for i in range(n):
    c=list(map(str,input().split()))
    if c[0]=='M':
        for i in range(int(c[1]),int(c[2]) + 1):
            a[i]+=1
    else:
        for i in range(int(c[1]),int(c[2]) + 1):
            b[i]+=1
x=min(a[1],b[1])
for i in range(2,367):
    if x <min(a[i],b[i]):
        x=min(a[i],b[i])
print(2*x)


n = int(input())

males = [0]*368
females = [0]*368
for i in range(n):
    pol, a, b = input().split()
    a = int(a)
    b = int(b)
    if pol == 'M':
        for i in range(a,b+1):
            males[i]+=1
    else:
        for i in range(a,b+1):
            females[i]+=1
ans = 0
for i in range(368):
    if min(males[i],females[i])>ans:
        ans = min(males[i],females[i])
print(ans*2)


n = int(input())

males = [0]*367
females = [0]*367
for i in range(n):
    pol, a, b = input().split()
    a = int(a)
    b = int(b)
    if pol == 'M':
        for i in range(a,b+1):
            males[i]+=1
    else:
        for i in range(a,b+1):
            females[i]+=1
ans = 0
for i in range(367):
    if (males[i] == females[i]) and males[i]>ans:
        ans = males[i]
print(ans*2)


n = int(input())

males = [0]*368
females = [0]*368
for i in range(n):
    pol, a, b = input().split()
    a = int(a)
    b = int(b)
    if pol == 'M':
        for i in range(a,b+1):
            males[i]+=1
    else:
        for i in range(a,b+1):
            females[i]+=1
ans = 0
for i in range(368):
    if (males[i] == females[i]) and (males[i]>ans):
        ans = males[i]
print(ans*2)


n=int(input())
friends=[None]*n*3
from_to=[None]*n*2
for i in range(n):
	line=input().split()
	friends[i*3]=line[0]
	friends[i*3+1]=from_to[i*2]=int(line[1])
	friends[i*3+2]=from_to[i*2+1]=int(line[2])

from_to_dist=list(set(from_to))
len_from_to_dist=len(from_to_dist)
female_male=[0]*len_from_to_dist*2
pair_counts=[None]*len_from_to_dist
for i in range(len_from_to_dist):
	cur=from_to_dist[i]
	for j in range(n):
		if cur>=friends[j*3+1] and cur<=friends[j*3+2]:
			if friends[j*3]=='F':
				female_male[i*2]+=1
			else:
				female_male[i*2+1]+=1
	pair_counts[i]=min(female_male[i*2],female_male[i*2+1])
print(max(pair_counts)*2)


from sys import *
inp = lambda : stdin.readline()
N = 368
def main():
    n = int(inp())
    m = [0 for i in range(N)]
    f = m[:]
    for i in range(n):
        s = inp().split()
        if s[0] == 'M':
            m[int(s[1])] += 1
            m[int(s[2])+1] -= 1
        else:
            f[int(s[1])] += 1
            f[int(s[2])+1] -= 1
    myet,fyet,ans = 0,0,0
    for i in range(1,N):
        myet += m[i]
        fyet += f[i]
        if fyet == myet:
            ans = max(2*fyet,ans)
    print(ans)

if __name__ == "__main__":
    main()


from sys import *
inp = lambda : stdin.readline()
N = 368
def main():
    n = int(inp())
    m = [0 for i in range(N)]
    f = m[:]
    for i in range(n):
        s = inp().split()
        if s[0] == 'M':
            m[int(s[1])] = 1
            m[int(s[2])+1] = -1
        else:
            f[int(s[1])] = 1
            f[int(s[2])+1] = -1
    myet,fyet,ans = 0,0,0
    for i in range(1,N):
        myet += m[i]
        fyet += f[i]
        if fyet == myet:
            ans = max(2*fyet,ans)
    print(ans)

if __name__ == "__main__":
    main()


from sys import *
inp = lambda : stdin.readline()
N = 368
def main():
    n = int(inp())
    m = [0 for i in range(N)]
    f = m[:]
    for i in range(n):
        s = inp().split()
        if s[0] == 'M':
            m[int(s[1])] += 1
            m[int(s[2])+1] -= 1
        else:
            f[int(s[1])] += 1
            f[int(s[2])+1] -= 1
    myet,fyet,ans = 0,0,0
    for i in range(1,N):
        myet += m[i]
        fyet += f[i]
        ans = max(2 * min(fyet,myet), ans)

    print(ans)

if __name__ == "__main__":
    main()


m=[0]*367
f=[0]*367
for i in range(int(input())):
    a=list(input().split())
    if   a[0]=='M':
        for i in range(int(a[1]),int(a[2])+1):
            m[i]+=1
    else:
        for i in range(int(a[1]),int(a[2])+1):
            f[i]+=1
x=0
for i in range(367):
    x=max(x,min(m[i],f[i]))
print(2*x)


n = int(input())
data_m = []
data_f = []
for i in range(n):
    sex, start, finish = input().split()
    if sex == 'M':
        data_m.append([int(start), int(finish)])
    else:
        data_f.append([int(start), int(finish)])
data_m.sort()
data_f.sort()
m, f = 0, 0
start, finish = -1, 100000000000000000000000
help = 0
ans = 0
while m < min(len(data_m), len(data_f)) and f < min(len(data_m), len(data_f)):
    if data_m[m][0] > data_f[f][1]:
        f += 1
    elif data_f[f][0] > data_m[m][1]:
        m += 1
    elif data_f[f][0] <= data_m[m][1] <= data_f[f][1] or data_m[f][0] <= data_f[f][1] <= data_m[m][1]:
        start = max(data_f[f][0], data_m[m][0], start)
        finish = min(data_f[f][1], data_m[m][1], finish)
        help += 2
        if start > finish:
            ans = max(ans, help)
            help = 0
        f += 1
        m += 1
print(max(ans, help))


data_m = [0 for i in range(367)]
data_f = [0 for i in range(367)]
for i in range(int(input())):
    sex, start, finish = input().split()
    if sex == 'M':
        for j in range(int(start), int(finish) + 1):
            data_m[j] += 1
    else:
        for j in range(int(start), int(finish) + 1):
                    data_f[j] += 1
ans = 0
for i in range(367):
    ans = max(ans, min(data_f[i], data_m[i]))
print(ans * 2)


n = int(input())
data = []
a = 0
F = 0
M = 0
for i in range(n):
    sex, start, finish = input().split()
    data.append([int(start),  int(finish)])
    if sex == 'M':
        M += 1
    else:
        F += 1
for i in range(1, 367):
    help = 0
    for j in range(n):
        if data[j][0] <= i <= data[j][1]:
            help += 1
    a = max(a, help)
print(min(a, min(F, M) * 2))


n = int(input())
data_m = []
data_f = []
for i in range(n):
    sex, start, finish = input().split()
    if sex == 'M':
        data_m.append([int(start), int(finish)])
    else:
        data_f.append([int(start), int(finish)])
data_m.sort()
data_f.sort()
m, f = 0, 0
start, finish = 0, 367
help = 0
ans = 0
while m < min(len(data_m), len(data_f)) and f < min(len(data_m), len(data_f)):
    if data_m[m][0] > data_f[f][1]:
        f += 1
    elif data_f[f][0] > data_m[m][1]:
        m += 1
    elif data_f[f][0] <= data_m[m][1] <= data_f[f][1] or data_m[f][0] <= data_f[f][1] <= data_m[m][1]:
        start = max(data_f[f][0], data_m[m][0], start)
        finish = min(data_f[f][1], data_m[m][1], finish)
        help += 2
        if start > finish:
            ans = max(ans, help)
            help = 0
        f += 1
        m += 1
print(max(ans, help))


class Guest(object):
    def __init__(self, gender, start_day, end_day):
        self.gender = gender
        self.start_day = start_day
        self.end_day = end_day

    def __str__(self):
        return " ".join([self.gender, str(self.start_day), str(self.end_day)])

class Party(object):
    def __init__(self, number_of_guests):
        self.number_of_guests = number_of_guests
        self.guests = []
        self.number_of_available_guests_on_day = [0]*366

    def __str__(self):
        output = ""
        for counter in range(self.number_of_guests):
            output = "\n".join([output, self.guests[counter].__str__()])
        return output

    def add_guest(self, gender, start_day, end_day):
        self.guests.append(Guest(gender, start_day, end_day))

    def determine_guests_available_on_day(self,index):
        day = index + 1
        males = 0
        females = 0
        for guest in self.guests:
            if guest.start_day <= day <= guest.end_day:
                if guest.gender == 'M':
                    males += 1
                else:
                    females += 1
        self.number_of_available_guests_on_day[index] = min(males,females)*2

    def check_all_days(self):
        for index in range(366):
            self.determine_guests_available_on_day(index)

if __name__ == '__main__':
    doors_party = Party(int(input()))
    for i in range(doors_party.number_of_guests):
        input_guest = input().split(" ")
        doors_party.add_guest(input_guest[0],
                              int(input_guest[1]),
                              int(input_guest[2]))

    print(doors_party)

    doors_party.check_all_days()

    print(max(doors_party.number_of_available_guests_on_day))


class Guest(object):
    def __init__(self, gender, start_day, end_day):
        self.gender = gender
        self.start_day = start_day
        self.end_day = end_day

    def __str__(self):
        return " ".join([self.gender, str(self.start_day), str(self.end_day)])

class Party(object):
    def __init__(self, number_of_guests):
        self.number_of_guests = number_of_guests
        self.guests = []
        self.number_of_available_guests_on_day = [0]*366

    def __str__(self):
        output = ""
        for counter in range(self.number_of_guests):
            output = "\n".join([output, self.guests[counter].__str__()])
        return output

    def add_guest(self, gender, start_day, end_day):
        self.guests.append(Guest(gender, start_day, end_day))

    def determine_guests_available_on_day(self,index):
        day = index + 1
        males = 0
        females = 0
        for guest in self.guests:
            if guest.start_day <= day <= guest.end_day:
                if guest.gender == 'M':
                    males += 1
                else:
                    females += 1
        self.number_of_available_guests_on_day[index] = min(males,females)*2

    def check_all_days(self):
        for index in range(366):
            self.determine_guests_available_on_day(index)

if __name__ == '__main__':
    doors_party = Party(int(input()))
    for i in range(doors_party.number_of_guests):
        input_guest = input().split(" ")
        doors_party.add_guest(input_guest[0],
                              int(input_guest[1]),
                              int(input_guest[2]))

    # print(doors_party)

    doors_party.check_all_days()

    print(max(doors_party.number_of_available_guests_on_day))


#include <bits/stdc++.h>

using namespace std;

int n;

int main(){
	cin >> n;

	if(n == 2) { cout << -1 << endl; cout << 1 << " " << 2 << endl; }
	else {
		for(int i = 1; i <= n-1; i++){
			if(i < (n-3))
				cout << 1 << " " << i+1 << endl;
			else
				cout << 2 << " " << i+1 << endl;
		}

		//Caso que sempre da certo
		for(int i = 1; i <= n-1; i++){
			cout << i << " " << i+1 << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define debug(a) cout<< #a <<" = "<< a <<end

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int n;
  cin >> n;
  if(n <= 4 || n%2 == 1) cout << -1 << endl;
  else{
    cout << "1 2" << endl;
    cout << "1 3" << endl;
    for(int i = 2; i <= n-2; i += 2){
      cout << i << " " << i+2 << endl;
      if(i != n-2)cout << i << " " << i+3 << endl;
    }
  }
  for(int i = 2; i <= n; ++i){
    cout << "1 " << i << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define debug(a) cout<< #a <<" = "<< a <<end

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int n;
  cin >> n;
  if(n <= 5) cout << -1 << endl;
  else{
    for(int i = 2; i <= n-2; ++i) cout << 1 << " " << i << endl;
    cout << 2 << " " << n-1 << endl;
    cout << 2 << " " << n << endl;
  }
  for(int i = 2; i <= n; ++i){
    cout << "1 " << i << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define debug(a) cout<< #a <<" = "<< a <<end

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int n;
  cin >> n;
  if(n == 2){
    cout << -1 << endl;
    cout << "1 2" << endl;
  }
  else if(n == 3){
    cout << -1 << endl;
    cout << "1 2" << endl;
    cout << "1 3" << endl;
  }
  else{
    for(int i = 1; i <= n-1; ++i){
      cout << i << " " << i+1 << endl;
    }
    for(int i = 2; i <= n; ++i){
      cout << "1 " << i << endl;
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define debug(a) cout<< #a <<" = "<< a <<end

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int n;
  cin >> n;
  if(n <= 5) cout << -1 << endl;
  else{
    int root = 1,t = 2,new_root = 2;
    bool f = 0;
    while(1){
      for(int i = new_root; i <= new_root+t-1; ++i){
        if(i > n){
          f = 1;
          break;
        }
        cout << root << " " << i << endl;
      }
      if(f) break;
      root = new_root;
      new_root += t;
      t++;
    }
  }
  for(int i = 2; i <= n; ++i){
    cout << "1 " << i << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
///#define mp make_pair
#define ll long long
const int MX=3e5;
int N, M, k;
int arr[MX];
int p[MX], mn[MX];
map<string, int> mp;
int f(int x)
{
    if(x == p[x]) return x;

    return p[x]=f(p[x]);
}
void un(int x, int y)
{
    x=f(x);
    y=f(y);
    if(x == y) return ;
    if(arr[x] > arr[y])
        p[x]=y;
    else p[y]=x;
}
void read()
{

    for(int i=1; i<=N; i++) scanf("%d", &arr[i]), mn[i]=arr[i];
}
char s[22];
int main()
{
    cin>>N
    ;
    if(N > 4)
    {
        for(int i=2;i<=N-1;i++)
             cout<<i << ' '<<1<<'\n';
        cout<<N<<" "<<N-1<<"\n";
        for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';

    }
    else if(N == 2)
    {
        cout<<-1<<"\n"<<1<<" "<<2<<"\n";

    }
    else
    {
        cout<<-1<<"\n";
       for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
const int MX=3e5;
int N, M, k;
int arr[MX];
void p(int x, int xx)
{
    cout<<x<<  " "<<xx<<"\n";
}
int main()
{
    cin>>N;
    if(N < 6) cout<<-1<<"\n";
    else
    {
        p(1, 2);
        p(2, 4);
        p(2, 5);
        p(1, 3);
        p(1, 6);
        for(int i=7;i<=N;i++)
            p(1, i);
    }
    for(int i=2;i<=N;i++) p(i, i-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
///#define mp make_pair
#define ll long long
const int MX=3e5;
int N, M, k;
int arr[MX];
int p[MX], mn[MX];
map<string, int> mp;
int f(int x)
{
    if(x == p[x]) return x;

    return p[x]=f(p[x]);
}
void un(int x, int y)
{
    x=f(x);
    y=f(y);
    if(x == y) return ;
    if(arr[x] > arr[y])
        p[x]=y;
    else p[y]=x;
}
void read()
{

    for(int i=1; i<=N; i++) scanf("%d", &arr[i]), mn[i]=arr[i];
}
char s[22];
int main()
{
    cin>>N
    ;
    if(N > 3)
    {
        for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';
        for(int i=2;i<=N;i++)
             cout<<i << ' '<<1<<'\n';
    }
    else if(N == 2)
    {
        cout<<-1<<"\n"<<1<<" "<<2<<"\n";

    }
    else
    {
        cout<<-1<<"\n";
        cout<<1<< ' '<<2<<'\n';
        cout<<2<<" "<<3;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
///#define mp make_pair
#define ll long long
const int MX=3e5;
int N, M, k;
int arr[MX];

void p(int x, int xx)
{
    cout<<x<<  " "<<xx<<"\n";
}
int main()
{
    cin>>N
    ;
    if(N > 7)
    {
        p(1, 2);
        p(1, 3);
        p(3, 5);
        p(2, 4);
        p(2, 6);
        p(4, 7);
        p(4, 8);
        for(int i=9;i<=N;i++)
        {
            p(8, i);
        }
        for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';

    }
    else if(N == 2)
    {
        cout<<-1<<"\n"<<1<<" "<<2<<"\n";

    }
    else
    {
        cout<<-1<<"\n";
       for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
///#define mp make_pair
#define ll long long
const int MX=3e5;
int N, M, k;
int arr[MX];

void p(int x, int xx)
{
    cout<<x<<  " "<<xx<<"\n";
}
int main()
{
    cin>>N
    ;
    if(N > 7)
    {
        p(1, 2);
        p(1, 3);
        p(3, 5);
        p(2, 4);
        p(2, 6);
        p(4, 7);
        p(4, 8);
        bool ok=1;
        for(int i=9;i<=N;i++)
        {
            if(!ok)
            p(4, i);
            else
            p(2, i);
            ok=!ok;
        }
        for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';

    }
    else if(N == 2)
    {
        cout<<-1<<"\n"<<1<<" "<<2<<"\n";

    }
    else
    {
        cout<<-1<<"\n";
       for(int i=2;i<=N;i++) cout<<i<<" "<<i-1<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
///#define mp make_pair
#define ll long long
const int MX=3e5;
int N, M, k;
int arr[MX];

void p(int x, int xx)
{
    cout<<x<<  " "<<xx<<"\n";
}
int main()
{
    cin>>N
       ;
    if(N > 7)
    {
        p(1, 2);
        p(1, 3);
        p(3, 5);
        p(2, 4);
        p(2, 6);
        p(4, 7);
        p(4, 8);
        bool ok=1;
        for(int i=9; i<=N; i++)
        {
            if(!ok)
                p(4, i);
            else
                p(2, i);
            ok=!ok;
        }
        for(int i=2; i<=N; i++) cout<<i<<" "<<i-1<<'\n';

    }
    else if(N == 7)
    {
        p(1, 2);
        p(1, 4);
        p(1, 3);
      //  p(3, 5);
        p(1, 5);
        p(2, 6);
        p(2, 7);
        for(int i=2; i<=N; i++) cout<<i<<" "<<i-1<<'\n';
    }
    else
    {
        cout<<-1<<"\n";
        for(int i=2; i<=N; i++) cout<<i<<" "<<i-1<<'\n';
    }
    return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<sstream>
#include<cmath>
#include<iterator>
#include<bitset>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
int readint() { int x; cin >> x; return x; }
const int INF = 1 << 30;
const int maxn = 100005;

int main() {
	int n;

	while (cin >> n) {
		if (n < 6) cout << "-1" << endl;
		else {
			cout << "1 2\n1 3\n1 4\n2 5\n2 6\n";
			for (int i = 6; i <= n; ++i) {
				printf("2 %d\n", i);
			}
		}
		for (int i = 1; i < n; ++i) {
			printf("%d %d\n", i, i + 1);
		}
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<sstream>
#include<cmath>
#include<iterator>
#include<bitset>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
int readint() { int x; cin >> x; return x; }
const int INF = 1 << 30;
const int maxn = 100005;

int main() {
	int n;

	while (cin >> n) {
		if (n < 6) cout << "-1" << endl;
		else {
			cout << "1 2\n1 3\n1 4\n2 5\n2 6\n";
			for (int i = 6; i <= n; ++i) {
				printf("4 %d\n", i);
			}
		}
		for (int i = 1; i < n; ++i) {
			printf("%d %d\n", i, i + 1);
		}
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<sstream>
#include<cmath>
#include<iterator>
#include<bitset>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
int readint() { int x; cin >> x; return x; }
const int INF = 1 << 30;
const int maxn = 100005;

int main() {
	int n;

	while (cin >> n) {
		if (n < 6) cout << "-1" << endl;
		else {
			cout << "1 2\n1 3\n1 4\n2 5\n2 6\n";
			for (int i = 7; i <= n; ++i) {
				printf("2 %d\n", i);
			}
		}
		for (int i = 1; i < n; ++i) {
			printf("%d %d\n", i, i + 1);
		}
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<sstream>
#include<cmath>
#include<iterator>
#include<bitset>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
int readint() { int x; cin >> x; return x; }
const int INF = 1 << 30;
const int maxn = 100005;

int main() {
	int n;

	while (cin >> n) {
		if (n < 8) cout << "-1" << endl;
		else {
			cout << "1 2\n1 3\n2 4\n2 5\n3 6\n4 7\n4 8\n";
			for (int i = 9; i <= n; ++i) {
				printf("4 %d\n", i);
			}
		}
		for (int i = 1; i < n; ++i) {
			printf("%d %d\n", i, i + 1);
		}
	}

	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int main()
{ int n;
scanf("%d",&n);
int a=1 , b=1 ;
do {
      printf( "%d_%d\n",b,++a"); if (a+1>n)break;
      printf("%d_%d\n",a,a+1") ;if (a+1>n)break;
      printf("%d_%d\n",a,a+2") ;
      a=a+2 ;} while (a<n);

      cout<< "\n";

      if (n<6) cout <<-1 ;
      else {
        int c=1;
        printf ("%d_%d\n",c,++c);
        printf ("%d_%d\n",c,c+1);
        printf ("%d_%d\n",c,c+2);
        c=c+3;
        for (int i=0 ;i<=n ;i++) { printf ("%d_%d \n",1,i);}

      }

    return 0;


#include<bits/stdc++.h>
using namespace std;
#define INT_SIZE 32
#define ll long long int
#define ff first
#define ss second
int X[2000005],used[2000005],start=2;
vector<int> A[2000005];
void sieve()
{
	memset(X,1,sizeof(X));
	X[0]=X[1]=0;
	for(int i=2;i<2000005;++i) {
		if(X[i]) {
			for(int j=i;j<2000005;j+=i) {
				A[j].push_back(i);
				X[j]=0;
			}
		}
	}
}
void solve(int x) {
	for(int i=0;i<A[x].size();++i) {
		used[A[x][i]]=1;
	}
}
int check(int x)
{
	for(int i=0;i<A[x].size();++i) {
		if(used[A[x][i]]==1) return 1;
	}
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    int n;  cin>>n;
    sieve();  memset(used,0,sizeof(used));
    int cur=2,c=1,x,a;
    for(int i=0;i<n;++i) {
    	cin>>a;  x=a;
    	if(c==1) {
    		while(check(x)) {
    			x++;
			}
			if(x!=a) c=0;
		}
		else {
			while(check(cur)) {
				cur++;
			}
			x=cur;
		}
		solve(x);
		cout<<x<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INT_SIZE 32
#define ll long long int
#define ff first
#define ss second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    int n; cin>>n;
    if(n<6) {
    	cout<<-1<<endl;
	}
	else {
		cout<<1<<" "<<2<<endl;
		for(int i=2;i<=n;i+=2) {
			if(i+1<=n) cout<<i<<" "<<i+1<<endl;
			if(i+2<=n) cout<<i<<" "<<i+2<<endl;
		}
	}
	if(n==2) {
		cout<<1<<" "<<2<<endl;
		return 0;
	}
	if(n==3) {
		cout<<1<<" "<<2<<endl;
		cout<<1<<" "<<3<<endl;
		return 0;
	}
		cout<<1<<" "<<2<<endl;
		cout<<1<<" "<<3<<endl;
	for(int i=2;i<=n;i+=2) {
		if(i+2<=n) cout<<i<<" "<<i+2<<endl;
	}
	for(int i=3;i<=n;i+=2) {
		if(i+2<=n) cout<<i<<" "<<i+2<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INT_SIZE 32
#define ll long long int
#define ff first
#define ss second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
	 ll n;
    cin>>n;
    if(n<6){
        cout<<-1<<endl;
    }
    else{
        cout<<1<<" "<<2<<endl;
        cout<<1<<" "<<3<<endl;
        cout<<1<<" "<<4<<endl;
        for(ll i=5;i<=n;i++){
            cout<<2<<" "<<i<<endl;
        }
    }
    for(ll i=2;i<=n;i++){
        cout<<1<<" "<<i<<endl;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INT_SIZE 32
#define ll long long int
#define ff first
#define ss second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    int n; cin>>n;
    if(n<6||n%2!=0) {
    	cout<<-1<<endl;
	}
	else {
		cout<<1<<" "<<2<<endl;
		for(int i=2;i<=n;i+=2) {
			if(i+1<=n) cout<<i<<" "<<i+1<<endl;
			if(i+2<=n) cout<<i<<" "<<i+2<<endl;
		}
	}
	if(n==2) {
		cout<<1<<" "<<2<<endl;
		return 0;
	}
	if(n==3) {
		cout<<1<<" "<<2<<endl;
		cout<<1<<" "<<3<<endl;
		return 0;
	}
		cout<<1<<" "<<2<<endl;
		cout<<1<<" "<<3<<endl;
	for(int i=2;i<=n;i+=2) {
		if(i+2<=n) cout<<i<<" "<<i+2<<endl;
	}
	for(int i=3;i<=n;i+=2) {
		if(i+2<=n) cout<<i<<" "<<i+2<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
void W(int x, int y) { printf("%d %d\n", x, y); }
int main()
{
    scanf("%d", &n);
    if(n<6) puts("-1");
    else if((n-6)&1) {
        rep(i,1,n-7) W(i, i+1);
        W(n-2, n-4); W(n-2, n);
        W(n-2, n-1); W(n-3, n-4);
        W(n-4, n-5); W(n-4, n-6);
    }
    else {
        rep(i,1,n-6) W(i, i+1);
        W(n-2, n-4); W(n-2, n);
        W(n-2, n-1); W(n-3, n-4);
        W(n-4, n-5);
    }
    rep(i,1,n-1)  W(i, i+1);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
void W(int x, int y) { printf("%d %d\n", x, y); }
int main()
{
    scanf("%d", &n);
    if(n<6) puts("-1");
    else {
        rep(i,2,n-5) printf("%d %d\n", i-1, i);
        W(n-2, n-4); W(n-2, n);
        W(n-2, n-1); W(n-3, n-4);
        W(n-4, n-5);
    }
    rep(i,1,n-1)  W(i, i+1);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
void W(int x, int y) { printf("%d %d\n", x, y); }
int main()
{
    scanf("%d", &n);
    if(n<6) puts("-1");
    else if((n-6)&1) puts("-1");
    else {
        rep(i,1,n-6) W(i, i+1);
        W(n-2, n-4); W(n-2, n);
        W(n-2, n-1); W(n-3, n-4);
        W(n-4, n-5);
    }
    rep(i,1,n-1)  W(i, i+1);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
void W(int x, int y) { printf("%d %d\n", x, y); }
int main()
{
    scanf("%d", &n);
    if(n<8) puts("-1");
    else {
        rep(i,2,n-7) printf("%d %d\n", i-1, i);
        W(n-7, n-5); W(n-7, n-6);
        W(n-5, n-2); W(n-6, n-4);
        W(n-6, n-3); W(n-4, n);
        W(n-4, n-1);
    }
    rep(i,1,n-1)  W(i, i+1);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <stack>
#include <bitset>
#include <sstream>
#include <fstream>
#include <map>
#include <iomanip>
#include <cmath>
#include <climits>
#define mod 1000000007
#define MATHPI 3.14159265359
#define lli long long
#define forr(a,b) for(long long i=a;i<b;i++)
#define endl '\n'
#define MP(a,b) make_pair(a,b)
//#define pii pair<long long,long long>
#define ld long double
#define PII pair<long long,long long>
#define PIII pair<long long,pair<long long ,long long> >
#define S second
#define F first
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    lli n,m;
    cin>>n>>m;
    string ss[n];
    for(lli i=0;i<n;i++){
        cin>>ss[i];
    }
    lli right[n][m],down[n][m];
    for(lli i=0;i<n;i++){
        if(ss[i][0] == '*') right[i][0] = 0;
        else right[i][0] = -1;
        for(lli j=1 ;j<m;j++){
            if(ss[i][j]=='.')right[i][j] = -1;
            else if(right[i][j-1]>-1)right[i][j] = right[i][j-1];
            else right[i][j] = j;
        }
    }
    for(lli i=0;i<m;i++){
        if(ss[0][i] == '*') down[0][i] = 0;
        else down[0][i] = -1;
        for(lli j=1 ;j<n;j++){
            if(ss[j][i]=='.')down[j][i] = -1;
            else if(down[j-1][i]>-1)down[j][i] = down[j-1][i];
            else down[j][i] = j;
        }
    }
    vector<PIII> ans;
    for(lli i=0;i<n;i++){
        for(lli j=0;j<m;j++){
            if(ss[i][j]=='.')continue;
            lli mine=1000;
            lli start = 0;
            while(mine){
                while(1){
                    if(i+start+mine >= n || i-start-mine < 0) break;
                    if(j+start+mine >= m || j-start-mine < 0) break;
                    if(down[i+start+mine][j] == -1 || (down[i+start+mine][j] != down[i-start-mine][j])) break;
                    if(right[i][j+start+mine]==-1||(right[i][j+start+mine] != right[i][j-start-mine])) break;
                    start += mine;
                }
                mine/=2;
            }
            mine = start;
            if(mine == 0)continue;
            PIII p = MP(mine,MP(i,j));
            ans.push_back(p);
            //cout<<p.S.F;
        }
    }
    lli grid[n][m];
    for(lli i=0;i<n;i++){
        for(lli j=0;j<m;j++)grid[i][j] = 0;
    }
    for(lli i=0;i<ans.size();i++){
        for(lli j=0;j<=ans[i].F;j++){
            grid[ans[i].S.F+j][ans[i].S.S] = 1;
            grid[ans[i].S.F-j][ans[i].S.S] = 1;
            grid[ans[i].S.F][ans[i].S.S+j] = 1;
            grid[ans[i].S.F][ans[i].S.S-j] = 1;
        }
    }
    for(lli i=0;i<n;i++){
        for(lli j=0 ;j<m;j++){
            if(grid[i][j] == 0 &&ss[i][j] == '*'){
                cout<<-1;
                return 0;
            }
        }
    }
    cout<<ans.size()<<endl;
    for(lli i =0 ;i<ans.size();i++){
        cout<<ans[i].S.F+1<<' '<<ans[i].S.S+1<<' '<<ans[i].F<<endl;
    }
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1001][1001];
char grid[1001][1001];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( grid[i][j] == '*' && ! stars[i][j] )
                        {
                                return false;
                        }
                }
        }

        return true;
}

bool Valid(int &x,int &y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);
        int st=0;
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
			st+=(grid[i][j]=='*');
                }
        }

	if(st>n*m/2) return puts("-1"),0;
        HitStars();

        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1001][1001];
char grid[1001][1001];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( grid[i][j] == '*' && ! stars[i][j] )
                        {
                                return false;
                        }
                }
        }

        return true;
}

bool Valid(int &x,int &y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);
        int st=0;
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
			st+=(grid[i][j]=='*');
                }
        }
        int x=n*m; x=x*(x+1)*2;
	if(st>x) return puts("-1"),0;
        HitStars();

        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1001][1001];
char grid[1001][1001];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( grid[i][j] == '*' && ! stars[i][j] )
                        {
                                return false;
                        }
                }
        }

        return true;
}

bool Valid(int &x,int &y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);

        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
                }
        }

        HitStars();

        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


#include <bits/stdc++.h>
using namespace std;
int star[200][200], n, m, cntr;
vector<int> v;
void f(int x, int y){
    int left = y-1, right = y+1, up = x-1, down = x+1, c=0;
    while(left>-1 && right<m && up>-1 && down<n)
    {
        if(!star[x][left] || !star[x][right] || !star[up][y] || !star[down][y]) break;
        if(star[x][left]==1){star[x][left]=2; c=1;}
        if(star[x][right]==1){star[x][right]=2; c=1;}
        if(star[up][y]==1){star[up][y]=2; c=1;}
        if(star[down][y]==1){star[down][y]=2; c=1;}

        left--; up--; right++; down++;
    }
    if(right-y-1 && star[x][y]==1){c=1; star[x][y]=2;}
    if(c){v.push_back(x+1); v.push_back(y+1); v.push_back(right-y-1);}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char x; cin >> x;
            if(x=='*') star[i][j]=1;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if(star[i][j]) f(i, j);
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if(star[i][j]==1){cout << -1; return 0;}
        }
    }

    cout << v.size()/3 << endl;
    for (int i = 0; i < v.size(); i+=3) {
        cout << v[i] << " " << v[i+1] << " " << v[i+2] << endl;
    }

    return 0;
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m,stars[1111][1111];
char grid[1111][1111];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if(grid[i][j]=='*'&&!stars[i][j])
                        {
                                return false;
                        }
                }
        }
        return true;
}

bool Valid(int x,int y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        int x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;
                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]++;
                                stars[x2--][j]++;
                                stars[i][y1++]++;
                                stars[i][y2--]++;
                        }
                        if(Once)
                                stars[i][j]++,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
                }
        }

        HitStars();
        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)

int n,m,stars[1111][1111];
char grid[1111][1111];
vector<pair<int,pair<int,int> > >Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if(grid[i][j]=='*'&&!stars[i][j])
                        {
                                return false;
                        }
                }
        }
        return true;
}
bool Valid(int x,int y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

int SizeOne(int &x,int &y)
{
        return ( Valid(x,y) + Valid(x+1,y) + Valid(x-1,y) + Valid(x,y+1) + Valid(x,y-1) );
}

int SizeTwo(int &x,int &y)
{
        return ( Valid(x+2,y) + Valid(x-2,y) + Valid(x,y+2) + Valid(x,y-2) + SizeOne(x,y) );
}

int SizeThree(int &x,int &y)
{
        return ( Valid(x+3,y) + Valid(x-3,y) + Valid(x,y+3) + Valid(x,y-3) + SizeTwo(x,y));
}

void FillOne(int &x,int &y)
{
        stars[x][y]++;
        stars[x+1][y]++;
        stars[x-1][y]++;
        stars[x][y+1]++;
        stars[x][y-1]++;
}

void FillTwo(int &x,int &y)
{
        FillOne(x,y);
        stars[x+2][y]++;
        stars[x-2][y]++;
        stars[x][y-2]++;
        stars[x][y+2]++;
}

void FillThree(int &x,int &y)
{
        FillTwo(x,y);
        stars[x-3][y]++;
        stars[x+3][y]++;
        stars[x][y+3]++;
        stars[x][y-3]++;
}

void HitStars()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( SizeThree(i,j) == 13 )
                        {
                                FillThree(i,j);
                                Star.pb({i+1,{j+1,3}});

                        }elif( SizeTwo(i,j) == 9 )
                        {
                                FillTwo(i,j);
                                Star.pb({i+1,{j+1,2}});

                        }elif( SizeOne(i,j) == 5 )
                        {
                                FillOne(i,j);
                                Star.pb({i+1,{j+1,1}});
                        }
                }
        }
}

int main()
{
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
                }
        }

        HitStars();
        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1001][1001];
char grid[1001][1001];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( grid[i][j] == '*' && ! stars[i][j] )
                        {
                                return false;
                        }
                }
        }

        return true;
}

bool Valid(int &x,int &y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);
        int st=0;
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
			st+=(grid[i][j]=='*');
                }
        }
        int x=min(n/2+n%2,m/2+m%2); x=x*(x+1)*2;
	if(st>x) return puts("-1"),0;
        HitStars();

        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


#include <bits/stdc++.h>
using namespace std;
int star[200][200], n, m, cntr;
vector<int> v;
void f(int x, int y){
    int left = y-1, right = y+1, up = x-1, down = x+1, c=0;
    while(left>-1 && right<m && up>-1 && down<n)
    {
        if(!star[x][left] || !star[x][right] || !star[up][y] || !star[down][y]) break;
        if(star[x][left]==1){star[x][left]=2; c=1;}
        if(star[x][right]==1){star[x][right]=2; c=1;}
        if(star[up][y]==1){star[up][y]=2; c=1;}
        if(star[down][y]==1){star[down][y]=2; c=1;}

        left--; up--; right++; down++;
    }
    if(right-y-1 && star[x][y]==1){c=1; star[x][y]=2;}
    if(c){v.push_back(x+1); v.push_back(y+1); v.push_back(right-y-1);}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char x; scanf(" %c",&x);
            if(x=='*') star[i][j]=1;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if(star[i][j]) f(i, j);
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if(star[i][j]==1){cout << -1; return 0;}
        }
    }

    cout << v.size()/3 << endl;
    for (int i = 0; i < v.size(); i+=3) {
        printf("%d %d %d \n",v[i],v[i+1],v[i+2]);
    }

    return 0;
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1001][1001];
char grid[1001][1001];
vector<iiint>Star;

void CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( grid[i][j] == '*' && stars[i][j] == false )
                        {
                                puts("-1");
                                exit(0);
                        }
                }
        }
}

bool Valid(int &x,int &y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);

        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
                }
        }

        HitStars();

        CheckStar();

                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }

}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1001][1001];
char grid[1001][1001];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if( grid[i][j] == '*' && ! stars[i][j] )
                        {
                                return false;
                        }
                }
        }

        return true;
}

bool Valid(int &x,int &y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);
        int st=0;
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
			st+=(grid[i][j]=='*');
                }
        }
        int x=min(n/2,m/2); x=x*(x+1)*2;
	if(st>x) return puts("-1"),0;
        HitStars();

        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}


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

#define pb push_back
#define ll long long
#define f first
#define s second
#define elif(ex) else if(ex)
#define iiint pair<int,pair<int,int > >

int n,m;
bool stars[1111][1111];
char grid[1111][1111];
vector<iiint>Star;

bool CheckStar()
{
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if(grid[i][j]=='*'&&!stars[i][j])
                        {
                                return false;
                        }
                }
        }
        return true;
}

bool Valid(int x,int y)
{
        return ( x >= 0 && x < n && y >= 0 && y < m && grid[x][y] == '*' );
}

void HitStars()
{
        for(int x1,x2,y1,y2,i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {

                        x1 = i + 1 , x2 = i - 1 , y1 = j + 1 , y2 = j - 1 ;
                        bool Once = false ;

                        while( grid[i][j] == '*' && Valid(x1,j) && Valid(x2,j) && Valid(i,y1) && Valid(i,y2) )
                        {
                                Once=true;
                                stars[x1++][j]=true;
                                stars[x2--][j]=true;
                                stars[i][y1++]=true;
                                stars[i][y2--]=true;
                        }

                        if(Once)
                                stars[i][j]=true,Star.pb({i+1,{j+1,x1-i-1}});
                }
        }
}

int main()
{
        cin>>n>>m;

        memset(stars,false,sizeof stars);

        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        scanf(" %c",grid[i]+j);
                }
        }

        HitStars();
        if(CheckStar())
        {
                printf("%d\n",(int)Star.size());

                for(int i=0;i<(int)Star.size();i++)
                {
                        printf("%d %d %d\n",Star[i].f,Star[i].s.f,Star[i].s.s);
                }
        }else puts("-1");
}