QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#12609. Fish

Statistics

JOI decided to keep some fish.

He went to a pet shop near his house, where $N$ fish were for sale. The $i$-th fish has a length of $L_i$ cm and a color of either red, green, or blue. JOI decided to keep one or more of these $N$ fish at home.

There is something to be careful about when keeping fish. If you keep a large fish and a small fish together, the large fish will eat the small fish. Specifically, if the length of fish $X$ is at least twice the length of fish $Y$, then $X$ will eat $Y$ if they are kept together. Therefore, such a pair of fish cannot be kept together.

JOI is curious about how many possible combinations of colors of the fish he can keep. Two combinations of colors are considered different if the number of fish of at least one color (red, green, or blue) is different. Given the lengths and colors of the fish sold at the pet shop, he wants to find the number of possible combinations of colors of the fish he can keep.

Task

Given the lengths and colors of the fish sold at the pet shop, write a program that outputs the number of possible combinations of colors of the fish JOI can keep.

Constraints

  • $1 \le N \le 500\,000$
  • $1 \le L_i \le 1\,000\,000\,000$

Input

Read the following from standard input:

  • The first line contains an integer $N$, representing the number of fish sold at the pet shop.
  • The $(1+i)$-th line ($1 \le i \le N$) contains an integer $L_i$ and a character $C_i$ separated by a space. The character $C_i$ is one of 'R', 'G', or 'B'. This indicates that the $i$-th fish has a length of $L_i$ cm, and if $C_i$ is 'R', the color is red; if $C_i$ is 'G', the color is green; and if $C_i$ is 'B', the color is blue.

Output

Output the number of possible combinations of colors of the fish JOI can keep on a single line.

Subtasks

  • 10% of the points are awarded for test cases where $N \le 100$.
  • 30% of the points are awarded for test cases where $N \le 2000$.

Examples

Input 1

4
10 R
4 G
8 B
5 B

Output 1

6

Note 1

The 1st fish eats the 2nd fish, so they cannot be kept together. The same applies to the 1st and 4th fish, and the 2nd and 3rd fish. Therefore, the possible color combinations are: "1 red", "1 green", "1 blue", "1 red and 1 blue", "1 green and 1 blue", and "2 blue", for a total of 6 combinations.

Input 2

10
26 B
10 B
16 G
20 R
6 R
5 G
13 G
40 R
8 R
33 R

Output 2

13

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.