#abc369b. B - Piano 3
B - Piano 3
Score : points
问题陈述
高桥有一架钢琴,排列着 个键。从左边数第 个键被称为键 i
。
他将通过依次按下 个键来演奏音乐。对于第 次按下,他将按下键 ,如果 等于 L
,则使用左手,如果 等于 R
,则使用右手。
在开始演奏之前,他可以将双手放在任何他喜欢的键上,此时他的疲劳度为 。在演奏过程中,如果他将一只手从键x移动到键y,疲劳度将增加 (相反,除了移动手之外,疲劳度不会因任何原因增加)。要用手按下某个键,那只手必须放在那个键上。
找出演奏结束时可能的最小疲劳度。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Takahashi has a piano with keys arranged in a row. The -th key from the left is called key .
He will play music by pressing keys one by one. For the -th press, he will press key , using his left hand if L
, and his right hand if R
.
Before starting to play, he can place both of his hands on any keys he likes, and his fatigue level at this point is 0. During the performance, if he moves one hand from key to key , the fatigue level increases by (conversely, the fatigue level does not increase for any reason other than moving hands). To press a certain key with a hand, that hand must be placed on that key.
Find the minimum possible fatigue level at the end of the performance.
Constraints
- and are integers.
- is
L
orR
.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum fatigue level at the end of the performance.
Sample Input 1
4
3 L
6 R
9 L
1 R
Sample Output 1
11
For example, the performance can be done as follows:
- Initially, place the left hand on key and the right hand on key .
- Press key with the left hand.
- Press key with the right hand.
- Move the left hand from key to key . The fatigue level increases by .
- Move the right hand from key to key . The fatigue level increases by .
- Press key with the left hand.
- Press key with the right hand.
In this case, the fatigue level at the end of the performance is , which is the minimum possible.
Sample Input 2
3
2 L
2 L
100 L
Sample Output 2
98
Sample Input 3
8
22 L
75 L
26 R
45 R
72 R
81 R
47 L
29 R
Sample Output 3
188