
An ISBN (International Standard Book Number) is the unique number assigned to every book published worldwide. It encodes information such as the country and the publisher, and it is written as 13 digits. The last digit is the check digit, which tells you whether the ISBN is correct. The check digit is chosen so that multiplying the digits from the left by the weights 1,3,1,3,… and adding the products gives a sum divisible by 10. Written as a formula:
If the ISBN is abcdefghijklm, then a+3b+c+3d+e+3f+g+3h+i+3j+k+3l+m≡0(mod10).
That is, the check digit is m=(10−(a+3b+c+3d+e+3f+g+3h+i+3j+k+3l)mod10)mod10.
If the remainder is 0, the check digit is 0.
Younghoon works as a librarian at a university central library. While sorting books he found one whose ISBN has a single damaged position. Write a program that recovers the digit that belongs there.