Sunday Drive

Time limit1sMemory limit128 MB

Problem

After wracking your brains at a programming contest on Saturday, you would like to relax with a leisurely Sunday drive. But gasoline is so expensive nowadays! Maybe, by creatively changing lanes, you can minimize the distance you travel and save some money.

You are given a description of several sections of a highway. Every section has the same number of lanes. Think of your car as a point mass moving down the center of its lane, and let each lane be 10 feet wide. There are two kinds of sections: curved and straight. You may change lanes only on straight sections, and it takes at least 100 feet of a straight section to move over by one lane (you may take longer if you wish).

Every curved section makes a 90-degree turn. You cannot change lanes on a curve, and you must drive along the exact middle of a lane throughout the turn, so during a turn your position is 5 feet, or 15 feet, or 25 feet, and so on, from the edge.

Given a description of a highway, compute the minimum total distance needed to drive its entire length, including curves and lane changes. You may start and end in any lane. The highway may cross over or under itself, but the changes in elevation are tiny, so you may ignore their effect on the distance travelled.

Diagram of a multi-lane highway made of straight and curved sections

Input

The input contains several test cases. Each test case begins with two integers N M on one line, where $N$ ($1 \le N \le 1000$) is the number of sections and $M$ ($2 \le M \le 10$) is the number of lanes.

Each of the next $N$ lines describes one section as a letter and a number separated by a single space, T K. The letter $T$ is one of S, L, or R (always capital), giving the section type: a straight section (S), a left curve (L), or a right curve (R). For a straight section, $K$ ($10 \le K \le 10000$) is its length in feet. For a left or right curve, $K$ ($10 \le K \le 10000$) is the radius of the inside edge of the highway, again in feet. Two straight sections are never adjacent, but several curves may be adjacent. The input ends with a line containing two zeros.

Output

For each test case, print a single number on its own line: the minimum distance, in feet, needed to drive the entire highway. Print the number with exactly two digits after the decimal point, rounded. Print no extra spaces, and do not separate answers with blank lines.