<p>You are given an array of strings <code>words</code>. Each element of <code>words</code> consists of <strong>two</strong> lowercase English letters.</p>

<p>Create the <strong>longest possible palindrome</strong> by selecting some elements from <code>words</code> and concatenating them in <strong>any order</strong>. Each element can be selected <strong>at most once</strong>.</p>

<p>Return <em>the <strong>length</strong> of the longest palindrome that you can create</em>. If it is impossible to create any palindrome, return <code>0</code>.</p>

<p>A <strong>palindrome</strong> is a string that reads the same forward and backward.</p>

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

<pre>
<strong>Input:</strong> words = [&quot;lc&quot;,&quot;cl&quot;,&quot;gg&quot;]
<strong>Output:</strong> 6
<strong>Explanation:</strong> One longest palindrome is &quot;lc&quot; + &quot;gg&quot; + &quot;cl&quot; = &quot;lcggcl&quot;, of length 6.
Note that &quot;clgglc&quot; is another longest palindrome that can be created.
</pre>

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

<pre>
<strong>Input:</strong> words = [&quot;ab&quot;,&quot;ty&quot;,&quot;yt&quot;,&quot;lc&quot;,&quot;cl&quot;,&quot;ab&quot;]
<strong>Output:</strong> 8
<strong>Explanation:</strong> One longest palindrome is &quot;ty&quot; + &quot;lc&quot; + &quot;cl&quot; + &quot;yt&quot; = &quot;tylcclyt&quot;, of length 8.
Note that &quot;lcyttycl&quot; is another longest palindrome that can be created.
</pre>

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

<pre>
<strong>Input:</strong> words = [&quot;cc&quot;,&quot;ll&quot;,&quot;xx&quot;]
<strong>Output:</strong> 2
<strong>Explanation:</strong> One longest palindrome is &quot;cc&quot;, of length 2.
Note that &quot;ll&quot; is another longest palindrome that can be created, and so is &quot;xx&quot;.
</pre>

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

<ul>
	<li><code>1 &lt;= words.length &lt;= 10<sup>5</sup></code></li>
	<li><code>words[i].length == 2</code></li>
	<li><code>words[i]</code> consists of lowercase English letters.</li>
</ul>

'''
EDGE CASES:
aa aa bb cc
- can only have 1 odd number

ae ea ea ta at za
- pair up mirrored pairs

DATA STRUC:
symmetric <str: int>
{

}

mirrored1
- put into mirrored2 only if the mirror already exists in mirrored1, otherwise put into mirrored1
{

}
mirrored2

ALGOS:
2-sum like approach where if it doesn't exist, we put in mirrored1
else put in mirrored2

iterate through symmetric and mirrored1 to do final count
'''

class Solution:
    def longestPalindrome(self, words: List[str]) -> int:
        symmetric = {}
        mirrored1 = {}
        mirrored2 = {}
        for w in words:
            flip = w[::-1]
            if flip == w:
                symmetric[w] = symmetric.get(w, 0) + 1
            else:
                if flip in mirrored1:
                    mirrored2[w] = mirrored2.get(w, 0) + 1
                else:
                    mirrored1[w] = mirrored1.get(w, 0) + 1
        res = 0
        print(symmetric)
        print(mirrored1)
        print(mirrored2)
        seen_odd = False
        for w, c in symmetric.items():
            if c % 2 == 1:
                if not seen_odd:
                    res += 2
                    seen_odd = True
                c -= 1
            res += c * 2
        for w, c in mirrored1.items():
            flip = w[::-1]
            res += min(mirrored1[w], mirrored2.get(flip, 0)) * 4
        return res

1134