A-combination Lock

Source: Internet
Author: User

Time Limit: 2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i64u

Description

Scrooge McDuck keeps his is treasured savings in a home safe with a combination lock. Each time he wants into put there the treasures that he's earned fair and square, he has to open the lock.

The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck have to turn some disks so, 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, on one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for?

Input

The first line contains a single integer n (1≤ n ≤1000)-the number of disks on the Combinati On lock.

The second line contains a string of n digits-the original state of the disks.

The third line contains a string of n digits-scrooge McDuck ' s combination that opens the lock.

Output

Print a single integer-the minimum number of moves Scrooge McDuck needs to open the lock.

Sample Input

Input
5
82195
64723
Output
13

Hint

In the sample he needs moves:

    • 1 Disk:
    • 2 Disk:
    • 3 Disk:
    • 4 Disk:
    • 5 Disk:

Over Gotanda, water and water.

The AC code is attached:

1#include <iostream>2#include <cstring>3#include <cmath>4 using namespacestd;5 6 intN;7 Chara[1100],b[1100];8 intx[1100],y[1100];9 Ten intMain () { One      while(cin>>N) { ACin>>a>>b; -          for(intI=0; i<n;i++){ -x[i]=a[i]-'0'; they[i]=b[i]-'0'; -         } -         intsum=0; -          for(intI=0; i<n;i++){ +             if(ABS (X[i]-y[i]) >5) -sum+= (Ten-abs (x[i]-y[i])); +             Else ASum+=abs (x[i]-y[i]); at         } -cout<<sum<<Endl; -     } -     return 0; -}

A-combination Lock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.