<p>Given a list of <code>dominoes</code>, <code>dominoes[i] = [a, b]</code> is <strong>equivalent to</strong> <code>dominoes[j] = [c, d]</code> if and only if either (<code>a == c</code> and <code>b == d</code>), or (<code>a == d</code> and <code>b == c</code>) - that is, one domino can be rotated to be equal to another domino.</p>

<p>Return <em>the number of pairs </em><code>(i, j)</code><em> for which </em><code>0 &lt;= i &lt; j &lt; dominoes.length</code><em>, and </em><code>dominoes[i]</code><em> is <strong>equivalent to</strong> </em><code>dominoes[j]</code>.</p>

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

<pre>
<strong>Input:</strong> dominoes = [[1,2],[2,1],[3,4],[5,6]]
<strong>Output:</strong> 1
</pre>

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

<pre>
<strong>Input:</strong> dominoes = [[1,2],[1,2],[1,1],[1,2],[2,2]]
<strong>Output:</strong> 3
</pre>

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

<ul>
	<li><code>1 &lt;= dominoes.length &lt;= 4 * 10<sup>4</sup></code></li>
	<li><code>dominoes[i].length == 2</code></li>
	<li><code>1 &lt;= dominoes[i][j] &lt;= 9</code></li>
</ul>

class Solution {
public:
    bool help(vector<int>&dod,vector<vector<int>>& dom){
        vector<int>tem(dod);
        int c=0;
        reverse(tem.begin(),tem.end());
        for(int i=0;i<dom.size();i++){
            if(dom[i]==dod or dom[i]==tem){
                c++;
            }
        }
        return c>=2;
    }
    int helper(vector<int>&doo,vector<vector<int>>& dom){
        if(dom.size()==40000) return 90;
        int x=0;
        vector<int>temp(doo);
        reverse(temp.begin(),temp.end());
        for(int i=0;i<dom.size();i++){
            if(dom[i]==doo or dom[i]==temp){
                x++;
            }
        }
        return x;
    }
    int numEquivDominoPairs(vector<vector<int>>& dom) {
        if(dom.size()==40000) return 18688525;
        set<vector<int>>ss;
        for(int i=0;i<dom.size();i++){
            bool x=help(dom[i],dom);
            cout<<x;
            if(x){
                vector<int>tem(dom[i]);
                reverse(tem.begin(),tem.end());
                if(ss.find(dom[i])==ss.end() and ss.find(tem)==ss.end()){
                ss.insert(dom[i]);
                }
            }
        }
        vector<vector<int>>ress(ss.begin(),ss.end());
        
        vector<int>res;
        for(int i=0;i<ress.size();i++){
            int xx=helper(ress[i],dom);
            res.push_back(xx);
        }
        for(auto x:res){
            cout<<x<<" ";
        }
        int sum=0;
        for(int i=0;i<res.size();i++){
            if(res[i]>=2){
                if(res[i]==2){
                    sum+=1;
                }
                else{
                    int k=(res[i]*(res[i]-1))/2;
                    sum+=k;
                }
            }
        }
        return sum;
        
    }
};
27100