P26588 [AtCoder] Elevator
普及
题目描述

Problem Description

There is a building with 18 floors named B9, B8, ..., B1, 1F, 2F, ..., 9F from bottom to top.

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

Given two floors \( S \) and \( T \), what is the shortest time required for the elevator to move from \( S \) to \( T \)?

Input Format

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

\( S \) \( T \)

Output Format

Output an integer representing the shortest number of seconds required to move from \( S \) to \( T \).

Sample Input and Output

Sample Input #1

1F 5F

Sample Output #1

4

Sample Input #2

B1 B7

Sample Output #2

6

Sample Input #3

1F B1

Sample Output #3

1

Sample Input #4

B9 9F

Sample Output #4

17

Notes/Hints

Constraints

  • \( S \) and \( T \) are each one of B1, B2, B3, B4, B5, B6, B7, B8, B9, 1F, 2F, 3F, 4F, 5F, 6F, 7F, 8F, 9F
  • \( S \) and \( T \) are not equal

Sample Explanation 1

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

Sample Explanation 2

It takes 6 seconds to move from B1 to B7.

Sample Explanation 3

Since 1F and B1 are adjacent, it takes 1 second to move.

Sample Explanation 4

It takes 17 seconds to move from B9 to 9F.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

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