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. python服务之flask

    前言: 关于python flask 的介绍.指导.案例,网络上比比皆是.这里参考官网:http://www.pythondoc.com/flask/index.html 你可能不知道的flask服务 ...

  2. [POI2009]Tab

    Description 2个n\(\times\)m矩阵,保证同一个矩阵中元素两两不同.问能否通过若干次交换两行或交换两列把第一个矩阵变成第二个. Input 第一行正整数T(1≤T≤10)表示数据组 ...

  3. [POI2008]激光发射器SZK

    Description 多边形相邻边垂直,边长为整数,边平行坐标轴.要在多边形的点上放一些激光发射器和接收器.满足下列要求: 1发射器和接收器不能放置在同一点: 2发射器发出激光可以沿壁反射,最终到达 ...

  4. [ZOJ1610]Count the Colors

    Description 画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了. 你的任务就是要数出你随后能看到的不同颜色的段的数目. Input 每组测试数据第一行只有一个整数n, 1 < ...

  5. _bzoj1059 [ZJOI2007]矩阵游戏【二分图匹配】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1059 保存匈牙利模板. #include <cstdio> #include & ...

  6. COT2 - Count on a tree II(树上莫队)

    COT2 - Count on a tree II You are given a tree with N nodes. The tree nodes are numbered from 1 to N ...

  7. hihoOffer收割练习20题目2

    题目2 : SCI表示法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 每一个正整数 N 都能表示成若干个连续正整数的和,例如10可以表示成1+2+3+4,15可以表示 ...

  8. python的des和3des加解密

    1.加密: pyDes.des(key, [mode], [IV], [pad], [padmode]) pyDes.triple_des(key, [mode], [IV], [pad], [pad ...

  9. Wamp搭建的服务器登录的时候出现Access denied for user 'hello'@'localhost' (using password: YES)

    想用自己电脑做一个服务器,然后就选择了Wamp,本来一切顺利,可是到登录的时候却出现了问题,出现了 Access denied for user 'hello'@'localhost' (using ...

  10. Spring data jpa中Query和@Query分别返回map结果集

    引用: http://blog.csdn.net/yingxiake/article/details/51016234 http://blog.csdn.net/yingxiake/article/d ...