title: Illegal Function, Spotify Tech Puzzle
body: <p>I am trying to solve the Spotify Puzzle 'Bilateral' found here: <a href="http://www.spotify.com/us/jobs/tech/bilateral-projects/" rel="nofollow">http://www.spotify.com/us/jobs/tech/bilateral-projects/</a></p>
  
  <p>I have run a bunch of tests on my program and I seem to get the correct output, however upon submitting it, the Puzzle Judge tells me "Illegal Function". </p>
  
  <p>I was wondering if someone would look at my code and see if anything looks like it could be causing this error.</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  struct idnumber
  {
    int num;
    int count;      
  };
  struct team
  {
         int id1;
         int id2;
  };
  void solve(team *team, int size);
  bool duplicate(idnumber id1, idnumber id2[], int size);
  
  
  int main(int argc, char *argv[])
  {
     int m=0; 
     string input;
     team * teams;
     cout&lt;&lt;"Number of teams: ";
     while(!(cin &gt;&gt; m) || cin.peek() != '\n' || m &lt; 1 || m &gt; 10000)
              {
                  cout &lt;&lt; "\n\nPlease enter a valid number of teams: ";
                  cin.clear();
                  cin.ignore();            
              }
     cin.clear();
     cin.ignore();
     teams = new team[m];
     for (int i=0;i&lt;m;i++)
     {
         cout&lt;&lt;"IDs for team " &lt;&lt;i+1 &lt;&lt;": ";
         cin &gt;&gt; teams[i].id1;
         cin &gt;&gt; teams[i].id2;
  
     }
      solve(teams, m);
      delete teams;
      system("PAUSE");
      return EXIT_SUCCESS;
  }
  
  void solve(team *teams,int size)
  {
       int p=0,j=0, size2 = size*2, tempnum=size,count=0;
       idnumber stockholm[size],london[size],tempid,tempid2[size],idlist[size2],id[size2];
       const int FRIEND = 1009;
  
       int temp[size],temp2[size];
  
       for (p=0;p&lt;size;p++)
       {
          stockholm[p].num = teams[p].id1;
          stockholm[p].count = 0;
          london[p].num = teams[p].id2;
          london[p].count = 0;
       }
  
       for (p=0;p&lt;size;p++)
       {
           temp[p] = stockholm[p].num;
           temp2[p] = london[p].num;
       }
  
       for (p=0;p&lt;size;p++)
       {
          for(j=0;j&lt;size;j++)
          {
              if (stockholm[p].num ==  temp[j])
                 stockholm[p].count++;   
  
              if (london[p].num ==  temp2[j])
                 london[p].count++;                 
          }   
       }
  
       for(p=0;p&lt;size;p++)
       {
          id[p] = stockholm[p];
          id[p+size] =  london[p];               
       }
  
       for(p=0;p&lt;=size2;p++)
       { 
          for(j=0;j&lt;size2-1;j++)
          {
             if(id[j+1].count &gt; id[j].count || ((id[j+1].count == id[j].count) &amp;&amp; (id[j+1].num == FRIEND)))
             { 
                tempid = id[j];
                id[j] = id[j+1];
                id[j+1] = tempid;
             }
          }                 
       }
  
       for(p=0;p&lt;size2;p++)
       {
          idlist[p].count = 0;
          idlist[p].num = 9999;    
       }
  
       for(p=0;p&lt;size2;p++)
       {
             if(!duplicate(id[p], idlist, size2))
             {
                if(count&lt;size2)
                {
                   idlist[count] = id[p];
                   count++;
                }
             }                    
       }
       for(p=0;p&lt;size2;p++)
        count=0;
        while(tempnum &gt; 0)
        {
            tempnum -= idlist[count].count;
            count++;          
        }
  
        cout&lt;&lt;count&lt;&lt;"\n";
        for(p=0;p&lt;count;p++)
          cout&lt;&lt;idlist[p].num&lt;&lt;"\n";
  }
  
  
  bool duplicate(idnumber id1, idnumber id2[], int size)
  { 
    bool flag = false;
    for(int i=0;i&lt;size;i++)
    {
       if(id1.num == id2[i].num)
       {                     
          flag = true;
       }
       if(flag)
         break;
    }
    return flag;   
  }
  </code></pre>