P7379 [COCI 2018/2019 #6] Lun

Description

There is an algorithm to check whether a certain bank card number is valid: 1. Starting from the second-to-last digit, move from right to left. Multiply every other digit by $2$; keep the remaining digits unchanged. 2. For each digit that was multiplied by $2$, compute the sum of its digits. 3. Compute the sum of all digits after the above operations, then multiply it by $9$ and take modulo $10$. Check whether the result equals the last digit (i.e., the check digit of the bank card number). If the card number to be verified is $79927398713$, the checking process is as follows: |Digits of the card number|$7$|$9$|$9$|$2$|$7$|$3$|$9$|$8$|$7$|$1$|$3$| | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | |Multiply by $2$ every other digit (starting from the second-to-last digit, moving left)|$7$|$\red {18}$|$9$|$\red 4$|$7$|$\red 6$|$9$|$\red {16}$|$7$|$\red 2$| -| |Compute digit sums and accumulate|$7$|$\green 9$|$9$|$4$|$7$|$6$|$9$|$\green 7$|$7$|$2$|$=67$| Multiply the obtained sum $67$ by $9$ and take modulo $10$, getting $67 \times 9 \bmod 10=3$. Here $3$ is the check digit of this card number, so the original card number is valid. Now you are given a bank card number with one digit missing. According to the algorithm above, fill in a suitable digit at the missing position so that the resulting card number is valid.

Input Format

The first line contains an integer $N$, representing the length of the bank card number with one missing digit. The second line contains a string of length $N$, representing the bank card number. The string contains only digits $0 \sim 9$ and the character `x`. The character `x` appears exactly once, indicating the missing digit.

Output Format

Output a digit that satisfies the requirement. If there are multiple valid digits, output the smallest one.

Explanation/Hint

#### Constraints For $50\%$ of the testdata, the missing digit is at the check digit position, i.e., the character `x` is at the last position of the string. For $100\%$ of the testdata, $1 \le N \le 100$. #### Notes **The scoring of this problem follows the original COCI problem, with a full score of $50$.** **Translated from [COCI2018-2019](https://hsin.hr/coci/archive/2018_2019/) [CONTEST #6](https://hsin.hr/coci/archive/2018_2019/contest6_tasks.pdf) _T1 Lun_.** Translated by ChatGPT 5