title: Segmentation fault when using large number of input data in C++
body: <p>I would like to know the reason behind my code not working in case of large no. of input. Actual this is a problem from codingame.com
  <a href="https://www.codingame.com/ide/puzzle/rock-paper-scissors-lizard-spock" rel="nofollow noreferrer">The problem</a>
  The code is working on previous test cases. But not on the last test case, where the input is large. I would like to complete the problem 100%, but i am stuck at 80% with the last test case.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;map&gt;
  #include &lt;iterator&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  int ventarr[1024][1024];
  
  void add_edge(int u, int v,int N) {
      for(int i =0;i&lt;N;i++){
          if(ventarr[u][i] != 0){
              continue;
          }
          else{
              ventarr[u][i] = v;
              break;
          }
      }
  }
  
  int main()
  {
      map&lt;pair&lt;char,char&gt;,char&gt; rules;
      map&lt;int,int&gt; matrix_player_id;
      map&lt;int,int&gt;:: iterator matrix_player_id_itr;
      vector&lt;int&gt;::iterator player_id_itr;
      vector&lt;char&gt;::iterator player_sign_itr;
      map&lt;pair&lt;char, char&gt;, char&gt;::iterator rules_itr;
      char R,P,C,L,S;
      int key_winner = -1;
      int key_loser = -1;
      int key_final = -1;
  
      rules.insert(make_pair(make_pair('C', 'P'), 'C'));
      rules.insert(make_pair(make_pair('P', 'C'), 'C'));
  
      rules.insert(make_pair(make_pair('P', 'R'), 'P'));
      rules.insert(make_pair(make_pair('R', 'P'), 'P'));
  
      rules.insert(make_pair(make_pair('R', 'L'), 'R'));
      rules.insert(make_pair(make_pair('L', 'R'), 'R'));
  
      rules.insert(make_pair(make_pair('L', 'S'), 'L'));
      rules.insert(make_pair(make_pair('S', 'L'), 'L'));
  
      rules.insert(make_pair(make_pair('S', 'C'), 'S'));
      rules.insert(make_pair(make_pair('C', 'S'), 'S'));
  
      rules.insert(make_pair(make_pair('C', 'L'), 'C'));
      rules.insert(make_pair(make_pair('C', 'C'), 'C'));
  
      rules.insert(make_pair(make_pair('L', 'P'), 'L'));
      rules.insert(make_pair(make_pair('P', 'L'), 'L'));
  
      rules.insert(make_pair(make_pair('P', 'S'), 'P'));
      rules.insert(make_pair(make_pair('S', 'P'), 'P'));
  
      rules.insert(make_pair(make_pair('S', 'R'), 'S'));
      rules.insert(make_pair(make_pair('R', 'S'), 'S'));
  
      rules.insert(make_pair(make_pair('R', 'C'), 'R'));
      rules.insert(make_pair(make_pair('C', 'R'), 'R'));
  
      int N;
      cin &gt;&gt; N; cin.ignore();
      vector&lt;int&gt; player_id;
      vector&lt;char&gt; player_sign;
      for (int i = 0; i &lt; N; i++) {
          int NUMPLAYER;
          char SIGNPLAYER;
          cin &gt;&gt; NUMPLAYER &gt;&gt; SIGNPLAYER; cin.ignore();
          player_id.push_back(NUMPLAYER);
          player_sign.push_back(SIGNPLAYER);
          matrix_player_id.insert(pair&lt;int, int&gt;(i,NUMPLAYER));
      }
      /*copy(player_id.begin(), player_id.end(), ostream_iterator&lt;int&gt;(std::cout, " "));
      cout &lt;&lt; endl;
      copy(player_sign.begin(), player_sign.end(), ostream_iterator&lt;char&gt;(std::cout, " "));*/
      /*for (matrix_player_id_itr = matrix_player_id.begin(); matrix_player_id_itr != matrix_player_id.end(); ++matrix_player_id_itr) { 
          cout &lt;&lt; matrix_player_id_itr-&gt;first
               &lt;&lt; '\t' &lt;&lt; matrix_player_id_itr-&gt;second &lt;&lt;'\n'; 
      } 
      cout &lt;&lt; endl; 
      */
  
      for(int i = 0; i &lt; log10(N)/log10(2); i++){
          for(int j = 0; j &lt; player_id.size(); j++){
              int k = j+1;
              if(player_sign[j] != player_sign[k]){
                  rules_itr = rules.find(make_pair(player_sign[j],player_sign[k]));   
                  if(player_sign[k] == rules_itr-&gt;second){
  
                      for(matrix_player_id_itr = matrix_player_id.begin(); matrix_player_id_itr != matrix_player_id.end(); ++matrix_player_id_itr)
                      {
                              if (matrix_player_id_itr-&gt;second == player_id[k])
                              {
                                  key_winner = matrix_player_id_itr-&gt;first;
                                  break;
                              }
                      }
  
                      add_edge(key_winner,player_id[j],N);
  
                      player_id[j] = 0;
                      player_sign[j] = '0';
  
                  }
                  if(player_sign[j] == rules_itr-&gt;second){
  
                      for(matrix_player_id_itr = matrix_player_id.begin(); matrix_player_id_itr != matrix_player_id.end(); ++matrix_player_id_itr)
                      {
                              if (matrix_player_id_itr-&gt;second == player_id[j])
                              {
                                  key_winner = matrix_player_id_itr-&gt;first;
                                  break;
                              }
                      }
  
                      add_edge(key_winner,player_id[k],N);
  
                      player_id[k] = 0;
                      player_sign[k] = '0';
  
                  }
              }
              else{
                  if(player_id[j] &lt; player_id[k]){
  
                      for(matrix_player_id_itr = matrix_player_id.begin(); matrix_player_id_itr != matrix_player_id.end(); ++matrix_player_id_itr)
                      {
                              if (matrix_player_id_itr-&gt;second == player_id[j])
                              {
                                  key_winner = matrix_player_id_itr-&gt;first;
                                  break;
                              }
                      }
  
                      add_edge(key_winner,player_id[k],N);
  
                      player_id[k] = 0;
                      player_sign[k] = '0';
                  }
                  else{
                      for(matrix_player_id_itr = matrix_player_id.begin(); matrix_player_id_itr != matrix_player_id.end(); ++matrix_player_id_itr)
                      {
                              if (matrix_player_id_itr-&gt;second == player_id[k])
                              {
                                  key_winner = matrix_player_id_itr-&gt;first;
                                  break;
                              }
                      }
  
                      add_edge(key_winner,player_id[j],N);
  
                      player_id[j] = 0;           
                      player_sign[j] = '0';
                  }
              }
              ++j;    
          }
  
          for(int i=0; i&lt;player_id.size(); i++){
                  player_id_itr = find(player_id.begin(), player_id.end(), 0);
                  player_id.erase(player_id_itr);
                  player_sign_itr = find(player_sign.begin(), player_sign.end(), '0');
                  player_sign.erase(player_sign_itr);
          }
          for(int i=0; i&lt;player_id.size(); i++){
              cout &lt;&lt; player_id[i] &lt;&lt; '\t' &lt;&lt; player_sign[i] &lt;&lt; endl;
          }
          cout &lt;&lt; endl;
      }
  
      for(matrix_player_id_itr = matrix_player_id.begin(); matrix_player_id_itr != matrix_player_id.end(); ++matrix_player_id_itr)
      {
           if (matrix_player_id_itr-&gt;second == player_id.front())
           {
              key_final = matrix_player_id_itr-&gt;first;
              break;
           }
      }
      cout &lt;&lt; player_id.front()&lt;&lt; endl;
      for(int i=0;i&lt;N;i++){
          if(ventarr[key_final][i] != 0){
              if(ventarr[key_final][i+1] != 0){
                  cout &lt;&lt; ventarr[key_final][i];
                  cout &lt;&lt; " ";
              }
              else{
                   cout &lt;&lt; ventarr[key_final][i];
              }
          }
          else{
              continue;
          }
      }
  
  }
  
  </code></pre>