#P7379. [COCI 2018/2019 #6] Lun

[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 22; keep the remaining digits unchanged.
  2. For each digit that was multiplied by 22, compute the sum of its digits.
  3. Compute the sum of all digits after the above operations, then multiply it by 99 and take modulo 1010. 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 7992739871379927398713, the checking process is as follows:

Digits of the card number 77 99 22 77 33 99 88 77 11 33
Multiply by 22 every other digit (starting from the second-to-last digit, moving left) 77 18\red {18} 99 4\red 4 77 6\red 6 99 16\red {16} 77 2\red 2 -
Compute digit sums and accumulate 9\green 9 44 66 7\green 7 22 =67=67

Multiply the obtained sum 6767 by 99 and take modulo 1010, getting 67×9mod10=367 \times 9 \bmod 10=3. Here 33 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 NN, representing the length of the bank card number with one missing digit.

The second line contains a string of length NN, representing the bank card number. The string contains only digits 090 \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.

11
7992739871x
3
5
x2464
5
10
93380x1696
1

Hint

Constraints

For 50%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%100\% of the testdata, 1N1001 \le N \le 100.

Notes

The scoring of this problem follows the original COCI problem, with a full score of 5050.

Translated from COCI2018-2019 CONTEST #6 T1 Lun.

Translated by ChatGPT 5