There is a string, $unrecognized$, of lowercase English letters that is repeated infinitely many times.  Given an integer, $unrecognized$, find and print the number of letter a's in the first $unrecognized$ letters of the infinite string.

Example 

$unrecognized$ 

$unrecognized$  

The substring we consider is $unrecognized$, the first $unrecognized$ characters of the infinite string.  There are $unrecognized$ occurrences of a in the substring.  

Function Description  

Complete the repeatedString function in the editor below.  

repeatedString has the following parameter(s):  

s: a string to repeat  
n: the number of characters to consider  

Returns  

int: the frequency of a in the substring  

Input Format

The first line contains a single string, $unrecognized$. 

The second line contains an integer, $unrecognized$.

Constraints

$unrecognized$
$unrecognized$
For $unrecognized$ of the test cases, $unrecognized$.

Sample Input

Sample Input 0

aba
10

Sample Output 0

7

Explanation 0 

The first $unrecognized$ letters of the infinite string are abaabaabaa. Because there are $unrecognized$ a's, we return $unrecognized$.

Sample Input 1

a
1000000000000

Sample Output 1

1000000000000

Explanation 1 

Because all of the first $unrecognized$ letters of the infinite string are a, we return $unrecognized$.

Difficulty: EASY

Solutions:
s = input().strip()
n = int(input().strip())
L = len(s)
print(s.count('a') * (n // L) + s[:n % L].count('a'))


import sys
s = input().strip()
n = int(input().strip())
c = sum((x == 'a' for x in s))
print(c * (n // len(s)) + sum((x == 'a' for x in s[:n % len(s)])))


import sys
s = input().strip()
n = int(input().strip())
count = 0
for i in s:
	if i == 'a':
		count += 1
l = len(s)
m = n // l
t = n % l
h = 0
for i in range(t):
	if s[i] == 'a':
		h += 1
ans = m * count + h
print(ans)


import sys
s = input().strip()
n = int(input().strip())
x = 0
for i in s:
	if i == 'a':
		x += 1
l = len(s)
q = n // l
r = n % l
c = 0
for i in range(r):
	if s[i] == 'a':
		c += 1
ans = q * x + c
print(ans)


import sys
s = input().strip()
n = int(input().strip())
c = sum((1 for c in s if c == 'a'))
r = c * (n // len(s)) + sum((1 for c in s[:n % len(s)] if c == 'a'))
print(r)


import sys
import re
s = input().strip()
n = int(input().strip())
rem = n % len(s)
cnt = len(re.findall('a', s)) * (n // len(s))
cnt += len(re.findall('a', s[:rem]))
print(cnt)


import sys
s = input().strip()
n = int(input().strip())
x = n - int(n / len(s)) * len(s)
print(s.count('a') * int(n / len(s)) + s[:x].count('a'))


import sys
s = input().strip()
n = int(input().strip())
a = s.count('a')
extra = n % len(s)
extra_count = s[:extra].count('a')
print(a * (n // len(s)) + extra_count)


import sys
from collections import Counter
s = input().strip()
n = int(input().strip())
c = Counter(s)
a = n % len(s)
b = n // len(s)
ans = c['a'] * b
for char in s[:a]:
	if char == 'a':
		ans += 1
print(ans)


def main():
	s = input().strip()
	n = int(input())

	def num_of_a(t):
		return sum((1 for c in t if c == 'a'))
	(times, rest) = divmod(n, len(s))
	print(times * num_of_a(s) + num_of_a(s[:rest]))
main()


import sys
s = input().strip()
n = int(input().strip())
if n <= len(s):
	print(s[:n].count('a'))
else:
	print(s.count('a') * (n // len(s)) + s[:n % len(s)].count('a'))


import sys
import math
s = input().strip()
n = int(input().strip())
print(s.count('a') * math.floor(n / len(s)) + s[0:n % len(s)].count('a'))


import sys
s = input().strip()
n = int(input().strip())
m = n // len(s)
yushu = n % len(s)
c = s.count('a')
new_s = s[:yushu]
print(c * m + new_s.count('a'))


import sys
s = input().strip()
n = int(input().strip())
na = s.count('a')
ls = len(s)
total = n // ls * na
s1 = s[:n % ls]
total += s1.count('a')
print(total)


s = input()
n = int(input())
numA = s.count('a')
l = len(s)
m = n // l
remaining = n - m * l
rString = s[0:remaining]
print(m * numA + rString.count('a'))


s = input()
n = int(input())
if n < len(s):
	t = s[:n]
	print(t.count('a'))
else:
	m = n % len(s)
	a = s.count('a') * int(n / len(s))
	t = s[:m]
	print(a + t.count('a'))


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
k = n // l
r = n % l
print(s.count('a') * k + s[:r].count('a'))


import sys
s = input().strip()
n = int(input().strip())
acount = s.count('a')
count = int(n / len(s)) * acount
for i in range(n % len(s)):
	if s[i] == 'a':
		count += 1
print(count)


import sys
s = input().strip()
n = int(input().strip())
ls = len(s)
a = n // ls
b = n % ls
result = s.count('a') * a + s[:b].count('a')
print(result)


import sys
s = input().strip()
n = int(input().strip())
(q, r) = divmod(n, len(s))
numa1 = sum([i == 'a' for i in s])
numa2 = sum([i == 'a' for i in s[0:r]])
print(numa1 * q + numa2)


import sys
from math import *
s = input().strip()
n = int(input().strip())
c = 0
ans = 1
for i in s:
	if i == 'a':
		c += 1
if c == 1 and len(s) == 1:
	print(n)
else:
	ans = c * (n // len(s))
	rem = n % len(s)
	for i in range(rem):
		if s[i] == 'a':
			ans += 1
	print(ans)


c = 0
s = input().strip()
n = int(input().strip())
for i in s:
	if i == 'a':
		c += 1
m = n // len(s)
c = c * m
r = n % len(s)
for i in range(r):
	if s[i] == 'a':
		c += 1
print(c)


import sys
s = input().strip()
n = int(input().strip())
repeats = n // len(s)
leftover = n % len(s)
a_count = s.count('a')
ans = a_count * repeats + s[:leftover].count('a')
print(ans)


s = input()
n = int(input())
if len(s) < n:
	num_letter_in_string = s.count('a')
	ans = num_letter_in_string * (n // len(s))
	if n % len(s) != 0:
		ans += s[:n % len(s)].count('a')
	print(ans)
else:
	print(s[:n].count('a'))


import sys
s = input().strip()
n = int(input().strip())
x = s.count('a')
y = n % len(s)
z = s[:y].count('a')
print(x * (n // len(s)) + z)


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
c = len([b for b in s if b == 'a'])
m = n % l
d = n // l
s = c * d + len([b for b in s[:m] if b == 'a'])
print(s)


import sys
s = input().strip()
n = int(input().strip())
l_s = len(s)
m = n % l_s
n_a = 0
n_a2 = 0
for i in range(l_s):
	if s[i] == 'a':
		n_a += 1
		if i < m:
			n_a2 += 1
print(n // l_s * n_a + n_a2)


import sys
s = input().strip()
n = int(input().strip())
count = 0
l = len(s)
for i in range(l):
	if s[i] == 'a':
		count = count + 1
remain = n % l
count = count * (n // l)
for i in range(remain):
	if s[i] == 'a':
		count = count + 1
print(count)


import sys
a_count = 0
s = input().strip()
n = int(input().strip())
for c in s:
	if c == 'a':
		a_count += 1
total_a_count = n // len(s) * a_count
for i in range(0, n % len(s)):
	if s[i] == 'a':
		total_a_count += 1
print(total_a_count)


import sys
s = input().strip()
n = int(input().strip())
if s == 'a':
	print(n)
else:
	size = len(s)
	count = 0
	for i in range(0, size):
		if s[i] == 'a':
			count = count + 1
	if count == 0:
		print(0)
	else:
		div = int(n / size)
		remainder = n % size
		result = div * count
		for j in range(0, remainder):
			if s[j] == 'a':
				result = result + 1
		print(result)


from math import floor
import sys
s = input().strip()
n = int(input().strip())
l = len(s)
x = s.count('a')
occurences = int(floor(n / l)) * x
missing_chars = n % l
missing = s.count('a', 0, missing_chars)
print(missing + occurences)


def solve(string, length):
	(full_encounters, last_length) = divmod(length, len(string))
	full_num = len([c for c in string if c == 'a'])
	last_num = len([c for c in string[:last_length] if c == 'a'])
	return full_num * full_encounters + last_num
s = input().strip()
n = int(input().strip())
print(solve(s, n))


import sys
from math import *
s = input().strip()
n = int(input().strip())
c = 0
ans = 1
for i in s:
	if i == 'a':
		c += 1
if c == 1 and len(s) == 1:
	print(n)
else:
	ans = c * (n // len(s))
	rem = n % len(s)
	for i in range(rem):
		if s[i] == 'a':
			ans += 1
	print(ans)


st = input()
n = int(input())
li = list(st)
x = li.count('a')
a = x * (n // len(st))
b = li[0:n % len(st)].count('a')
print(a + b)


import sys
s = input().strip()
n = int(input().strip())
q = n // len(s)
r = n % len(s)
res = sum((1 for x in s if x == 'a')) * q
res += sum((1 for i in range(r) if s[i] == 'a'))
print(res)


import sys
s = input().strip()
n = int(input().strip())
str_len = len(s)
a_n = []
count = 0
for c in s:
	if c == 'a':
		count += 1
	a_n.append(count)
rep = n // len(s)
over = n % len(s)
if over == 0:
	adder = 0
else:
	adder = a_n[over - 1]
total = rep * count + adder
print(total)


import sys
s = input().strip()
n = int(input().strip())
k = len(s)
print(n // k * s.count('a') + s[0:n % k].count('a'))


import sys
s = input().strip()
n = int(input().strip())
N = s.count('a')
l = len(s)
rep = int(n / l)
rest = n % l
cont = rep * N + s[0:rest].count('a')
print(cont)


import sys

def count_a(s, n):
	if n < len(s):
		return s[:n].count('a')
	else:
		o_count = s.count('a')
		floor_n = n // len(s)
		remainder = n % len(s)
		return o_count * floor_n + s[:remainder].count('a')
s = input().strip()
n = int(input().strip())
print(count_a(s, n))


import sys
s = input().strip()
n = int(input().strip())
na = s.count('a')
(x, y) = (n // len(s), n % len(s))
sum = na * x + s.count('a', 0, y)
print(sum)


s = input()
a = s.count('a')
n = int(input())
x = n // len(s)
y = n % len(s)
c = x * a
c += s[0:y].count('a')
print(c)


import sys
s = input().strip()
n = int(input().strip())
acount = 0
for char in s:
	if char == 'a':
		acount += 1
count = 0
for char in s[:n % len(s)]:
	if 'a' == char:
		count += 1
print(acount * (n // len(s)) + count)


import sys
s = input().strip()
n = int(input().strip())
str_length = len(s)
a_count = s.count('a')
number_full = n // str_length
leftover = n % str_length
leftover_string = s[0:leftover]
print(a_count * number_full + leftover_string.count('a'))


import sys
s = input().strip()
n = int(input().strip())
listcount = []
count = 0
for i in range(len(s)):
	if s[i] == 'a':
		count = count + 1
	listcount.append(count)
ans = listcount[len(s) - 1] * (n // len(s))
if n % len(s) != 0:
	ans = ans + listcount[n % len(s) - 1]
print(ans)


import sys
s = input().strip()
n = int(input().strip())
i = 0
c = 0
l = len(s)
for i in range(l):
	if s[i] == 'a':
		c += 1
count = int(n / l) * c
for i in range(n % l):
	if s[i] == 'a':
		count += 1
print(count)


s = input()
n = int(input())
len_s = len(s)
a_cnt = s.count('a')
b = 0
b += a_cnt * int(n / len_s)
c = n % len_s
s1 = s[0:c]
b += s1.count('a')
print(b)


s = input().strip()
n = int(input().strip())
l = len(s)
numa = 0
for c in s:
	if c == 'a':
		numa += 1
total = n // l * numa
left = n % l
for i in range(left):
	if s[i] == 'a':
		total += 1
print(total)


import sys
s = input().strip()
n = int(input().strip())
print(s.count('a') * int(n / len(s)) + s[:n % len(s)].count('a'))


import sys
s = input().strip()
n = int(input().strip())
r1 = n // len(s) * s.count('a')
r2 = s[:n % len(s)].count('a')
print(r1 + r2)


import sys
s = input().strip()
n = int(input().strip())
count = 0
l = len(s)
for i in s:
	if i == 'a':
		count += 1
r = n % l
a = count * (n // l)
if r == 0:
	print(a)
else:
	for i in range(r):
		if s[i] == 'a':
			a += 1
	print(a)


import sys
s = input().strip()
n = int(input().strip())
print(s.count('a') * (n // len(s)) + s[:n % len(s)].count('a'))


s = input()
n = int(input())
l = len(s)
h = n % l
res = s[:h].count('a')
if n - h > 0:
	res += n // l * s.count('a')
print(res)


import sys
s = input().strip()
n = int(input().strip())
ctr = 0
if len(s) > n:
	for i in s:
		if i == 'a':
			ctr += 1
else:
	q = int(n / len(s))
	r = n % len(s)
	base = 0
	for i in s:
		if i == 'a':
			base += 1
	ctr += q * base
	for i in range(0, r):
		if s[i] == 'a':
			ctr += 1
print(ctr)


s = input()
t = int(input())
x = len(s)
s = list(s)
c = s.count('a')
rr = []
rr = list(divmod(t, x))
qu = rr[0]
rem = rr[1]
sol = 1
sol = sol * qu * c
for i in range(rem):
	if s[i] == 'a':
		sol = sol + 1
print(sol)


import itertools
import sys
s = input().strip()
n = int(input().strip())
no_of_as = s[:n].count('a')
s_len = len(s)
if n < len(s):
	print(no_of_as)
else:
	print(no_of_as * int(n / s_len) + s[:n % s_len].count('a'))


import sys
s = input().strip()
n = int(input().strip())
m = n % len(s)
su = sum = 0
for i in range(0, m):
	if s[i] == 'a':
		su += 1
for i in range(m, len(s)):
	if s[i] == 'a':
		sum += 1
sum += su
sum *= n // len(s)
sum += su
print(sum)


import sys
s = input().strip()
n = int(input().strip())
if len(s) >= n:
	print(s[:n].count('a'))
else:
	if n % len(s) == 0:
		ca = s.count('a') * (n // len(s))
	else:
		ca = s.count('a') * (n // len(s))
		ca += s[:n % len(s)].count('a')
	print(ca)


import sys
import math
s = input().strip()
n = int(input().strip())
counter = 0
for x in s:
	if x == 'a':
		counter += 1
amount = math.floor(n / len(s))
rest = n % len(s)
sec = 0
for x in s[:rest]:
	if x == 'a':
		sec += 1
print(sec + counter * amount)


s = input()
n = int(input())
count = s.count('a')
count = count * int(n / len(s))
if n % len(s) != 0:
	s = s[:n % len(s)]
	count += s.count('a')
print(count)


import sys
line = input().strip()
N = int(input().strip())
cont = [0] * 150
for (index, c) in enumerate(line):
	if index != 0:
		cont[index] = cont[index - 1]
	if c == 'a':
		cont[index] += 1
ans = N // len(line) * cont[len(line) - 1] + cont[N % len(line) - 1]
print(ans)


import sys
s = input().strip()
n = int(input().strip())
print(len(list(filter(lambda x: x == 'a', s))) * (n // len(s)) + len(list(filter(lambda x: x == 'a', s[:n % len(s)]))))


import sys
s = input().strip()
k = list(s)
count = 0
n = int(input().strip())
for i in range(0, len(s)):
	if k[i] == 'a':
		count = count + 1
rem = n % len(s)
stuff = 0
for i in range(0, rem):
	if k[i] == 'a':
		stuff = stuff + 1
if rem == 0:
	print(count * (n // len(s)))
else:
	print(count * (n // len(s)) + stuff)


import sys
s = input().strip()
n = int(input().strip())
strlen = len(s)
count = s.count('a')
if n % strlen == 0:
	print(int(n / strlen * count))
else:
	extra = n % strlen
	print(n // strlen * count + s[:extra].count('a'))


s = input()
n = int(input())
r = n % len(s)
r = n // len(s) * s.count('a') + s[:r].count('a')
print(r)


s = input()
t = int(input())
x = len(s)
s = list(s)
c = s.count('a')
rrx = []
rrx = list(divmod(t, x))
qu = rrx[0]
rem = rrx[1]
sol = 1
sol = sol * qu * c
for i in range(rem):
	if s[i] == 'a':
		sol = sol + 1
print(sol)


a = input()
n = int(input())
print(n // len(a) * a.count('a') + a[:n % len(a)].count('a'))


import sys
s = input().strip()
n = int(input().strip())
base = s.count('a')
l = len(s)
if n % l == 0:
	print(int(n / l * base))
else:
	close = int(n / l)
	remain = n - l * close
	print(close * base + s[:remain].count('a'))


import sys
s = input().strip()
n = int(input().strip())
nrAs = sum((1 for c in s if c == 'a'))
full = n // len(s)
rest = n % len(s)
print(nrAs * full + sum((1 for i in range(0, rest) if s[i] == 'a')))


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
c = s.count('a')
r = c * (n // l)
r += s[0:n % l].count('a')
print(r)


import sys
s = input().strip()
n = int(input().strip())
length = len(s)
cnt = s.count('a')
total = cnt * (n // length)
total += s[:n % length].count('a')
print(total)


__Author__ = 'Deepak Singh Mehta...'
st = input()
n = int(input())
aa = st.count('a')
len1 = len(st)
res = n // len(st)
rest = res * aa
jj = n - len(st) * res
print(rest + +st[:jj].count('a'))


import sys
s = list(input().strip())
n = int(input().strip())
l = len(s)
t = n // l
c = s.count('a')
tc = c * t
r = n % l
if r != 0:
	rs = s[0:r]
	ac = rs.count('a')
	tc += ac
print(tc)


import sys

def main():
	string = input()
	n = int(input())
	a = string.count('a')
	new_n = n // len(string)
	if new_n:
		temp = a * new_n
	else:
		temp = a
	ostatok = n % len(string)
	count_A_in_new_string = string[:ostatok].count('a')
	if ostatok and new_n:
		print(temp + count_A_in_new_string)
	else:
		print(temp)
main()


import sys
s = input().strip()
n = int(input().strip())
slist = list(s)
a = slist.count('a')
len_s = len(slist)
times = n // len_s
number_a = times * a
remainder = n % len_s
if remainder != 0:
	new_list = []
	for i in s:
		new_list.append(i)
		if len(new_list) == remainder:
			number_a = number_a + new_list.count('a')
			break
print(number_a)


import sys
s = input().strip()
n = int(input().strip())
aBasic = s.count('a')
remainder = n % len(s)
numCycles = (n - remainder) / len(s)
aCount = aBasic * numCycles
i = 0
if remainder > 0:
	while True:
		for char in s:
			if char == 'a':
				aCount += 1
			i += 1
			if i == remainder:
				break
		if i == remainder:
			break
print(int(aCount))


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
if l >= n:
	f = s[0:n].count('a')
else:
	f = s.count('a')
	r = int(n / l)
	q = int(n % l)
	f = r * f + s[0:q].count('a')
print(f)


import sys
s = input().strip()
n = int(input().strip())
num_of_as = s.count('a')
total = 0
if len(s) <= n:
	complete = n // len(s)
	rest_of_s = s[:n % len(s)]
	total += num_of_as * complete + rest_of_s.count('a')
else:
	total += s[:n].count('a')
print(total)


import sys
s = input().strip()
n = int(input().strip())
count = 0
for c in s:
	if c == 'a':
		count += 1
nofwords = n // len(s)
count *= nofwords
n = n % len(s)
for c in s:
	n -= 1
	if c == 'a' and n >= 0:
		count += 1
	if n <= 0:
		break
print(count)


import sys
s = input().strip()
n = int(input().strip())
p = len(s)
answer = n // p * s.count('a')
remaining = n % p
answer += s[0:remaining].count('a')
print(answer)


import sys
s = input().strip()
n = int(input().strip())
m = n % len(s)
n = n // len(s)
count1 = count2 = 0
for (i, c) in enumerate(s):
	if c == 'a':
		count1 += 1
		if i < m:
			count2 += 1
result = n * count1 + count2
print(result)


import sys
s = input().strip()
n = int(input().strip())
if n % len(s) == 0:
	print(s.count('a') * int(n / len(s)))
else:
	print(s.count('a') * int(n / len(s)) + s[:n % len(s)].count('a'))


import sys
s = input().strip()
n = int(input().strip())
temp = 0
for i in s:
	temp += int(i == 'a')
temp = n // len(s) * temp
for i in range(n % len(s)):
	if 'a' == s[i]:
		temp += 1
print(temp)


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
ass = 0
for chr in s:
	if chr == 'a':
		ass += 1
rep = int(n / l)
bag = n % l
if bag == 0:
	print(ass * rep)
else:
	arep = 0
	s = list(s)
	for i in range(len(s)):
		if s[i] == 'a' and i < bag:
			arep += 1
	print(ass * rep + arep)


s = input()
n = int(input())
nA = 0
for l in s:
	if l == 'a':
		nA += 1
comp = n // len(s)
rest = n % len(s)
tot = nA * comp
for l in s[:rest]:
	if l == 'a':
		tot += 1
print(tot)


st = input()
a_cont = len([letter for letter in st if letter == 'a'])
n = int(input())
length = len(st)
xxx = len([letter for letter in st[:n % length] if letter == 'a'])
print(a_cont * (n // length) + xxx)


import sys
s = input().strip()
n = int(input().strip())
lenofS = len(s)
timesTomult = n // lenofS
subLen = n - timesTomult * lenofS
s_subbed = s[0:subLen]
a_insub = s_subbed.count('a')
a_ins = s.count('a')
print(a_insub + a_ins * timesTomult)


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
mod = n % l
count = 0
for _ in range(l):
	if s[_] == 'a':
		count += 1
count = count * (n // l)
for _ in range(mod):
	if s[_] == 'a':
		count += 1
print(count)


from math import ceil
n = input().strip()
l = len(n)
k = int(input().strip(''))
c = n.count('a')
k1 = int(k / l)
k2 = k % l
if k2 != 0:
	ans = k1 * c + n[:k2].count('a')
else:
	ans = k1 * c
print(ans)


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
p = s.count('a')
full = n // l
left = n % l
w = full * p
sl = s[0:left]
z = sl.count('a')
ans = w + z
print(ans)


s = input().strip()
n = int(input().strip())
l = len(s)
ans = s.count('a')
ans = ans * int(n / l)
ans += s[:n % l].count('a')
print(ans)


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
no_of_a = s.count('a')
if n % l == 0:
	print(int(no_of_a * (n / l)))
else:
	rem = n % l
	mul = int((n - rem) / l)
	s = s[:rem]
	no_of_a = int(no_of_a * mul)
	a = s.count('a')
	no_of_a = no_of_a + a
	print(int(no_of_a))


import sys
s = input().strip()
n = int(input().strip())
sac = len([True for i in s if i == 'a'])
c = sac * (n // len(s))
c += len([True for i in s[:n % len(s)] if i == 'a'])
print(c)


import sys
s = input().strip()
n = int(input().strip())
s = list(s)
z = len(s)
k = 0
for i in range(z):
	if s[i] == 'a':
		k = k + 1
x = int(n / z) * k
y = n % z
for i in range(y):
	if s[i] == 'a':
		x = x + 1
print(x)


import sys
s = input().strip()
n = int(input().strip())
arec = s.count('a')
l = len(s)
num = n // l
total = num * arec
total += s.count('a', 0, n % l)
print(total)


import sys
s = input().strip()
n = int(input().strip())
cnt = 0
res = 0
for i in range(len(s)):
	if s[i] == 'a':
		cnt += 1
		if i < n % len(s):
			res += 1
print(cnt * (n // len(s)) + res)


import sys
s = input().strip()
n = int(input().strip())
start = s.count('a')
(div, mod) = divmod(n, len(s))
total = start * div + s[:mod].count('a')
print(total)


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
a = 0
mul = int(n / l)
rem = int(n % l)
rema = 0
for i in range(l):
	if s[i] == 'a':
		a += 1
		if i < rem:
			rema += 1
ans = mul * a + rema
print(ans)


import sys
s = input().strip()
n = int(input().strip())
m = 0
for c in s:
	if c == 'a':
		m = m + 1
m = m * (n // len(s))
for i in range(n % len(s)):
	if s[i] == 'a':
		m = m + 1
print(m)