P23700 [AtCoder] [ABC013B] Lock
入门
题目描述

Problem Description

Takahashi, with his high security awareness, has decided to install a new lock at his home.

This lock is a dial lock with a display showing a single digit number and two buttons: one red and one blue. Pressing the red button increases the number on the display by 1, and pressing the blue button decreases it by 1.

However, if the display shows 9 and the red button is pressed, it wraps around to 0. Similarly, if the display shows 0 and the blue button is pressed, it wraps around to 9.

Currently, the number displayed on the lock is $a$, and the lock will open the moment the number becomes $b$. How many times do you need to press the buttons to open the lock with the minimum number of presses?

Input Format

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

$ a $ $ b $

  • The first line contains an integer $a$ ($0 \leq a \leq 9$), representing the current number displayed on the lock.
  • The second line contains an integer $b$ ($0 \leq b \leq 9$), representing the number that needs to be displayed to unlock the lock.
  • $a$ and $b$ will never be the same value.

Output Format

Output the minimum number of button presses required to open the lock on a single line.

Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

4
6

Sample Output #1

2

Sample Input #2

6
4

Sample Output #2

2

Sample Input #3

8
1

Sample Output #3

3

Notes/Hints

Sample Explanation 1

In this example, the lock can be unlocked by pressing the red button twice:
- Press the red button to change the number from 4 to 5.
- Press the red button again to change the number from 5 to 6.

Sample Explanation 2

In this case, the lock can be unlocked by pressing the blue button twice.

Sample Explanation 3

Although the lock can be unlocked by pressing the blue button seven times, it can also be unlocked by pressing the buttons three times as follows:
- Press the red button to change the number from 8 to 9.
- Press the red button to change the number from 9 to 0.
- Press the red button to change the number from 0 to 1.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 6
样例输出
2