Under construction

Still being built. Things may change

ISBN

Interview

Time limit1sMemory limit1024 MB

Summary
Given a 10-character ISBN with one '?', find the digit (0 to 9 or X) that makes the weighted sum divisible by 11, or print -1 if none does.
Level

Easy2 of 10

Topics
Brute force, Math
Solved
No attempts yet

Problem

Farmer John's cows enjoy reading books, and FJ has found that they produce more milk when they read somewhat intellectual books. He plans to replace the cheap romance novels in the barn library with textbooks on algorithms and mathematics. A shipment of the new books fell in the mud, and their ISBN numbers are now hard to read.

An ISBN (International Standard Book Number) is a ten digit code that uniquely identifies a book. The first nine digits represent the book, and the last digit checks that the ISBN is correct. To verify an ISBN, multiply the first digit by 10, the second digit by 9, and so on down to multiplying the last digit by 1, then add the products. If the sum leaves no remainder when divided by 11, the ISBN is valid.

For example, 0201103311 is a valid ISBN, since 10×0+9×2+8×0+7×1+6×1+5×0+4×3+3×3+2×1+1×1=5510 \times 0 + 9 \times 2 + 8 \times 0 + 7 \times 1 + 6 \times 1 + 5 \times 0 + 4 \times 3 + 3 \times 3 + 2 \times 1 + 1 \times 1 = 55.

Each of the first nine digits can take a value from 0 to 9. The last digit can also be X, which stands for ten. For example, 156881111X is a valid ISBN.

Your task is to fill in the missing digit of an ISBN where the missing digit is marked as '?'.

Input

A single line containing a ten digit ISBN number with '?' in exactly one position.

Output

Print the missing digit (0 to 9 or X). Print -1 if no digit for the '?' position makes a valid ISBN.

Examples1

  1. Example 1

    Input
    15688?111X
    
    Expected output
    1