#P8267. Minimum Lying Cows

    ID: 21446 Type: Default 1000ms 256MiB

Minimum Lying Cows

Minimum Lying Cows

Bessie the cow is hiding somewhere on the number line. Farmer John's N cows (where 1 \le N \le 1000) each make a statement regarding Bessie's hiding spot. The i-th cow gives one of two types of statements:

  • L: "Bessie is hiding at a position less than or equal to pi".
  • G: "Bessie is hiding at a position greater than or equal to pi".

Here, 0 \le pi \le 10^9. Unfortunately, it may be impossible for all statements to be simultaneously true, implying that some cows are lying. Your task is to determine the minimum number of cows that must be lying so that there exists at least one position on the number line which satisfies all the non-lying cows' statements.

Hint: You may consider only a small set of candidate positions (such as each pi and pi - 1 when nonnegative) to determine the optimal solution.

inputFormat

The first line contains a single integer N representing the number of cows.

Each of the following N lines contains a character and an integer separated by a space. The character is either L (indicating the statement "Bessie is hiding at or below p") or G (indicating the statement "Bessie is hiding at or above p").

Example:

3
L 5
G 7
L 6

outputFormat

Output a single integer: the minimum number of cows that must be lying in order for there to exist a valid hiding position for Bessie.

sample

2
L 10
G 10
0

</p>