QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#18668. Meerkat

Statistics

A family of $N$ meerkats lives in a group. During the day, the meerkats come out of their burrow and stand on a one-dimensional coordinate line to keep watch for predators. When standing guard, each meerkat has a fixed position and a direction (either left or right) they are facing; during the watch, they cannot change the direction they are facing.

All meerkats in the family have distinct heights. A meerkat cannot see over the lookout if a taller meerkat is standing in the direction they are facing. Taking pity on them, you can perform the following action arbitrarily without the meerkats noticing:

  • Choose two meerkats facing the same direction and swap their positions.

Determine the maximum number of meerkats that can see over the lookout after performing the above actions appropriately.

Input

The first line contains the number of meerkats $N$. ($3 \leq N \leq 5\,000$)

The next $N$ lines contain information about the meerkats. For all $1 \leq i \leq N$, the $(i+1)$-th line contains an integer $A_i$ representing the height of the meerkat at the $i$-th position from the left, and a character $D_i$ representing the direction it is facing, separated by a space. ($1\leq A_i \leq N$) $D_i$ is given as L for left or R for right.

All values $A_i$ are distinct.

Output

Print the maximum number of meerkats that can see over the lookout.

Examples

Input 1

5
5 L
2 R
3 R
4 R
1 L

Output 1

4

Input 2

7
7 R
1 L
6 R
3 L
5 L
4 R
2 R

Output 2

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.