Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

See notes for definition of a tandem repeat.


-----Input-----

The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.


-----Output-----

Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.


-----Examples-----
Input
aaba
2

Output
6

Input
aaabbbb
2

Output
6

Input
abracadabra
10

Output
20



-----Note-----

A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: s_{i} = s_{i} + n.

In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.

Difficulty: MEDIUM

Solutions:
import sys
str = input()
k = int(input())
ans = 0
if k >= len(str):
	print((k + len(str)) // 2 * 2)
	return
for i in range(len(str)):
	for j in range(0, i + 1):
		len1 = len(str[j:i + 1])
		len2 = len(str[i + 1:])
		minn = min(len1, len2)
		if str[j:j + minn] == str[i + 1:i + 1 + minn]:
			if minn == len1:
				ans = max(ans, len1 * 2)
			elif k + len2 >= len1:
				ans = max(ans, len1 * 2)
print(ans)


s = input()
k = int(input())
n = len(s)
if k >= n:
	print(int(2 * ((n + k) // 2)))
	raise SystemExit
ll = 0
for i in range(k + 1):
	for l in range((n + i) // 2, i - 1, -1):
		if s[n - (l - i):n] == s[n + i - 2 * l:n - l]:
			if l > ll:
				ll = l
			break
j = ll
while 2 * j <= n:
	j = j + 1
	for i in range(n - 2 * j):
		if s[i:i + j] == s[i + j:i + 2 * j]:
			ll = j
			break
print(int(2 * ll))


s = input()
k = int(input())
s += '?' * k
for i in range(len(s) - len(s) % 2, 0, -2):
	for j in range(len(s) - i + 1):
		if all((s[x + i // 2] in {'?', s[x]} for x in range(j, j + i // 2))):
			print(i)
			exit(0)


s = input()
n = len(s)
k = int(input())
best = 0
if k >= n:
	best = (k + n) // 2 * 2
for st in range(n):
	for ln in range(2, n - st):
		if s[st:st + ln // 2] == s[st + ln // 2:st + ln]:
			best = max(best, ln)
for st1 in range(n):
	if (n + k - st1) % 2 == 0:
		lens = (n + k - st1) // 2
		nlen = lens - k
		st2 = st1 + lens
		if s[st1:st1 + nlen] == s[st2:]:
			best = max(best, lens * 2)
print(best)


s = input()
n = int(input())

def is_tandem(string, half):
	if len(string) <= half:
		return True
	second = string[half:]
	first = string[0:len(second)]
	return first == second
min_len = 0
if n >= len(s):
	min_len = (len(s) + n) // 2 * 2
for i in range(n, len(s) + 1, 2):
	total_len = i + n
	half = total_len // 2
	sub_str = s[len(s) - i:]
	if is_tandem(sub_str, half):
		min_len = i + n
if min_len < len(s):
	for i in range(len(s)):
		for j in range(i + 2, len(s) + 1, 2):
			sub_str = s[i:j]
			half = (j - i) // 2
			if is_tandem(sub_str, half) and len(sub_str) > min_len:
				min_len = len(sub_str)
print(min_len)


3
import sys
s = sys.stdin.readline().strip()
k = int(sys.stdin.readline())
s += '*' * k

def is_tandem(s):
	n = len(s) // 2
	(a, b) = (s[:n], s[n:])
	for i in range(n):
		if a[i] == '*' or b[i] == '*':
			continue
		if a[i] != b[i]:
			return False
	return True
l = 0
for i in range(len(s)):
	for n in range(2, len(s) - i + 1, 2):
		if is_tandem(s[i:i + n]):
			l = max(l, n)
print(l)


def readln():
	return tuple(map(int, input().split()))
import sys
s = input()
(k,) = readln()
s += '?' * k
ans = len(s) // 2 * 2
while ans:
	for i in range(len(s) - ans + 1):
		flag = True
		for j in range(i, i + ans // 2):
			flag = flag and (s[j] == s[j + ans // 2] or s[j + ans // 2] == '?')
		if flag:
			print(ans)
			return
	ans -= 2


s = input()
k = int(input())
n = len(s)
ans = min(2 * k, 2 * n)
start = min(k + 1, n + 1)
end = (n + k) // 2 + 1
for i in range(start, end):
	flag = True
	for j in range(n - 1, max(-1, n - (i - k) - 1), -1):
		if s[j] != s[j - i]:
			flag = False
			break
	if flag:
		ans = 2 * i
for l in range(n):
	for d in range(n - l):
		if l + 2 * d <= n and s[l:l + d] == s[l + d:l + 2 * d]:
			ans = max(ans, d * 2)
print(ans)


def main():
	s = input()
	k = int(input())
	s += '?' * k
	N = len(s)
	result = 0
	for l in range(1, N):
		count = 0
		for i in range(N - l):
			if s[i] == s[i + l] or s[i + l] == '?':
				count += 1
				if count == l:
					result = l
					break
			else:
				count = 0
	print(result * 2)
main()


def tandem(s):
	n = len(s) // 2
	for i in range(n):
		if s[i] != s[i + n] and s[i] != '#' and (s[i + n] != '#'):
			return False
	return True

def main():
	s = input()
	k = int(input())
	s = s + '#' * k
	n = len(s)
	ans = 0
	for i in range(n):
		for j in range(i + 2, n + 1, 2):
			if tandem(s[i:j]):
				ans = max(ans, j - i)
	print(ans)
main()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	s = si()
	k = ii()
	n = len(s)
	for i in range(k):
		s += '?'
	mx = 0
	for i in range(1, n // 2 + 1):
		for j in range(n):
			if j + 2 * i - 1 <= n:
				if s[j:j + i] == s[j + i:j + 2 * i]:
					mx = 2 * i
					break
	l = len(s)
	mx = max(k // 2 * 2, mx)
	for i in range(n):
		for j in range(l // 2):
			if s[i + j] == s[i + j + l // 2]:
				continue
			elif s[i + j] != s[i + j + l // 2] and s[i + j + l // 2] == '?':
				mx = max(mx, l // 2 * 2)
				break
			else:
				break
		l -= 1
	print(mx)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def max_len(s):
	N = len(s)
	for L in range(N // 2, 0, -1):
		for i in range(N - 2 * L + 1):
			if all((ch2 in ch1 + '_' for (ch1, ch2) in zip(s[i:i + L], s[i + L:i + 2 * L]))):
				return 2 * L
print(max_len(input() + '_' * int(input())))


s = input()
k = int(input())
s = s + '?' * k
for i in range(len(s) // 2 + 1):
	a = [0] * len(s)
	for j in range(len(s) - i):
		if s[j] == s[j + i] or s[j + i] == '?':
			a[j] = 1
	c = 0
	mx = 0
	for j in a:
		if j == 1:
			c += 1
		else:
			mx = max(mx, c)
			c = 0
	if mx >= i:
		ans = i * 2
print(ans)


def tandem(s, start, l, max_len, n):
	if start >= n:
		if max_len - start >= 2 * l:
			return True
		return False
	if max_len - start < 2 * l:
		return False
	for i in range(start, start + l):
		si = s[start]
		if i + l > max_len:
			return False
		if i + l < len(s) and s[i] != s[i + l]:
			return False
	return True

def found(s, l, max_len):
	if l == 0:
		return True
	n = len(s)
	l = l // 2
	for i in range(1, n):
		start = i
		if tandem(s, start, l, max_len, n):
			return True
		while len(s) != n:
			s.pop()
	return False

def solve(s, k):
	max_len = 2 * ((len(s) + k) // 2)
	s1 = [0]
	s1.extend(s)
	s = s1[:]
	while True:
		if found(s, max_len, len(s) + k):
			print(max_len)
			return
		max_len -= 2

def main():
	s = list(input())
	k = int(input())
	solve(s, k)
main()


s = input().rstrip()
k = int(input())
if k > len(s):
	print(len(s) + k - ((len(s) + k) % 2 == 1))
else:
	aux = []
	for j in range(1, len(s)):
		i = len(s) - 1
		cnt = 0
		while i - j >= 0 and s[i] == s[i - j]:
			i -= 1
			cnt += 1
			if cnt == j:
				break
		diff = i - (len(s) - j - 1)
		if diff <= k:
			aux.append(2 * j)
	aux.append(2 * k)
	for i in range(len(s)):
		for j in range((len(s) - i) // 2):
			if s[i:i + j] == s[i + j:i + 2 * j]:
				aux.append(2 * j)
	print(max(aux))


(t, k) = (input(), int(input()))
n = len(t)
s = min(k, (n + k) // 2)
for i in range(n - k):
	for j in range(i + s + 1, min(n, (n + i + k) // 2 + 1)):
		d = j - i
		if n - j > d:
			if t[i:j] == t[j:j + d]:
				s = d
		elif t[i:n - d] == t[j:n]:
			s = d
print(2 * s)


st = input()
num = int(input())
maxlen = 0
for start in range(len(st) + num):
	for end in range(start + 1, len(st) + num, 2):
		middle = (end + start + 1) // 2
		ans = True
		for it in range(min(len(st) - middle, end - middle)):
			if st[start + it] != st[middle + it]:
				ans = False
				break
		if ans:
			maxlen = max(maxlen, end - start + 1)
print(maxlen)


def tandem(n, a, i):
	for k in range(i, i + n):
		if a[k] != a[k + n] and a[k + n] != '??':
			return 0
	return 1
s = list(input().strip())
k = int(input())
s += ['??' for i in range(k)]
res = 0
for i in range(len(s)):
	for n in range(1, (len(s) - i) // 2 + 1):
		if tandem(n, s, i):
			res = max(res, n * 2)
print(res)


def equal(x, y):
	for i in range(len(x)):
		if x[i] != y[i] and '?' not in x[i] + y[i]:
			return False
	return True
s = input()
r = 1
for i in range(len(s) - 1):
	j = (len(s) - i) // 2
	while j >= 0:
		if s[i:i + j] == s[i + j:i + 2 * j]:
			r = max(r, j)
			break
		j -= 1
n = int(input())
if len(s) + n & 1 == 1:
	s = s[1:]
s += '?' * n
n = len(s)
for i in range(0, len(s), 2):
	if equal(s[i:n // 2 + i // 2], s[n // 2 + i // 2:]):
		print(max(n - i, r * 2))
		exit()


s = input()
k = int(input())
s += '?' * k
n = len(s)
res = 0
for i in range(n):
	for j in range(i + 1, n):
		d = j - i + 1
		if d % 2 != 0:
			continue
		valid = True
		for e in range(i, j + 1):
			if e + d // 2 > j:
				break
			if s[e] == '?' or s[e + d // 2] == '?' or s[e] == s[e + d // 2]:
				continue
			valid = False
		if valid:
			res = max(res, d)
print(res)


s = input() + 'X' * int(input())
for v in range(len(s) - len(s) % 2, 0, -2):
	for i in range(len(s) - v + 1):
		if all((s[j + v // 2] in ('X', s[j]) for j in range(i, i + v // 2))):
			(print(v), exit())


s = input()
k = int(input())
ans = 0

def get_max_tandem_repeat(s, n):
	while n > 0:
		for i in range(len(s) - 2):
			if i + 2 * n > len(s):
				n -= 1
				break
			flag = True
			for j in range(i, i + n):
				if s[j] != s[j + n] and s[j + n] != '_':
					flag = False
					break
			if flag:
				return n * 2
if k >= len(s):
	ans = (k + len(s)) // 2 * 2
else:
	s = s + '_' * k
	n = len(s) // 2
	ans = get_max_tandem_repeat(s, n)
print(ans)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))

def fn(l):
	for i in range(n - l + 1):
		f = 1
		for j in range(i, i + l // 2):
			if a[j] == a[j + l // 2] or a[j + l // 2] == ' ':
				continue
			f = 0
			break
		if f == 1:
			return True
	return False
for m in range(1):
	s = list(input())
	n = len(s)
	k = nmbr()
	n = n + k
	a = s + [' '] * k
	ans = 0
	for l in range(2, n + 1, 2):
		if fn(l):
			ans = max(ans, l)
	print(ans)


s = input()
k = int(input())
m = len(s) + k
ans = 0
if k >= len(s):
	ans = m - m % 2
for x in range(len(s) // 2 + 1, 0, -1):
	for y in range(len(s) - 2 * x):
		if s[y:y + x] == s[y + x:y + 2 * x]:
			ans = max(ans, 2 * x)
for l in range(m // 2, 0, -1):
	c = s[m - 2 * l:m - l]
	if c[:l - k] == s[m - l:]:
		ans = max(ans, 2 * l)
		break
print(ans)


s = input()
k = int(input())
le = len(s) + k
m = 0
for i in range(len(s)):
	j = 1
	while i + 2 * j <= le:
		mi = i + j
		la = i + 2 * j
		if mi >= len(s):
			m = max(m, j)
		if la <= len(s) and s[i:mi] == s[mi:la]:
			m = max(m, j)
		if mi < len(s):
			xl = len(s) - mi
			if s[i:i + xl] == s[mi:len(s)]:
				m = max(m, j)
		j += 1
print(2 * m)


def equal(a, b):
	for i in range(len(a)):
		if a[i] != b[i] and a[i] != '*' and (b[i] != '*'):
			return False
	return True
(string, k, best) = (input().strip(), int(input()), 0)
string += '*' * k
for i in range(len(string) + 1):
	for j in range(i + 1, len(string) + 1):
		if not (j - i) % 2:
			if equal(string[i:(i + j) // 2], string[(i + j) // 2:j]):
				best = max(best, j - i)
print(best)


def match(str1, str2):
	for t in range(len(str1)):
		if str1[t] != str2[t] and str2[t] != '_':
			return False
	return True
string = input()
k = int(input())
length = len(string)
mark = False
if k >= length:
	print(2 * int((length + k) / 2))
else:
	s = string + k * '_'
	n = int(len(s) / 2)
	for i in range(n, 0, -1):
		for j in range(len(s) - 2 * i + 1):
			if match(s[j:i + j], s[i + j:i + i + j]) and mark == False:
				print(2 * i)
				mark = True


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def check(a, b):
	i = 0
	while i < len(a):
		if a[i] == '-' or b[i] == '-':
			pass
		elif a[i] != b[i]:
			return False
		i += 1
	return True
s = input()
k = Int()
n = len(s)
s += '-' * k
n += k
ans = 0
for i in range(0, n):
	for j in range(i, -1, -1):
		l = i + 1 - j
		if l % 2:
			continue
		a = s[j:j + l // 2]
		b = s[j + l // 2:i + 1]
		flag = check(a, b)
		if flag:
			ans = max(ans, l)
print(ans)


a = input()
b = int(input())
j = 0
l = 0
for start in range(len(a) + b):
	for end in range(start + 1, len(a) + b):
		if (end - start + 1) % 2 == 0:
			middle = (start + end) // 2 + 1
			k = 0
			for traverse in range(start, len(a)):
				if k + middle >= len(a) or k + middle > end:
					j = end - start + 1
					if j > l:
						l = j
				elif k + middle < len(a) and a[traverse] != a[middle + k]:
					break
				elif k + middle < len(a) and a[traverse] == a[middle + k]:
					k += 1
print(l)


def solve():
	str1 = input()
	num = int(input())
	str2 = str1 + '0' * num
	ans = num / 2
	length = len(str2)
	for i in range(length):
		for j in range(2, length + 1, 2):
			if i + j <= length:
				lstr = str2[i:i + j // 2]
				rstr = str2[i + j // 2:i + j]
				ok = True
				for k in range(j // 2):
					if lstr[k] == rstr[k] or rstr[k] == '0':
						pass
					else:
						ok = False
				if ok:
					ans = max(ans, j)
	print(ans)
solve()


s = input()
k = int(input())
ans = 0
for l in range(1, (len(s) + k) // 2 + 1):
	cur = s + 'a' * k
	cur = ''.join((cur[i] if i < max(l, len(s)) else cur[i - l] for i in range(len(s) + k)))
	check = ''.join(('01'[cur[i] == cur[i + l]] for i in range(len(s) + k - l)))
	if '1' * l in check:
		ans = max(ans, l)
print(2 * ans)


s = [*input()]
k = int(input())
s.extend(['?'] * k)
m = 0
for i in range(1, len(s) // 2 + 1):
	for j in range(len(s) - 2 * i + 1):
		q = 0
		for k in range(i):
			if s[j + k] == '?' or s[j + k + i] == '?':
				continue
			if s[j + k] != s[j + k + i]:
				q = 1
				break
		if q:
			continue
		else:
			m = i
			break
print(2 * m)


def solve():
	s = input()
	k = int(input())
	len_s = len(s)
	len_f = len_s + k
	max_n = int(len_f / 2)
	for i in range(max_n, 0, -1):
		for j in range(len_f):
			if len_f - j >= 2 * i:
				ok = True
				for k in range(j, j + i):
					if k + i < len_s and s[k] != s[k + i]:
						ok = False
				if ok:
					print(i * 2)
					return
solve()


(s, r) = (input(), int(input()))

def compare(a, b):
	return a[:len(b)] == b

def f(s, n, N):
	if not s or n < 2 * N:
		return N
	for i in range(n // 2, 0, -1):
		if compare(s[:i], s[i:2 * i]):
			return f(s[1:], n - 1, max(i, N))
	return f(s[1:], n - 1, N)
if len(s) < r:
	print((len(s) + r) // 2 * 2)
else:
	print(2 * f(s, len(s) + r, 0))


def tandemRepeat(i, j):
	a = s[i:i + j - 1]
	b = s[i - j:i - 1]
	for k in range(len(a)):
		if a[k] == b[k] or a[k] == '*' or b[k] == '*':
			continue
		else:
			return False
	return True
s = input()
n = int(input())
s = s + '*' * n
ans = -1
for i in range(len(s)):
	for j in range(1, len(s)):
		if i + j - 1 < len(s) and i - j >= 0 and tandemRepeat(i, j):
			if ans < j:
				ans = j
print(ans * 2)


s = str(input())
k = int(input())
a = 0

def tandem(string):
	if len(string) % 2 == 1:
		return False
	elif string[:len(string) // 2] == string[len(string) // 2:]:
		return True
	else:
		return False
if len(s) <= k:
	a = 2 * ((len(s) + k) // 2)
else:
	a = 2 * k
for i in range(0, len(s) - 1):
	for j in range(i + 1, len(s)):
		if tandem(s[i:j + 1]):
			a = max(a, j - i + 1)
for i in range(len(s) - 1):
	if s[i] == s[-1]:
		x = 0
		while i - x >= 0:
			if s[i - x] == s[-1 - x] and i + x < len(s):
				x += 1
			else:
				break
		if len(s) - i - x - 1 <= k:
			a = max(a, 2 * (len(s) - i - 1))
print(a)