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*<sub class="lower-index">*i*</sub> to *b*<sub class="lower-index">*i*</sub>. 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.
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*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ *b*<sub class="lower-index">*i*</sub> ≤ 366), providing that the *i*-th friend can come to the party from day *a*<sub class="lower-index">*i*</sub> to day *b*<sub class="lower-index">*i*</sub> inclusive.
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.
4
M 151 307
F 343 352
F 117 145
M 24 128
2
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200
4
1
F 68 307
0
40
M 55 363
F 117 252
M 157 282
F 322 345
M 330 363
F 154 231
F 216 352
F 357 365
M 279 292
F 353 359
F 82 183
M 78 297
M 231 314
M 107 264
F 34 318
M 44 244
F 42 339
M 253 307
M 128 192
F 119 328
M 135 249
F 303 358
F 348 352
F 8 364
F 126 303
M 226 346
F 110 300
F 47 303
F 201 311
F 287 288
M 270 352
M 227 351
F 8 111
F 39 229
M 163 315
F 269 335
F 147 351
F 96 143
M 97 99
M 177 295
22
2
F 1 1
M 1 1
2
4
M 1 2
M 2 3
F 3 4
F 4 5
2
1
F 1 2
0
18
F 3 4
F 3 4
F 3 4
F 3 4
F 5 6
F 5 6
M 3 4
M 3 4
M 5 6
M 5 6
M 5 6
M 5 6
F 7 8
F 7 8
F 7 8
M 7 8
M 7 8
M 7 8
6
2
M 1 1
F 1 1
2
3
M 1 1
F 1 1
M 1 1
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 (days_males[i] == days_females[i] and
        days_males[i] + days_females[i] > maxd):
        maxd = days_males[i] + days_females[i]
print(maxd)
