title: c++ program stops in the middle of test cases if pasting test cases all at once, but works if you input the test cases individually
body: <p>Not sure what's going at all, title says it all. When I mean inputting the test cases individually, I mean writing to the console each test case with the keyboard, not just pasting them into the console. The problem I'm trying to solve is <a href="https://codeforces.com/problemset/problem/1335/C" rel="nofollow noreferrer">https://codeforces.com/problemset/problem/1335/C</a>. I'm not sure how to really debug the issue either because when I tried using the debugger for the first test case:</p>
  <pre><code>4
  7
  4 2 4 1 4 3 4
  5
  2 1 5 4 3
  1
  1
  4
  1 1 1 3
  </code></pre>
  <p>The debugger would stop before finishing the last test case as well.</p>
  <pre><code>2
  11
  11 2 10 8 6 2 8 5 10 5 9
  12
  6 7 4 6 2 2 10 9 12 1 8 3
  </code></pre>
  <p>My program also doesn't work for the above test case if you copy and paste it into the console all at once, but if you manually input each test case it works.</p>
  <p>My code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;set&gt;
  
  int main() {
      int t, n, a;
      std::cin &gt;&gt; t;
  
      for (int i = 0; i &lt; t; i++) {
          std::cin &gt;&gt; n;
          std::multiset&lt;int&gt; students;
  
          for (int j = 0; j &lt; n; j++) {
              std::cin &gt;&gt; a;
              students.insert(a);
          }
  
          if (students.size() == 1 || students.size() == 0) {
              std::cout &lt;&lt; 0 &lt;&lt; std::endl;
          } else {
              std::pair&lt;int, int&gt; greatest = std::make_pair(*students.begin(), students.count(*students.begin()));
              for (auto k = ++students.begin(); k != students.end(); ++k) {
                  if (*k != greatest.first &amp;&amp; students.count(*k) &gt; greatest.second) {
                      greatest = std::make_pair(*k, students.count(*k));
                  }
              }
  
              std::multiset&lt;int&gt; tempStudents;
              for (int k = 0; k &lt; greatest.second; ++k) {
                  tempStudents.insert(greatest.first);
              }
  
              for (auto k : students) {
                  if (k != greatest.first &amp;&amp; tempStudents.count(k) == 0) {
                      tempStudents.insert(k);
                  }
              }
  
              students = tempStudents;
  
              int duplicate = greatest.second, unique = students.size() - duplicate;
              if (unique == duplicate) {
                  std::cout &lt;&lt; unique &lt;&lt; std::endl;
              } else if (duplicate &gt; unique) {
                  int compare = (unique + 1) * 2;
                  if (students.size() &gt; compare) {
                      std::cout &lt;&lt; students.size() - compare &lt;&lt; std::endl;
                  } else if (students.size() == compare) {
                      std::cout &lt;&lt; unique + 1 &lt;&lt; std::endl;
                  } else { //duplicate = unique + 1
                      std::cout &lt;&lt; unique &lt;&lt; std::endl;
                  }
              } else {
                  std::cout &lt;&lt; duplicate &lt;&lt; std::endl;
              }
          }
      }
  }
  </code></pre>
  <p>Any thoughts?</p>