title: C++, multiset, Time complexity
body: <pre><code>#include&lt;bits/stdc++.h&gt;
  
  int main()
  {
      int n;
      std::cin&gt;&gt;n;
      char st[n];
      getchar();
      for (int i=0; i&lt;n; ++i)
          st[i]=getchar();
      std::multiset&lt;char&gt; s;
      int pos1=0,pos2=n-1;
      for (char c:st) s.insert(c);
      for (int i=0; i&lt;n; ++i) {
          if (s.count(st[i])==1) {
              pos1=i;
              break;
          } else s.erase(s.find(st[i]));
      }
      for (int i=n-1; i&gt;=0; --i) {
          if (s.count(st[i])==1) {
              pos2=i;
              break;
          } else s.erase(s.find(st[i]));
      }
      std::cout&lt;&lt;pos2-pos1+1;
  }
  </code></pre>
  
  <p>I have just summit this code to CodeForces system, and it fail the TL (2s), i dont know why, because n constrain is 10^5. And my code work with O(nlogn). Can u guys help me? Thanks &lt;3&lt;3. Link of problem here : <a href="http://codeforces.com/problemset/problem/701/C" rel="nofollow noreferrer">http://codeforces.com/problemset/problem/701/C</a></p>