P1898 Yuanfen Calculation

Background

Yuanfen is a Chinese term that is hard for foreigners to understand. Roughly speaking, yuanfen is a mysterious force that brings two people (usually lovers) together. Although it's superstitious, many people—especially girls—like to calculate it. Unfortunately, 644 is like that too. One day, she asked DL, “Honey, could you calculate our yuanfen?” Sigh, DL really dislikes this question, but he couldn’t refuse. Luckily, DL is a programmer, so he only needed to find a reasonable-looking algorithm and write a yuanfen calculator. After searching online for several hours, he decided to use the following yuanfen algorithm.

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 $\tt A$ with $\mathrm{ST}$, $\tt B$ with $\mathrm{ST}+1$, $\tt C$ with $\mathrm{ST}+2$, …, and $Z$ with $\mathrm{ST}+25$, where $\mathrm{ST}$ is a known positive integer. For example, if $\mathrm{ST}=81$, then $\tt A$ is replaced by $81$, $\tt B$ by $82$, …, and $\tt Z$ by $106$. The example JYFTYR becomes $901058610010598$. 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 $100$ or has no more than two digits (a two-digit number with a leading $0$ 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; - 01. So if $\mathrm{ST}=81$, the yuanfen between JiangYunFan and TangYuRou is only $1$. Oh no! DL knows 644 very well. He knows that even if the program calculates a yuanfen as high as $99$, 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 $\mathrm{ST}$, can you write a program to compute their yuanfen?

Input Format

The first line contains a string of length $L$ consisting only of uppercase letters. The second line contains a positive integer $\mathrm{ST}$, as defined in the statement.

Output Format

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

Explanation/Hint

### Constraints For $100\%$ of the testdata, $4 \le L \le 10$, $1 \le \mathrm{ST} \le 10000$. ### Note If your yuanfen with your lover is not $100$, don’t be sad. It’s not a big deal. Translated by ChatGPT 5