#P1898. 缘分计算

缘分计算

Description

Step 1: Take the initials (abbreviation) of the names and concatenate them. For example, if the lovers are named JiangYunFan and TangYuRou, their initials are JYFTYR.

Step 2: Replace each letter with a string of digits. Replace A\tt A with ST\mathrm{ST}, B\tt B with ST+1\mathrm{ST}+1, C\tt C with ST+2\mathrm{ST}+2, …, and ZZ with ST+25\mathrm{ST}+25, where ST\mathrm{ST} is a known positive integer. For example, if ST=81\mathrm{ST}=81, then A\tt A is replaced by 8181, B\tt B by 8282, …, and Z\tt Z by 106106. The example JYFTYR becomes 901058610010598901058610010598.

Step 3: Repeat the following operation: add each pair of adjacent digits, and write down the ones digit of the sum. It is easy to see that each time this operation is performed, the digit string becomes one digit shorter. When the number becomes 100100 or has no more than two digits (a two-digit number with a leading 00 also counts), the program stops. The resulting number is the couple’s yuanfen. For the example above, the process is as follows:

  • 901058610010598;
  • 91153471011547;
  • 0268718112691;
  • ...
  • 374;

So if ST=81\mathrm{ST}=81, the yuanfen between JiangYunFan and TangYuRou is only 11.

Oh no! DL knows 644 very well. He knows that even if the program calculates a yuanfen as high as 9999, she still won’t be happy. What’s worse, 644 is also curious about the yuanfen of many other couples, and it would be too tedious to compute them one by one. Given the couple’s initials string and a value of ST\mathrm{ST}, can you write a program to compute their yuanfen?

Input Format

The first line contains a string of length LL consisting only of uppercase letters.

The second line contains a positive integer ST\mathrm{ST}, as defined in the statement.

Output Format

Output a single line containing an integer, which is the couple’s yuanfen.

DLLSS
478
100

Hint

Constraints

For 100%100\% of the testdata, 4L104 \le L \le 10, 1ST100001 \le \mathrm{ST} \le 10000.

Note

If your yuanfen with your lover is not 100100, don’t be sad. It’s not a big deal.

Translated by ChatGPT 5