LearnPy Hub
← Arena
EasyRating 1000

Letters in a Repeated Word

A word is repeated forever: abcabcabc… Count the letter a in the first n letters.

Input

A word, then n (1 ≤ n ≤ 10¹²).

Output

One integer.

Sample 1

Input
aba
10
Output
7

Sample 2

Input
a
1000000000000
Output
1000000000000
solution.py
Output appears here
Letters in a Repeated Word · Python Arena problem · LearnPy Hub