<p>Given two strings <code>s1</code> and&nbsp;<code>s2</code>, return <em>the lowest <strong>ASCII</strong> sum of deleted characters to make two strings equal</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s1 = &quot;sea&quot;, s2 = &quot;eat&quot;
<strong>Output:</strong> 231
<strong>Explanation:</strong> Deleting &quot;s&quot; from &quot;sea&quot; adds the ASCII value of &quot;s&quot; (115) to the sum.
Deleting &quot;t&quot; from &quot;eat&quot; adds 116 to the sum.
At the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s1 = &quot;delete&quot;, s2 = &quot;leet&quot;
<strong>Output:</strong> 403
<strong>Explanation:</strong> Deleting &quot;dee&quot; from &quot;delete&quot; to turn the string into &quot;let&quot;,
adds 100[d] + 101[e] + 101[e] to the sum.
Deleting &quot;e&quot; from &quot;leet&quot; adds 101[e] to the sum.
At the end, both strings are equal to &quot;let&quot;, and the answer is 100+101+101+101 = 403.
If instead we turned both strings into &quot;lee&quot; or &quot;eet&quot;, we would get answers of 433 or 417, which are higher.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s1.length, s2.length &lt;= 1000</code></li>
	<li><code>s1</code> and <code>s2</code> consist of lowercase English letters.</li>
</ul>

class Solution:
    def minimumDeleteSum(self, s1: str, s2: str) -> int:
    #     lcs = self.longest_common_subsequence(s1, s2)

    #     return sum([ord(c) for c in s1 + s2]) - 2 * sum([ord(c) for c in lcs])

    # def longest_common_subsequence(self, text1: str, text2: str) -> int:
    #     m = len(text1)
    #     n = len(text2)
    #     dp = [[0] * (n + 1) for _ in range(m + 1)]
    #     for i in range(m):
    #         for j in range(n):
    #             if text1[i] == text2[j]:
    #                 dp[i + 1][j + 1] = dp[i][j] + ord(text1[i])
    #             else:
    #                 dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

    #     res = deque()
    #     i = m - 1
    #     j = n - 1
    #     while i >= 0 and j >= 0:
    #         if text1[i] == text2[j]:
    #             res.appendleft(text1[i])

    #             i -= 1
    #             j -= 1
    #         elif dp[i][j + 1] > dp[i + 1][j]:
    #             i -= 1
    #         else:
    #             j -= 1

    #     return ''.join(res)

        return sum([ord(c) for c in s1 + s2]) - 2 * self.longest_common_subsequence(s1, s2)

    def longest_common_subsequence(self, text1: str, text2: str) -> int:
        @cache
        def dp(i, j):
            if i < 0 or j < 0:
                return 0

            if text1[i] == text2[j]:
                return dp(i - 1, j - 1) + ord(text1[i])
            else:
                return max(dp(i - 1, j), dp(i, j - 1))

        return dp(len(text1) - 1, len(text2) - 1)
    
76355