added LCS algorithm code to script
version that takes too long
finally solved long and cleaned up code