Codeforces Round 343 (Div. 2)
B
Far Relative’s Problem
Codeforces
1100
原题
← AC →
翻译中…

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.

翻译中…

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$.

翻译中…

样例

Input #1
4
M 151 307
F 343 352
F 117 145
M 24 128
Output #1
2
InputCopy OutputCopy
Input #2
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200
Output #2
4
InputCopy OutputCopy
题目信息
题号
629B
时间限制
2 s
内存限制
256 MB
标签
暴力

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。