title: please help me in finding all the counts of beautiful permutation
body: <p>With an array consisting of integers where each integer occurs at most 2 times in the array, I have to count the number of beautiful permutations.</p>
  <p>A permutation is beautiful if there is no index <em>i</em> such that P<sub>i</sub> = P<sub>i+1</sub> where <em>i</em> belongs to [0, n-1).</p>
  <pre><code>struct hashFunction
  {
      size_t operator()(const vector&lt;int&gt;&amp; myVector) const
      {
          std::hash&lt;int&gt; hasher;
          size_t answer = 0;
          for (int i : myVector)
          {
              answer ^= hasher(i) + 0x9e3779b9 +
                  (answer &lt;&lt; 6) + (answer &gt;&gt; 2);
          }
          return answer;
      }
  };
  
  bool beautiful(vector&lt;int&gt;&amp; ds)
  {
      for (int i = 0; i &lt; ds.size(); i++)
      {
          if (ds[i] == ds[i + 1])
          {
              return false;
          }
      }
      return true;
  }
  
  void permutation(vector&lt;int&gt;&amp; arr, int index,
      unordered_set&lt;vector&lt;int&gt;, hashFunction&gt;&amp; unorderedsetOfVectors)
  {
      if (unorderedsetOfVectors.find(arr) != unorderedsetOfVectors.end()) return;
      if (index == arr.size())
      {
          if (beautiful(arr) == true)
          {
              unorderedsetOfVectors.insert(arr);
              return;
          }
      }
  
      for (int i = index; i &lt; arr.size(); i++)
      {
          swap(arr[index], arr[i]);
          permutation(arr, index + 1, unorderedsetOfVectors);
          swap(arr[index], arr[i]);
      }
  }
  
  int permutations(vector&lt;int&gt; arr)
  {
      unordered_set&lt;vector&lt;int&gt;, hashFunction&gt; unorderedsetOfVectors;
      permutation(arr, 0, unorderedsetOfVectors);
      return unorderedsetOfVectors.size() % 1000000007;
  }
  </code></pre>
  <p>How can I optimize this code?</p>