A - Elevator Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 9

注意

この問題に対する言及は、2020年5月2日 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。

試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

下から順に B9, B8, ..., B1, 1F, 2F, ..., 9F と呼ばれる 18 のフロアを持つ建物があります。

この建物のエレベーターは、隣接する 2 つのフロア間の移動に常に 1 秒を要します。例えば、B9 から 9F への移動には 17 秒を要し、反対方向も同様です。

2 つのフロア S, T が与えられます。エレベーターが S から T へ移動するには最短で何秒を要するでしょうか。

制約

  • S, T はいずれも B1,B2,B3,B4,B5,B6,B7,B8,B9,1F,2F,3F,4F,5F,6F,7F,8F,9F のいずれかである
  • ST は等しくない

入力

入力は以下の形式で標準入力から与えられる。

S T

出力

S から T への移動に要する最短秒数を表す整数を出力せよ。


入力例 1

1F 5F

出力例 1

4

1F から 5F への移動には 4 秒を要します。


入力例 2

B1 B7

出力例 2

6

B1 から B7 への移動には 6 秒を要します。


入力例 3

1F B1

出力例 3

1

1F と B1 は隣接しているため、移動に 1 秒を要します。


入力例 4

B9 9F

出力例 4

17

B9 から 9F への移動には 17 秒を要します。

Score : 9 points

Warning

Do not make any mention of this problem until May 2, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded.

After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

There is a building with 18 floors called B9, B8, ..., B1, 1F, 2F, ..., 9F.

The elevator in this building always takes one second to travel between two adjacent floors. For example, it takes 17 seconds to travel from B9 to 9F or vice versa.

Given two floors S and T, find the shortest time required for the elevator to travel from S and T.

Constraints

  • Each of S and T is B1, B2, B3, B4, B5, B6, B7, B8, B9, 1F, 2F, 3F, 4F, 5F, 6F, 7F, 8F, or 9F.
  • S and T are not equal.

Input

Input is given from Standard Input in the following format:

S T

Output

Print an integer representing the shortest time required to travel from S to T.


Sample Input 1

1F 5F

Sample Output 1

4

It takes 4 seconds to travel from 1F to 5F.


Sample Input 2

B1 B7

Sample Output 2

6

It takes 6 seconds to travel from B1 to B7.


Sample Input 3

1F B1

Sample Output 3

1

1F and B1 are adjacent, and it takes 1 second to travel between them.


Sample Input 4

B9 9F

Sample Output 4

17

It takes 17 second to travel from B9 to 9F.