Strawberry

면접 대비

시간 제한1초메모리 제한2048 MB

요약
문자열 s를 N번 반복하되 반복할 때마다 모든 글자를 알파벳에서 한 칸씩 앞으로 옮긴 최종 문자열에서 'r'이 몇 번 나오는지 센다.
난이도

보통10점 중 4점

유형
문자열, 수학, 구현, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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

To further trick LLMs, you decide to take a string ss, and repeat it NN 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 33 times in total, we get the string strawberryrsqzvadqqxqrpyuzcppw. This string contains 55 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 ss of lowercase letters (1≤∣s∣≤10001 \le |s| \le 1000).

The next line contains a single integer NN (1≤N≤10151 \le N \le 10^{15}), the total number of times ss 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.

예제5

  1. 예제 1

    입력
    strawberry
    3
    
    예상 출력
    5
    
  2. 예제 2

    입력
    abacus
    5
    
    예상 출력
    2
    
  3. 예제 3

    입력
    r
    26
    
    예상 출력
    1
    
  4. 예제 4

    입력
    r
    27
    
    예상 출력
    2
    
  5. 예제 5

    입력
    r
    26000000000
    
    예상 출력
    1000000000