Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from a_{i} to b_{i}. Of course, Famil Door wants to have as many friends celebrating together with him as possible.

Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.

Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.

Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers a_{i} and b_{i} (1 ≤ a_{i} ≤ b_{i} ≤ 366), providing that the i-th friend can come to the party from day a_{i} to day b_{i} inclusive.


-----Output-----

Print the maximum number of people that may come to Famil Door's party.


-----Examples-----
Input
4
M 151 307
F 343 352
F 117 145
M 24 128

Output
2

Input
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200

Output
4



-----Note-----

In the first sample, friends 3 and 4 can come on any day in range [117, 128].

In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.

Difficulty: EASY

Solutions:
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
m = 0
for i in range(1, 367):
	x = min(M[i], F[i])
	if x > m:
		m = x
print(m * 2)


lof = []
mi = 1000
ma = 0
mf = 0

class Bio:

	def __init__(self, c):
		self.gen = c
		self.cal = [False for i in range(368)]

	def setcal(self, mi, ma):
		for i in range(mi, ma + 1):
			self.cal[i] = True

	def getgen(self):
		return self.gen

	def getcal(self):
		return self.cal
n = int(input())
for x in range(n):
	(se, a, b) = input().split()
	a = int(a)
	b = int(b)
	if a < mi:
		mi = a
	if b > ma:
		ma = b
	lof.append(Bio(se))
	lof[x].setcal(a, b)
for j in range(mi, ma + 1):
	cm = 0
	cf = 0
	for i in range(n):
		if lof[i].getcal()[j] and lof[i].getgen() == 'F':
			cf += 1
		elif lof[i].getcal()[j] and lof[i].getgen() == 'M':
			cm += 1
	if cm > cf:
		nof = 2 * cf
	else:
		nof = 2 * cm
	if nof > mf:
		mf = nof
print(mf)


ii = lambda : int(input())
si = lambda : input()
m = [0] * 367
f = [0] * 367
s = [0] * 367
n = ii()
for _ in range(n):
	q = si().split()
	(b, e) = map(int, q[1:])
	if q[0] == 'M':
		for i in range(b, e + 1):
			m[i] += 1
	else:
		for i in range(b, e + 1):
			f[i] += 1
for i in range(367):
	s[i] = min(m[i], f[i])
print(max(s) * 2)


n = int(input())
m = [0 for i in range(366)]
f = [0 for i in range(366)]
for i in range(n):
	(c, a, b) = input().split()
	a = int(a) - 1
	b = int(b) - 1
	if c == 'M':
		for i in range(a, b + 1):
			m[i] += 1
	else:
		for i in range(a, b + 1):
			f[i] += 1
an = 0
for i in range(366):
	an = max(an, min(f[i], m[i]) * 2)
print(an)


n = int(input())
grid = []
for i in range(n):
	tokens = input().split()
	grid.append([tokens[0], int(tokens[1]), int(tokens[2])])
ans = 0
for i in range(366):
	(males, females) = (0, 0)
	for j in range(n):
		if grid[j][1] - 1 <= i <= grid[j][2] - 1:
			if grid[j][0] == 'M':
				males += 1
			else:
				females += 1
	x = 2 * min(males, females)
	if x > ans:
		ans = x
print(ans)


from sys import stdin as fin
n = int(fin.readline())
events = []
for i in range(n):
	inp = fin.readline().split()
	g = inp[0]
	(s, t) = map(int, inp[1:])
	events.append((s - 1, True, g))
	events.append((t, False, g))
events.sort()
days = [[0] * 2 for i in range(367)]
for (i, type, g) in events:
	if type:
		if g == 'M':
			days[i][0] += 1
		else:
			days[i][1] += 1
	elif g == 'M':
		days[i][0] -= 1
	else:
		days[i][1] -= 1
m_bal = f_bal = 0
maxv = 0
for (mc, fc) in days:
	(m_bal, f_bal) = (m_bal + mc, f_bal + fc)
	if min(f_bal, m_bal) * 2 > maxv:
		maxv = min(f_bal, m_bal) * 2
print(maxv)


n = int(input())
F1 = [0] * n
F2 = [0] * n
M1 = [0] * n
M2 = [0] * n
m = 0
f = 0
for i in range(n):
	c = input().split()
	if c[0] == 'M':
		M1[m] = int(c[1])
		M2[m] = int(c[2])
		m = m + 1
	if c[0] == 'F':
		F1[f] = int(c[1])
		F2[f] = int(c[2])
		f = f + 1
F = [0] * 3232
M = [0] * 3266
for i in range(f):
	for j in range(F1[i], F2[i] + 1):
		F[j] = F[j] + 1
for i in range(m):
	for j in range(M1[i], M2[i] + 1):
		M[j] = M[j] + 1
max = 0
for j in range(367):
	if F[j] > max and M[j] > max:
		max = F[j]
		if max > M[j]:
			max = M[j]
print(max * 2)


n = int(input())
events = []
for i in range(n):
	(gender, a, b) = input().split()
	(a, b) = (int(a), int(b))
	events.append((a, -1, gender))
	events.append((b, 1, gender))
events.sort()
currM = 0
currF = 0
ans = 0
for ev in events:
	if ev[2] == 'M':
		currM -= ev[1]
	else:
		currF -= ev[1]
	ans = max(ans, min(currM, currF) * 2)
print(ans)


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())
(male, female) = (366 * [0], 366 * [0])
for j in range(n):
	(gender, l, r) = [str(j) for j in input().split()]
	if gender == 'M':
		for k in range(int(l) - 1, int(r)):
			male[k] += 1
	else:
		for k in range(int(l) - 1, int(r)):
			female[k] += 1
output = 0
for j in range(366):
	v = min(male[j], female[j])
	output = max(v, output)
print(output * 2)


import os
import sys
from atexit import register
from io import BytesIO, StringIO
sys.stdin = StringIO(os.read(0, os.fstat(0).st_size).decode())
sys.stdout = StringIO()
register(lambda : os.write(1, sys.stdout.getvalue().encode()))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())

def main():
	ii = lambda : int(input())
	si = lambda : input()
	m = [0] * 367
	f = [0] * 367
	n = ii()
	for _ in range(n):
		q = si().split()
		(b, e) = map(int, q[1:])
		if q[0] == 'M':
			m[b - 1] += 1
			m[e] -= 1
		else:
			f[b - 1] += 1
			f[e] -= 1
	maxi = m_c = f_c = 0
	for i in range(366):
		m_c += m[i]
		f_c += f[i]
		maxi = max(maxi, min(m_c, f_c))
	print(maxi * 2)
main()


friends = int(input())
(m, f, lil, big) = ([], [], 366, 0)
for x in range(friends):
	inp = input().split(' ')
	(inp[1], inp[2]) = (int(inp[1]), int(inp[2]))
	if inp[0] == 'M':
		m.append((inp[1], inp[2]))
	else:
		f.append((inp[1], inp[2]))
	if inp[1] < lil:
		lil = inp[1]
	if inp[2] > big:
		big = inp[2]
maxattend = 0
for day in range(lil, big + 1):
	(maxm, maxf) = (0, 0)
	for i in m:
		if day >= i[0] and day <= i[1]:
			maxm += 1
	for i in f:
		if day >= i[0] and day <= i[1]:
			maxf += 1
	attend = min(maxm, maxf)
	if attend > maxattend:
		maxattend = attend
print(maxattend * 2)


n = int(input())
num_b = [0 for i in range(366)]
num_g = [0 for i in range(366)]
for i in range(n):
	s = list(input().split())
	if s[0] == 'M':
		for i in range(int(s[1]) - 1, int(s[2])):
			num_b[i] += 1
	else:
		for i in range(int(s[1]) - 1, int(s[2])):
			num_g[i] += 1
for i in range(366):
	num_b[i] = min(num_b[i], num_g[i])
print(2 * max(num_b))


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())
m = [0 for i in range(400)]
f = [0 for i in range(400)]
ppl = []
for i in range(n):
	tmp = input().split()
	tmp[1] = int(tmp[1])
	tmp[2] = int(tmp[2])
	ppl.append(tmp)
ans = 0
for day in range(1, 367):
	for p in ppl:
		(gender, a, b) = p
		if a <= day <= b:
			if gender == 'M':
				m[day] += 1
			else:
				f[day] += 1
	ans = max(ans, min(m[day], f[day]))
print(2 * ans)


n = int(input())
gender = []
fromdate = []
todate = []
for k in range(n):
	(a, b, c) = input().split()
	gender.append(a)
	fromdate.append(int(b))
	todate.append(int(c))
minimum = min(fromdate)
maximum = max(todate)
ans = 0
for i in range(minimum, maximum + 1):
	male = 0
	women = 0
	for j in range(n):
		if fromdate[j] <= i and todate[j] >= i:
			if gender[j] == 'M':
				male += 1
			else:
				women += 1
	count = min(male, women) * 2
	if count > ans:
		ans = count
print(ans)


n = int(input())
sex = []
max_k = 0
aa = []
bb = []
for _ in range(n):
	(s, a, b) = list(input().split())
	sex.append(s)
	aa.append(int(a))
	bb.append(int(b))
for i in range(1, 367):
	f = 0
	m = 0
	for j in range(n):
		if aa[j] <= i <= bb[j]:
			if sex[j] == 'F':
				f += 1
			else:
				m += 1
	max_k = max(max_k, min(f, m) * 2)
print(max_k)


n = int(input())
sex = []
date = []
for i in range(n):
	a = input().split()
	sex.append(a[0])
	date.append(list(map(int, a[1:])))
r = []
for i in range(366):
	r.append([0, 0])
for i in range(1, 367):
	for g in range(n):
		if date[g][0] <= i <= date[g][1]:
			if sex[g] == 'M':
				r[i - 1][0] += 1
			else:
				r[i - 1][1] += 1
a = []
for i in range(366):
	a.append(min(r[i]))
print(max(a) * 2)


def max_party(friends):
	m = [0] * 366
	f = [0] * 366
	for (g, a, b) in friends:
		mf = m if g else f
		for i in range(a, b + 1):
			mf[i - 1] += 1
	mf = list(map(min, zip(m, f)))
	return max(mf) * 2

def get_input():
	n = int(input())
	friends = []
	for _ in range(n):
		(g, a, b) = input().split()
		friends.append((g == 'M', int(a), int(b)))
	return friends
print(max_party(get_input()))


def inp(n):
	if n == 1:
		return map(int, stdin.readline().split())
	elif n == 2:
		return map(float, stdin.readline().split())
	else:
		return map(str, stdin.readline().split())
from sys import *
(arr, n) = ([], int(input()))
for i in range(n):
	(s1, s2, s3) = inp(3)
	arr.append([s1, int(s2), int(s3)])
ans = 0
for i in range(1, 367):
	(male, female) = (0, 0)
	for j in range(n):
		if i >= arr[j][1] and i <= arr[j][2]:
			if arr[j][0] == 'M':
				male += 1
			else:
				female += 1
	ans = max(ans, min(male, female) * 2)
print(ans)


t = int(input())
lst1 = []
lstm = [0] * 367
lstf = [0] * 367
lst2 = []
lst4 = []
count = 0
for k in range(t):
	(x, y, z) = input().split()
	for i in range(int(y), int(z) + 1):
		if x == 'M':
			lstm[i] = lstm[i] + 1
		elif x == 'F':
			lstf[i] = lstf[i] + 1
maxx = 0
for l in range(1, 367):
	num = 2 * min(lstf[l], lstm[l])
	if num >= maxx:
		maxx = num
print(maxx)


from math import *
from sys import *
M = [0] * 367
F = [0] * 367
n = int(stdin.readline())
for i in range(n):
	nn = [z for z in stdin.readline().split()]
	if nn[0] == 'M':
		for j in range(int(nn[1]), int(nn[2]) + 1):
			M[j] += 1
	else:
		for j in range(int(nn[1]), int(nn[2]) + 1):
			F[j] += 1
mx = 0
for i in range(367):
	mx = max(mx, min(M[i], F[i]))
print(2 * mx)


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


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())
p = []
for i in range(n):
	(s, t, j) = input().split()
	t = int(t)
	j = int(j)
	p.append([t, 'a', s])
	p.append([j, 'z', s])
p.sort()
e1 = 0
e2 = 0
maxi = 0
for i in range(2 * n):
	if p[i][1] == 'a' and p[i][2] == 'M':
		e1 += 1
	elif p[i][1] == 'a' and p[i][2] == 'F':
		e2 += 1
	elif p[i][1] == 'z' and p[i][2] == 'M':
		e1 -= 1
	else:
		e2 -= 1
	maxi = max(maxi, min(e1, e2))
print(maxi * 2)


N = int(input())
friends = []
for i in range(N):
	(s, a, b) = input().split()
	friends.append([int(a), False, s])
	friends.append([int(b), True, s])
res = 0
boys = 0
girls = 0
for (a, out, s) in sorted(friends):
	if out:
		if s == 'M':
			boys -= 1
		else:
			girls -= 1
	elif s == 'M':
		boys += 1
	else:
		girls += 1
	res = max(res, 2 * min(boys, girls))
print(res)


n = int(input())
m1 = {}
m2 = {}
for x in range(367):
	m1[x] = 0
for y in range(367):
	m2[y] = 0
for friend in range(n):
	(g, a, b) = input().split()
	for bruh in range(int(a), int(b) + 1):
		if g == 'M':
			m1[bruh] += 1
		elif g == 'F':
			m2[bruh] += 1
attendees = []
for day in range(367):
	attendees.append(min(m1[day], m2[day]))
print(max(attendees) * 2)


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


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)


import collections
import math
n = int(input())
(M, F) = ([], [])
(Ma, Fa) = ([0] * 400, [0] * 400)
for i in range(n):
	t = list(input().split())
	if t[0] == 'M':
		for j in range(int(t[1]), int(t[2]) + 1):
			Ma[j] += 1
		M.append(t)
	else:
		for j in range(int(t[1]), int(t[2]) + 1):
			Fa[j] += 1
		F.append(t)
ans = 0
for i in range(1, 367):
	x = 2 * min(Ma[i], Fa[i])
	if x > ans:
		ans = x
print(ans)


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())
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)


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())
a = [[], []]
c = []
for _ in [0] * n:
	(z, *w) = input().split()
	(x, y) = map(int, w)
	a[z == 'F'] += [(x, y)]
	c += [x, y]
r = 0
for d in range(367):
	x = sum((u <= d <= v for (u, v) in a[0]))
	y = sum((u <= d <= v for (u, v) in a[1]))
	r = max(r, min(x, y))
print(r * 2)


import unittest
import sys

class Relative:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n] = list(map(int, uinput().split()))
		(l, s) = (self.n, 3)
		inp = ' '.join((uinput() for i in range(l))).split()
		self.numm = [[int(inp[i]) if j != 0 else inp[i] == 'M' for i in range(j, l * s, s)] for j in range(s)]
		(self.nums, self.numa, self.numb) = self.numm
		self.dts = []
		for i in range(self.n):
			self.dts.append((self.numa[i], 1, self.nums[i]))
			self.dts.append((self.numb[i] + 1, 0, self.nums[i]))
		self.sdts = sorted(self.dts)
		(mcnt, fcnt) = (0, 0)
		(self.ms, self.fs) = ({}, {})
		for i in range(len(self.sdts)):
			day = self.sdts[i][0]
			if self.sdts[i][2]:
				if self.sdts[i][1]:
					mcnt += 1
				else:
					mcnt -= 1
			elif self.sdts[i][1]:
				fcnt += 1
			else:
				fcnt -= 1
			self.ms[day] = mcnt
			self.fs[day] = fcnt
		self.cr = []
		for d in self.ms:
			self.cr.append(min(self.ms[d], self.fs[d]) * 2)

	def calculate(self):
		result = max(self.cr)
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '4\nM 151 307\nF 343 352\nF 117 145\nM 24 128'
		d = Relative(test)
		self.assertEqual(d.n, 4)
		self.assertEqual(d.numa, [151, 343, 117, 24])
		self.assertEqual(d.nums, [1, 0, 0, 1])
		self.assertEqual(Relative(test).calculate(), '2')
		test = '6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200'
		self.assertEqual(Relative(test).calculate(), '4')
		test = ''
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Relative(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))

def __starting_point():
	sys.setrecursionlimit(100000)
	if sys.argv[-1] == '-ut':
		unittest.main(argv=[' '])
	sys.stdout.write(Relative().calculate())
__starting_point()


n = int(input())
ar = [(0, 0)] * 367
for i in range(n):
	(p, a, b) = [i for i in input().split()]
	a = int(a)
	b = int(b)
	if p == 'M':
		for j in range(a, b + 1):
			ar[j] = (ar[j][0] + 1, ar[j][1])
	else:
		for j in range(a, b + 1):
			ar[j] = (ar[j][0], ar[j][1] + 1)
m = 0
for i in range(1, 367):
	m = max(m, min(ar[i][0], ar[i][1]) * 2)
print(m)


ii = lambda : int(input())
si = lambda : input()
m = [0] * 367
f = [0] * 367
n = ii()
for _ in range(n):
	q = si().split()
	(b, e) = map(int, q[1:])
	if q[0] == 'M':
		m[b - 1] += 1
		m[e] -= 1
	else:
		f[b - 1] += 1
		f[e] -= 1
maxi = m_c = f_c = 0
for i in range(366):
	m_c += m[i]
	f_c += f[i]
	maxi = max(maxi, min(m_c, f_c))
print(maxi * 2)


n = int(input())
ludia = []
for i in range(n):
	s = input().split()
	ludia.append([s[0], int(s[1]), int(s[2])])
maxi = 0
for den in range(1, 367):
	(muzov, zien) = (0, 0)
	for clovek in ludia:
		if clovek[1] <= den <= clovek[2]:
			if clovek[0] == 'M':
				muzov += 1
			elif clovek[0] == 'F':
				zien += 1
			else:
				print('WTF?!')
	parov = min(muzov, zien)
	maxi = max(maxi, parov)
print(maxi * 2)


m = 366 * [0]
f = 366 * [0]
for i in range(int(input())):
	x = list(input().split())
	if x[0] == 'M':
		for j in range(int(x[1]), int(x[2]) + 1):
			m[j - 1] += 1
	else:
		for j in range(int(x[1]), int(x[2]) + 1):
			f[j - 1] += 1
maximum = 0
for k in range(len(m)):
	if min(m[k], f[k]) > maximum:
		maximum = min(m[k], f[k])
print(2 * maximum)


n = int(input())
p = []
for i in range(0, n):
	(sex, odd, doo) = str(input()).split(' ')
	p = p + [(int(odd), 0, sex)] + [(int(doo), 1, sex)]
(male, female, maxy) = (0, 0, 0)
p.sort()
for i in p:
	adding = -1
	if i[1] == 0:
		adding = 1
	if i[2] == 'M':
		male = male + adding
	else:
		female = female + adding
	maxy = max(maxy, 2 * min(male, female))
print(maxy)


n = int(input())
a = [input().split() for i in range(n)]
for i in range(n):
	if a[i][0] == 'M':
		a[i][0] = 0
	else:
		a[i][0] = 1
	a[i][1] = int(a[i][1])
	a[i][2] = int(a[i][2])
ans = 0
for i in range(1, 367):
	tot = [0, 0]
	for j in range(n):
		if a[j][1] <= i <= a[j][2]:
			tot[a[j][0]] += 1
	ans = max(ans, min(tot[0], tot[1]))
print(ans << 1)


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)]))


__author__ = 'Utena'
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])
	if temp > t:
		t = temp
print(t * 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 min(males[i], females[i]) > ans:
		ans = min(males[i], females[i])
print(ans * 2)


n = int(input())
m = []
f = []
rl_m = []
rh_m = []
rl_f = []
rh_f = []
MAX = 0
for i in range(n):
	lst = list(map(str, input().strip().split(' ')))
	if lst[0] == 'M':
		m.append(lst[0])
		rl_m.append(int(lst[1]))
		rh_m.append(int(lst[2]))
	else:
		f.append(lst[0])
		rl_f.append(int(lst[1]))
		rh_f.append(int(lst[2]))
rl_m.append(0)
rh_m.append(0)
rl_f.append(0)
rh_f.append(0)
for i in range(1, max(max(rh_m), max(rh_f)) + 1):
	mc = 0
	fc = 0
	for j in range(len(m)):
		if i >= rl_m[j] and i <= rh_m[j]:
			mc += 1
	for j in range(len(f)):
		if i >= rl_f[j] and i <= rh_f[j]:
			fc += 1
	if MAX <= min(mc, fc):
		MAX = min(mc, fc)
print(MAX * 2)


import heapq
n = int(input())
ll = [tuple(input().split()) for j in range(n)]
(gender, start, end) = zip(*ll)
start = [int(i) for i in start]
end = [int(i) for i in end]
final_ = list(zip(end, start, range(n), gender))
final_.sort(key=lambda x: x[1])
friendheap = []
n_m = 0
n_f = 0
max_friends = 0
for i in final_:
	cur_start = i[1]
	cur_gender = i[3]
	while True:
		if len(friendheap) == 0:
			break
		else:
			elem = heapq.nsmallest(1, friendheap)[0]
			gender = elem[3]
			if elem[0] < cur_start:
				heapq.heappop(friendheap)
				if gender == 'M':
					n_m -= 1
				else:
					n_f -= 1
			else:
				break
	heapq.heappush(friendheap, i)
	if cur_gender == 'M':
		n_m += 1
	else:
		n_f += 1
	max_friends = max(max_friends, min(n_m, n_f))
print(2 * max_friends)


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


def get(n):
	if n == 'M' or n == 'F':
		return n
	else:
		return int(n)
n = int(input())
mylist = [[0] * 367, [0] * 367]
for i in range(n):
	(g, a, b) = map(get, input().split())
	if g == 'M':
		index = 0
	else:
		index = 1
	for i in range(a, b + 1):
		mylist[index][i] += 1
mylist = list(map(list, zip(*mylist)))
mylist.sort(key=lambda x: min(x[0], x[1]), reverse=True)
print(min(mylist[0][0], mylist[0][1]) * 2)


n = int(input())
ls = [list(input().split()) for i in range(n)]
(ma, m, f) = (0, 0, 0)
for i in range(367):
	(m, f) = (0, 0)
	for j in range(n):
		if int(ls[j][1]) <= i and int(ls[j][2]) >= i:
			if ls[j][0] == 'M':
				m += 1
			else:
				f += 1
	ma = max(ma, min(m, f) * 2)
print(ma)


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)


days = [[0, 0] for i in range(367)]
num_friends = int(input())
for i in range(num_friends):
	(gender, starts, ends) = input().split(' ')
	start = int(starts)
	end = int(ends)
	if gender == 'M':
		idx = 0
	else:
		idx = 1
	for i in range(start, end + 1):
		days[i][idx] += 1
print(2 * max((min(pair) for pair in days)))


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)


import time
n = int(input())
bm = {}
em = {}
bf = {}
ef = {}
a = []
for i in range(n):
	(s, b, e) = (i for i in input().split())
	b = int(b)
	e = int(e) + 1
	a.append(b)
	a.append(e)
	if s == 'M':
		if b in bm.keys():
			bm[b] += 1
		else:
			bm[b] = 1
		if e in em.keys():
			em[e] += 1
		else:
			em[e] = 1
	else:
		if b in bf.keys():
			bf[b] += 1
		else:
			bf[b] = 1
		if e in ef.keys():
			ef[e] += 1
		else:
			ef[e] = 1
start = time.time()
a = sorted(list(set(a)))
ans = 0
nf = 0
nm = 0
for i in a:
	if i in bm.keys():
		nm += bm[i]
	if i in em.keys():
		nm -= em[i]
	if i in bf.keys():
		nf += bf[i]
	if i in ef.keys():
		nf -= ef[i]
	t = min(nf, nm)
	if ans < 2 * t:
		ans = 2 * t
print(ans)
finish = time.time()


n = int(input())
boy = [0] * 368
girl = [0] * 368
for _ in range(n):
	(a, b, c) = input().split()
	b = int(b)
	c = int(c)
	if a == 'F':
		girl[b] += 1
		girl[c + 1] -= 1
	else:
		boy[b] += 1
		boy[c + 1] -= 1
for i in range(1, 367):
	girl[i] += girl[i - 1]
	boy[i] += boy[i - 1]
maxi = 0
for i in range(1, 367):
	curr = 2 * min(boy[i], girl[i])
	maxi = max(maxi, curr)
print(maxi)


n = int(input())
arr = [[0 for i in range(n)] for j in range(3)]
endpts = set()
for i in range(n):
	(s, a, b) = [x for x in input().split()]
	a = int(a)
	b = int(b)
	endpts.add(a)
	endpts.add(b)
	arr[0][i] = s
	arr[1][i] = a
	arr[2][i] = b
endpts.add(1)
endpts.add(366)
answer = 0
for check in range(367):
	male = 0
	female = 0
	for i in range(n):
		sex = arr[0][i]
		left = arr[1][i]
		right = arr[2][i]
		if left <= check and check <= right:
			if sex == 'M':
				male += 1
			else:
				female += 1
	smallest = min(male, female)
	if smallest * 2 > answer:
		answer = smallest * 2
print(answer)


n = int(input())
y = []
for i in range(n):
	x = list(input().split())
	y += [[x[0], int(x[1]), int(x[2])]]
ans = 0
for i in range(367):
	m = sum([x[0] == 'M' and x[1] <= i <= x[2] for x in y])
	n = sum([x[0] == 'F' and x[1] <= i <= x[2] for x in y])
	ans = max(ans, min(m, n) * 2)
print(ans)


def main():
	n = int(input())
	amigos = []
	for i in range(n):
		(g, i, f) = input().split()
		i = int(i)
		f = int(f)
		amigos.append([g, i, f])
	maximo = 0
	for dia in range(1, 367):
		(m, h) = (0, 0)
		for i in range(n):
			if amigos[i][1] <= dia and dia <= amigos[i][2]:
				if amigos[i][0] == 'F':
					m += 1
				else:
					h += 1
		quantos = 2 * min(m, h)
		if quantos > maximo:
			maximo = quantos
	print(maximo)
main()


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())
m = [0] * 367
f = [0] * 367
for i in range(n):
	(a, x, y) = input().split()
	x = int(x)
	y = int(y)
	if a == 'M':
		for j in range(x, y + 1):
			m[j] += 1
	if a == 'F':
		for k in range(x, y + 1):
			f[k] += 1
ans = 0
for i in range(len(m)):
	ans = max(ans, min(f[i], m[i]))
print(2 * ans)


n = int(input())
females = [0] * 366
males = [0] * 366
for _ in range(n):
	(p, start, end) = input().split()
	start = int(start) - 1
	end = int(end)
	if p == 'F':
		females[start] += 1
		if end < 366:
			females[end] -= 1
	elif p == 'M':
		males[start] += 1
		if end < 366:
			males[end] -= 1
cur_m_count = 0
cur_f_count = 0
max_count = 0
for day in range(366):
	cur_m_count += males[day]
	cur_f_count += females[day]
	max_count = max(max_count, 2 * min(cur_f_count, cur_m_count))
print(max_count)


male = [0] * 368
female = [0] * 368
n = int(input())
for i in range(n):
	(s, a, b) = map(str, input().split())
	a = int(a)
	b = int(b)
	if s == 'M':
		male[a] += 1
		male[b + 1] -= 1
	if s == 'F':
		female[a] += 1
		female[b + 1] -= 1
male_sum = [0] * 368
female_sum = [0] * 368
pair = [0] * 368
for j in range(1, 368):
	male_sum[j] = male_sum[j - 1] + male[j]
	female_sum[j] = female_sum[j - 1] + female[j]
	pair[j] = min(male_sum[j], female_sum[j])
print(max(pair) * 2)


F = [0] * 367
M = [0] * 367
t = int(input())
for u in range(t):
	(a, b, c) = input().split()
	(b, c) = (int(b), int(c))
	if a == 'F':
		for _ in range(b, c + 1):
			F[_] += 1
	else:
		for _ in range(b, c + 1):
			M[_] += 1
ans = 0
for i in range(1, 367):
	tmp = min(F[i], M[i])
	ans = max(ans, tmp)
print(ans * 2)


def main():
	n = int(input())
	(ss, xs, ys) = ([], [], [])
	for _ in range(n):
		(s, x, y) = input().split()
		ss.append(s)
		xs.append(int(x))
		ys.append(int(y))
	res = 0
	for d in range(min(xs), max(ys) + 1):
		(f, m) = (0, 0)
		for i in range(n):
			(s, x, y) = (ss[i], xs[i], ys[i])
			if x <= d <= y:
				if s == 'M':
					m += 1
				else:
					f += 1
		res = max(res, min(f, m))
	print(res * 2)
main()


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())
M = [list(map(str, input().split())) for i in range(n)]
l = [[0, 0] for i in range(400)]
for i in range(n):
	for j in range(int(M[i][1]), int(M[i][2]) + 1):
		if M[i][0] == 'F':
			l[j][0] = l[j][0] + 1
		else:
			l[j][1] = l[j][1] + 1
ma = 0
for i in range(400):
	ma = max(ma, min(l[i]))
print(ma * 2)


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]
	elif m[i] > ans:
		ans = m[i]
print(ans * 2)


def s():
	n = int(input())
	f = [[0, 0] for _ in range(368)]
	for _ in range(n):
		[g, a, b] = input().split(' ')
		g = g == 'M'
		a = int(a)
		b = int(b) + 1
		f[a][g] += 1
		f[b][g] -= 1
	r = 0
	t = [0, 0]
	for i in f:
		t[0] += i[0]
		t[1] += i[1]
		r = max(r, min(t))
	print(2 * r)
s()


n = int(input())
rows = []
for _ in range(n):
	(g, s, e) = input().split()
	rows.append((g, int(s), int(e)))
best = 0
for i in range(1, 367):
	m = f = 0
	for row in rows:
		(g, s, e) = row
		if g == 'M':
			m += 1 if s <= i and i <= e else 0
		else:
			f += 1 if s <= i and i <= e else 0
	best = max(min(m, f), best)
print(best * 2)


n = int(input())
M = [0 for i in range(366)]
F = [0 for i in range(366)]
while n > 0:
	n -= 1
	(G, a, b) = input().split()
	if G == 'M':
		for i in range(int(a) - 1, int(b)):
			M[i] += 1
	else:
		for i in range(int(a) - 1, int(b)):
			F[i] += 1
mx = 0
for i in range(366):
	mx = max(mx, min(M[i], F[i]))
print(mx * 2)


from sys import stdin
input = stdin.readline
n = int(input())
a = []
for _ in range(n):
	k = list(input().split())
	a.append(k)
b = [0] * 366
for i in range(366):
	(m, f, l, k) = (0, 0, 0, 0)
	for j in a:
		if j[0] == 'M':
			if i + 1 >= int(j[1]) and i + 1 <= int(j[2]):
				l += 1
		if j[0] == 'F':
			if i + 1 >= int(j[1]) and i + 1 <= int(j[2]):
				k += 1
	b[i] = min(l, k) * 2
print(max(b))


lst = [[0, 0] for i in range(366)]
for i in range(int(input())):
	x = input().split()
	if x[0] == 'M':
		for i in range(int(x[1]) - 1, int(x[2])):
			lst[i][0] += 1
	else:
		for i in range(int(x[1]) - 1, int(x[2])):
			lst[i][1] += 1
ans = 0
for i in lst:
	ans = max(ans, min(i) * 2)
print(ans)


year_m = [0] * 366
year_f = [0] * 366
n = int(input())
for i in range(n):
	(gender, f, l) = input().split()
	(f, l) = (int(f), int(l))
	for j in range(f - 1, l):
		if gender == 'M':
			year_m[j] += 1
		else:
			year_f[j] += 1
m = 0
for i in range(366):
	m = max(m, min(year_m[i], year_f[i]) * 2)
print(m)


n = int(input())
d = {'M': [0] * 366, 'F': [0] * 366}
for i in range(n):
	a = input().split()
	for i in range(int(a[1]) - 1, int(a[2])):
		d[a[0]][i] += 1
max_p = 0
for (i, p) in enumerate(d['M']):
	if min(p, d['F'][i]) > max_p:
		max_p = min(p, d['F'][i])
print(2 * max_p)


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))))


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 = []
females = []
for i in range(n):
	(sex, start, end) = input().split()
	if sex == 'M':
		males.append((int(start), int(end)))
	else:
		females.append((int(start), int(end)))
days_males = [0] * 367
days_females = [0] * 367
for i in range(1, 367):
	for j in range(len(males)):
		if i <= males[j][1] and i >= males[j][0]:
			days_males[i] += 1
	for j in range(len(females)):
		if i <= females[j][1] and i >= females[j][0]:
			days_females[i] += 1
maxd = 0
for i in range(1, 367):
	if 2 * min(days_males[i], days_females[i]) > maxd:
		maxd = 2 * min(days_males[i], days_females[i])
print(maxd)


read = lambda : list(map(int, input().split()))
n = int(input())
p = [list() for i in range(367)]
for i in range(n):
	(s, a, b) = input().split()
	(a, b) = list(map(int, (a, b)))
	p[a].append((1, s))
	p[b].append((-1, s))
cntm = cntf = cur = ans = 0
for i in range(1, 367):
	for (t, s) in p[i]:
		if t == 1:
			if s == 'M':
				cntm += 1
			else:
				cntf += 1
	cur = min(cntf, cntm)
	ans = max(ans, cur)
	for (t, s) in p[i]:
		if t == -1:
			if s == 'M':
				cntm -= 1
			else:
				cntf -= 1
print(ans * 2)


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)


M = [0] * 368
W = [0] * 368
for _ in range(int(input())):
	(sex, *X) = input().split()
	(a, b) = map(int, X)
	if sex == 'F':
		W[a] += 2
		W[b + 1] -= 2
	else:
		M[a] += 2
		M[b + 1] -= 2
k = x = y = 0
for (m, w) in zip(M, W):
	x += m
	y += w
	k = max(k, min(x, y))
print(k)


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())
(f, m) = ([0] * 368, [0] * 368)
for i in range(n):
	(s, a, b) = input().split()
	if s == 'F':
		f[int(a)] += 1
		f[int(b) + 1] -= 1
	elif s == 'M':
		m[int(a)] += 1
		m[int(b) + 1] -= 1
for i in range(1, len(f)):
	f[i] += f[i - 1]
	m[i] += m[i - 1]
print(max([min(f[i], m[i]) * 2 for i in range(1, 367)]))


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())
(male, female) = ([0] * 367, [0] * 367)
for _ in range(n):
	(g, s, f) = input().split()
	l = male if g == 'M' else female
	for i in range(int(s), int(f) + 1):
		l[i] += 1
print(2 * max((min(x, y) for (x, y) in zip(male, female))))


from collections import defaultdict
n = int(input())
people = defaultdict(list)
ans = -1
while n:
	n -= 1
	(a, b, c) = input().split()
	for i in range(int(b), int(c) + 1):
		people[i].append(a)
for pair in people.values():
	m = pair.count('M')
	f = pair.count('F')
	if min(m, f) > ans:
		ans = min(m, f)
print(ans * 2)


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())
f = []
m = []
for i in range(n):
	(g, a, b) = input().split()
	if g == 'F':
		f.append([int(a), int(b)])
	else:
		m.append([int(a), int(b)])
maxi = 0
for i in range(1, 367):
	mw = 0
	mm = 0
	for j in range(len(f)):
		if f[j][0] <= i <= f[j][1]:
			mw += 1
	for j in range(len(m)):
		if m[j][0] <= i <= m[j][1]:
			mm += 1
	maxi = max(maxi, min(mw, mm))
print(maxi * 2)


n = int(input())
days = [[0, 0] for i in range(366)]
for i in range(n):
	str_input = list(input().split())
	row = 0
	if str_input[0][0] == 'M':
		row = 1
	for j in range(int(str_input[1]) - 1, int(str_input[2])):
		days[j][row] += 1
cnt_guests = 0
for i in range(366):
	cnt_guests = max(cnt_guests, min(days[i][0], days[i][1]) * 2)
print(cnt_guests)


class friends:

	def __init__(self, gender, start, end):
		self.gender = gender
		self.start = start
		self.end = end
n = int(input())
obj = []
for _ in range(n):
	(gender, start, end) = input().split()
	obj.append(friends(gender, int(start), int(end)))
obj.sort(key=lambda x: x.start)
invit = []
m = [0] * 367
f = [0] * 367
for i in obj:
	for j in range(i.start, i.end + 1):
		if i.gender == 'M':
			m[j] += 1
		elif i.gender == 'F':
			f[j] += 1
maxx = 0
for i in range(367):
	num = 2 * min(m[i], f[i])
	maxx = num if num > maxx else maxx
print(maxx)


import re
n = int(input())
list = [[0, 0] for i in range(367)]
for i in range(n):
	s = input()
	lis = re.split('[\\s]', s)
	ch = lis[0]
	a = int(lis[1])
	b = int(lis[2])
	for j in range(b - a + 1):
		if ch == 'M':
			list[j + a][0] += 1
		else:
			list[j + a][1] += 1
for c in list:
	if c[0] >= c[1]:
		c[0] = c[1]
	else:
		c[1] = c[0]
sum = 0
for c in list:
	if c[0] + c[1] > sum:
		sum = c[0] + c[1]
print(sum)


import os
import math
import time
f = [0] * 367
m = [0] * 367
n = int(input())
me = []
we = []
for i in range(n):
	s = input().split(' ')
	[x, y] = [int(x) for x in s[1:]]
	if s[0] == 'M':
		me.append([x, y])
		for j in range(x, y + 1):
			m[j] += 1
	else:
		we.append([x, y])
		for j in range(x, y + 1):
			f[j] += 1
for i in range(1, len(m)):
	mi = min(f[i], m[i])
	f[i] = mi
	m[i] = mi
ma = 0
for i in range(1, len(m)):
	if m[i] == f[i]:
		ma = max(ma, m[i] + f[i])
print(ma)


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()
	ends = []
	for i in range(n):
		line = reader.read_strings()
		(gen, f, t) = (line[0], int(line[1]), int(line[2]))
		ends.append((f, gen, 'f'))
		ends.append((t, gen, 't'))
	ends.sort(key=op.itemgetter(0, 2))
	females = 0
	males = 0
	max_sim = 0
	for end in ends:
		(x, gen, t) = end
		if t == 'f':
			females += gen == 'F'
			males += gen == 'M'
		else:
			females -= gen == 'F'
			males -= gen == 'M'
		ppl = min(females, males)
		max_sim = max(max_sim, ppl)
	print(max_sim * 2)
main()


n = int(input())
gender = []
days = []
for i in range(n):
	L = input().split()
	(g, a, b) = (L[0], int(L[1]), int(L[2]))
	gender.append(g)
	days.append([a, b])
Total = 0
for i in range(1, 367):
	Men = 0
	Fem = 0
	for j in range(n):
		if days[j][0] <= i and i <= days[j][1]:
			if gender[j] == 'F':
				Fem += 1
			else:
				Men += 1
	Total = max(Total, min(Men, Fem) * 2)
print(Total)


l = [[0, 0] for i in range(366)]
n = int(input())
for u in range(n):
	x = input().split()
	if x[0] == 'M':
		for i in range(int(x[1]) - 1, int(x[2])):
			l[i][0] += 1
	else:
		for i in range(int(x[1]) - 1, int(x[2])):
			l[i][1] += 1
s = 0
for i in l:
	s = max(s, min(i) * 2)
print(s)


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)
main()


n = int(input())
o = {'M': [0 for i in range(367)], 'F': [0 for i in range(367)]}
for i in range(n):
	(g, s, e) = input().split(' ')
	(s, e) = (int(s), int(e))
	for x in range(s, e + 1):
		o[g][x] += 1
e = [2 * min(o['M'][i], o['F'][i]) for i in range(0, 367)]
print(max(e))


n = int(input())
s = []
for i in range(0, n):
	(g, a, b) = input().split()
	a = int(a)
	b = int(b)
	s.append([g, a, b])
ans = 0
for i in range(1, 367):
	m = 0
	f = 0
	for o in range(0, n):
		if s[o][1] <= i and s[o][2] >= i:
			if s[o][0] == 'M':
				m += 1
			else:
				f += 1
		ans = max(ans, 2 * min(m, f))
print(ans)


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))


__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()


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
	elif item[0] == 'F':
		Fcnt -= 1
	else:
		Mcnt -= 1
	ans = max(ans, min(Mcnt, Fcnt))
print(ans * 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 + 1 <= int(l[j][2]):
				yearm[i] += 1
		elif 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())
a = [0 for i in range(368)]
b = [0 for i in range(368)]
for i in range(n):
	s = input().split()
	if s[0] == 'M':
		a[int(s[1])] += 1
		a[int(s[2]) + 1] -= 1
	else:
		b[int(s[1])] += 1
		b[int(s[2]) + 1] -= 1
ans = 0
for i in range(1, 367):
	a[i] += a[i - 1]
	b[i] += b[i - 1]
	ans = max(ans, min(a[i], b[i]))
print(ans << 1)


n = int(input())
days = [[0, 0] for i in range(370)]
for i in range(n):
	(gender, a, b) = input().split(' ')
	(a, b) = map(int, (a, b))
	if gender == 'M':
		gender = 0
	else:
		gender = 1
	for j in range(a, b + 1):
		days[j][gender] += 1
ans = max((min(day) for day in days))
print(ans * 2)


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)


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


M = [0 for i in range(367)]
F = [0 for i in range(367)]
n = int(input())
for _ in range(n):
	(g, n1, n2) = input().split()
	b = int(n1)
	c = int(n2)
	for j in range(b, c + 1):
		if g == 'M':
			M[j] += 1
		else:
			F[j] += 1
k = 0
for i in range(367):
	m = min(M[i], F[i])
	if m > k:
		k = m
print(k * 2)


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]))))


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)


arrMa = [0] * 367
arrFe = [0] * 367
p = int(input())
for i in range(p):
	inf = list(map(str, input().split()))
	if inf[0] == 'M':
		arrMa[int(inf[1]) - 1] += 1
		arrMa[int(inf[2])] -= 1
	else:
		arrFe[int(inf[1]) - 1] += 1
		arrFe[int(inf[2])] -= 1
maxi = -1
curM = 0
curF = 0
for i in range(366):
	curM += arrMa[i]
	curF += arrFe[i]
	if min(curM, curF) > maxi:
		maxi = min(curM, curF)
print(maxi * 2)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
(Male, Female) = ([], [])
days = [[0, 0] for _ in range(366)]
for _ in range(iinput()):
	(a, b, c) = map(str, input().split())
	if a == 'M':
		for i in range(int(b) - 1, int(c)):
			days[i][0] += 1
	else:
		for i in range(int(b) - 1, int(c)):
			days[i][1] += 1
answer = -1
for j in days:
	answer = max(answer, min(j) * 2)
print(answer)


N = 400
m = [0] * N
f = [0] * N
for _ in ' ' * int(input()):
	(a, b, c) = input().split()
	b = int(b)
	c = int(c) + 1
	if a == 'F':
		f[b] += 2
		f[c] -= 2
	else:
		m[b] += 2
		m[c] -= 2
(a, b) = (0, 0)
o = 0
for i in range(N):
	a += m[i]
	b += f[i]
	o = max(o, min(a, b))
print(o)


n = int(input())
counts = {'M': [0] * 366, 'F': [0] * 366}
for _ in range(n):
	(gender, start, end) = input().split()
	(start, end) = map(int, (start, end))
	for i in range(start - 1, end):
		counts[gender][i] += 1
print(2 * max(map(min, *counts.values())))


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())
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)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = [0] * 367
brr = arr[:]
for i in range(n):
	(g, a, b) = ip().split()
	a = int(a)
	b = int(b)
	if g == 'M':
		for i in range(a, b + 1):
			arr[i] += 1
	else:
		for i in range(a, b + 1):
			brr[i] += 1
print(2 * max([min(i, j) for (i, j) in zip(arr, brr)]))


n = int(input())
l = []
for i in range(n):
	(a, b, c) = map(str, input().split())
	b = int(b)
	c = int(c)
	l.append([a, b, c])
ans = 0
for i in range(1, 367):
	p = q = 0
	for j in range(n):
		(x, y, z) = l[j]
		if y <= i <= z:
			if x == 'M':
				p += 1
			else:
				q += 1
	ans = max(ans, 2 * min(p, q))
print(ans)


n = int(input())
m = [0] * 366
f = [0] * 366
res = 0
for i in range(n):
	(x, l, r) = [i for i in input().split()]
	l = int(l)
	r = int(r)
	if x == 'M':
		for j in range(l - 1, r):
			m[j] += 1
	else:
		for j in range(l - 1, r):
			f[j] += 1
for i in range(366):
	res = max(res, min(m[i], f[i]))
print(res * 2)


n = int(input())
f = [0 for x in range(0, 367)]
m = [0 for x in range(0, 367)]
for i in range(0, n):
	[g, r, l] = input().split()
	if g == 'F':
		for x in range(int(r), int(l) + 1):
			f[x] += 1
	else:
		for x in range(int(r), int(l) + 1):
			m[x] += 1
c = 0
for i in range(0, 367):
	c = max(c, 2 * min(m[i], f[i]))
print(c)


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)
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]))
doors_party.check_all_days()
print(max(doors_party.number_of_available_guests_on_day))


IL = lambda : list(map(int, input().split()))
IS = lambda : input().split()
I = lambda : int(input())
S = lambda : input()
n = I()
avail = [[0, 0] for i in range(367)]
for i in range(n):
	(t, a, b) = IS()
	(a, b) = map(int, [a, b])
	t = t == 'M'
	for j in range(a, b + 1):
		avail[j][t] += 1
print(max(map(min, avail)) * 2)


def prog():
	n = int(input())
	god = [[0, 0] for i in range(366)]
	from sys import stdin
	for i in range(n):
		q = stdin.readline()
		(a, b, c) = (q.split()[0], q.split()[1], q.split()[2])
		(b, c) = (int(b), int(c))
		for i in range(b - 1, c):
			if a == 'M':
				god[i][0] += 1
			else:
				god[i][1] += 1
	rez = 0
	for (i, x) in enumerate(god):
		if rez < min(x):
			rez = min(x)
	print(2 * rez)
prog()


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)


def main():
	n = int(input())
	mf = ([0] * 367, [0] * 367)
	for _ in range(n):
		tmp = input().split()
		l = mf[tmp[0] == 'F']
		l[int(tmp[1]) - 1] += 1
		l[int(tmp[2])] -= 1
	res = []
	m = f = 0
	for (a, b) in zip(*mf):
		m += a
		f += b
		res.append(m if m < f else f)
	print(max(res) * 2)
main()


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)


def solve():
	n = int(input())
	m = [[] for _ in range(n)]
	for i in range(n):
		(s, a, b) = input().split()
		a = int(a)
		b = int(b)
		m[i].extend([0] * a)
		if s == 'M':
			m[i].extend([1] * (b - a + 1))
		elif s == 'F':
			m[i].extend([2] * (b - a + 1))
		m[i].extend([0] * (366 - b))
	ans = [0] * 367
	for day in range(367):
		nf = 0
		nm = 0
		for i in m:
			if i[day] == 1:
				nm += 1
			elif i[day] == 2:
				nf += 1
		ans[day] = min([nf, nm]) * 2
	return max(ans)
ans = solve()
print(ans)


n = int(input())
male = [0] * 400
female = [0] * 400
for _ in range(n):
	s = input().split()
	a = int(s[1])
	b = int(s[2])
	if s[0] == 'M':
		male[a] += 1
		male[b + 1] -= 1
	else:
		female[a] += 1
		female[b + 1] -= 1
ans = 0
t1 = 0
t2 = 0
for i in range(400):
	t1 += male[i]
	t2 += female[i]
	ans = max(ans, min(t1, t2) * 2)
print(ans)