#Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome.

#Example

#For st = "abcdc", the output should be
#buildPalindrome(st) = "abcdcba".

def buildPalindrome(st):

	lista = list(st)
	long = len(lista)
	print(lista)
	#for i in range(long-1,-1,-1):
		# From long-1 to 0
		#lista.append(lista[i])
		#Append the last elements to the end
		#Sth like a mirror effect

	#New length is 2*long
	#Now run the algorithm from the beginning

	currentInd = long -1
	
	for i in range (long):
		#print ('Indice a comparar: ',currentInd,' con letra: ',lista[currentInd])
		#print('Tomamos el indice ',i,' con letra:',lista[i])
		if i >= currentInd:
			#print('Salimos porque se termino el string')
			break
		if lista[i] != lista[currentInd]:
			#print("Son distintas.Agregamos la letra al final")

			#The element is not in the correct position
			#Add element to make a mirrored effect
			lista.insert(long,lista[i])
			#print(lista)
		else:
			currentInd -= 1
			#print('Son iguales. Indice a comparar cambiado!')

	#We get to the end and there was no match
	#The string had no repeted elements
	return ''.join(lista)
