EICBNLOCK - Combination Lock

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Phuc as a combination block which is represented by ~n~ rotating disks with digits from ~0~ to ~9~ written on them. He has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit ~0~ to digit ~9~ and vice versa. What minimum number of actions does he need for that?

Input

  • The first line contains an integer ~n~ ~(1 \le n \le 10^5)~ : the number of rotating disks.
  • The second line contains a string of ~n~ digits: the initial state of the disks.
  • The third line contains a string of ~n~ digits: the target state (the secret combination).

Output

  • Print a single integer: the minimum number of moves required to transform the initial state into the target state.

Example Input 1

5
82195
64723

Example Output 1

13

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.