#include <algorithm>
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

int main()
{
	std::cout << "Superior code written in the superior C++ language by the superior Enforcer." << std::endl;	
	const std::clock_t startClocks = std::clock();
	const std::string input = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth";
	const std::string reversed = [&] () -> std::string { std::string reversed = input; std::reverse(reversed.begin(), reversed.end()); return reversed; }();
	const std::size_t length = input.length();
	const std::string::const_iterator iteratorInput = input.cbegin();
	const std::string::const_iterator iteratorReversed = reversed.end();
	std::string result;

	for (std::size_t i = 0, longest = 0; length - i > longest; ++i)
	{
		for (std::size_t j = i + longest; j < length + 1; ++j)
		{
			if (std::equal(iteratorInput + i, iteratorInput + j, iteratorReversed - j))
			{
				result = std::string(iteratorInput + i, iteratorInput + j);
				longest = j - i;
			}
		}
	}

	const std::clock_t clocksTaken = std::clock() - startClocks;
	std::cout << "Result: " << result << "." << std::endl;
	std::cout << "Time taken: " << (clocksTaken * 1000 / CLOCKS_PER_SEC) << "ms." << std::endl;
    
        return EXIT_SUCCESS;
}