시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB82545172.857%

문제

How many r's are there in the word strawberry? That's easy, it's obvious the answer is $3$. But to LLMs, the answer is not so obvious, and early models would count the word to have only $2$.

To further trick LLMs, you decide to take a string $s$, and repeat it $N$ times. Each time it's repeated, you change each letter to be the previous letter in the alphabet, with a instead becoming z. For example, the word abacus becomes zazbtr.

If we take the word strawberry and repeat it $3$ times in total, we get the string strawberryrsqzvadqqxqrpyuzcppw. This string contains $5$ occurrences of the letter r.

Given a word and the total number of times it is repeated, count the number of times r appears in it!

입력

The first line of input contains a string $s$ of lowercase letters ($1 \le |s| \le 1000$).

The next line contains a single integer $N$ ($1 \le N \le 10^{15}$), the total number of times $s$ is repeated including the initial string, where each letter is replaced by the one before it in each repetition.

출력

Output the number of times r appears in the final string.

예제 입력 1

strawberry
3

예제 출력 1

5

예제 입력 2

abacus
5

예제 출력 2

2

예제 입력 3

r
26

예제 출력 3

1

예제 입력 4

r
27

예제 출력 4

2

예제 입력 5

r
26000000000

예제 출력 5

1000000000

출처

ICPC > Regionals > North America > Pacific Northwest Regional > 2025 ICPC Pacific Northwest Regional > Division 2 F번

  • 문제를 만든 사람: Jonathan Shen