P24975 [AtCoder] [ARC041C] Rabbit Jump
提高-
题目描述

Problem Description

There are $ L $ squares arranged in a row. On these squares, there are $ N $ rabbits. The $ i $ ($1 \leq i \leq N$) th rabbit is on the $ x_i $ th square from the left. It is guaranteed that $1 \leq x_1 < x_2 < .. < x_N \leq L$. Each rabbit is facing either left or right.

Each rabbit can jump to the square immediately in front of it if that square exists and is unoccupied by another rabbit.

Determine the maximum total number of jumps when the order of jumps can be chosen freely.

Input Format

The input is given from the standard input in the following format:

$ N $ $ L $ $ x_1 $ $ d_1 $ $ x_2 $ $ d_2 $ : $ x_N $ $ d_N $

  • The first line contains the number of rabbits $ N $ ($1 \leq N \leq 10^5$) and the number of squares $ L $ ($N \leq L \leq 10^9$) separated by a space.
  • The next $ N $ lines contain information about the rabbits. The $ i $ th line contains the position $ x_i $ and direction $ d_i $ of the $ i $ th rabbit separated by a space. $ d_i $ is either L (left) or R (right).
  • It is guaranteed that $1 \leq x_1 < x_2 < .. < x_N \leq L$.

Output Format

Output the maximum total number of jumps on a single line. End the output with a newline.

Sample Input and Output

Sample Input #1

1 5
1 R

Sample Output #1

4

Sample Input #2

4 5
1 R
3 L
4 L
5 L

Sample Output #2

3

Sample Input #3

4 10
1 L
5 R
6 L
10 R

Sample Output #3

0

Notes/Hints

Sample Explanation 1

Jumps can be made as shown in the figure.

Sample Explanation 2

Jumps can be made as shown in the figure.

Sample Explanation 3

No rabbit can jump.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 5 1 R
样例输出
4