Description

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 ai to bi. 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 ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.

Output

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

Sample Input

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

Hint

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.

 #include<cstdio>
int wom[],man[],n,max= ,x,y;
char c;
int main()
{
scanf("%d",&n);
for(int i = ;i<n;i++)
{
scanf("%s %d %d",&c,&x,&y);
if(c == 'M')
{
for(int i = x;i<=y;i++)
{
man[i]++;
}
}
else
{
for(int i = x;i<=y;i++)
{
wom[i]++;
}
}
}
for(int i = ;i<=;i++)
{
if(max < (wom[i]<man[i]?wom[i]:man[i])*)
{
max = *(wom[i]<man[i]?wom[i]:man[i]);
}
}
printf("%d\n",max);
}

Far Relative’s Problem (贪心 计算来的最多客人)的更多相关文章

  1. codeforces 629BFar Relative’s Problem

    B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力

    B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Do ...

  3. Codeforces 629 B. Far Relative’s Problem

      B. Far Relative’s Problem   time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  4. Codeforces--629B--Far Relative’s Problem(模拟)

    Far Relative's Problem Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I ...

  5. 计算"aabbc"中最多的相同字母数

    package Test; import java.util.HashMap; import java.util.Map; public class test3 { /** * 计算"aab ...

  6. an easy problem(贪心)

    An Easy Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8333   Accepted: 4986 D ...

  7. CF #296 (Div. 1) B. Clique Problem 贪心(构造)

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. codeforces 442B B. Andrey and Problem(贪心)

    题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. hdu----(5055)Bob and math problem(贪心)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. eurekaclient向eurekaserver注册使用真实ip设置

    有时候eureka.instance.prefer-ip-address=true不管用,解决办法如下.

  2. 从零开始通过idea插件将一个spring boot项目部署到docker容器里运行

    实操:将一个spring boot项目部署到docker容器里运行 实验需要的环境: 腾讯云+Ubuntu 16.04 x64+idea+插件docker integration+daocloud 第 ...

  3. IEEE Trans 2006 使用K-SVD构造超完备字典以进行稀疏表示(稀疏分解)

    K-SVD可以看做K-means的一种泛化形式,K-means算法总每个信号量只能用一个原子来近似表示,而K-SVD中每个信号是用多个原子的线性组合来表示的.    K-SVD算法总体来说可以分成两步 ...

  4. 数据结构 - 链栈的实行(C语言)

    数据结构-链栈的实现 1 链栈的定义 现在来看看栈的链式存储结构,简称为链栈. 想想看栈只是栈顶来做插入和删除操作,栈顶放在链表的头部还是尾部呢?由于单链表有头指针,而栈顶指针也是必须的,那干吗不让它 ...

  5. Android偏好设置(5)偏好设置界面显示多个分组,每个分组也有一个界面

    1.Using Preference Headers In rare cases, you might want to design your settings such that the first ...

  6. Polynomial Division 数学题

    https://www.hackerrank.com/contests/101hack45/challenges/polynomial-division 询问一个多项式能否整除一个一次函数.a * x ...

  7. 如何成为一名优秀的 iOS 开发工程师

    如果你是一位专业的iOS开发工程师,你应该为自己感到自豪.因为你能在强大的iOS系统下,一展身手实现自己和他人的想法,这是一件令人无比激动的事情. 作为一名iOS开发工程师,你一定想成为行业的佼佼者. ...

  8. Discrete Logging

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5865   Accepted: 2618 ...

  9. android环境搭建环境 cordova run android gradle wrapper报错

    cordova run android命令报错 Error: Could not find an installed version of Gradle either in Android Studi ...

  10. git --删除文件、重命名

    修改最后一次提交 git commit --amend -m “” 删除文件:. git rm <需要删除的文件> 只是删除当前工作目录和暂存区的文件,也就是取消跟踪.在下次提交时不纳入版 ...