title: difference between Python's bisect.bisect_left and C++'s std::upper_bound
body: <p>I have encountered a question:<br>
  Given two arrays X and Y of positive integers, find number of pairs such that x^y > y^x (raised to power of) where x is an element from X and y is an element from Y.</p>
  
  <p>I tried to make the following code:</p>
  
  <pre><code>#code
  import bisect
  
  def pairs(ar1,ar2,n,m):
      count=0
      zeros=ar2.count(0)
      ones=ar2.count(1)
      twos=ar2.count(2)
      threes=ar2.count(3)
      fours=ar2.count(4)
      for x in ar1:
          if x==0:
              continue
  
          elif x==1:
              count+=zeros
              continue
  
          idx=bisect.bisect_left(ar2,x)
          if idx&lt;m:
              if ar2[idx]==x:
                  count+=m-idx-1
              else:
                  count+=m-idx
  
          count+=zeros+ones
  
          if x==2:
              count-=threes+fours
  
          if x==3:
              count+=twos
  
      return count
  </code></pre>
  
  <p>but some test cases aren't<br>
  I have tried to emulate this code from C++</p>
  
  <pre><code>int count(int x, int Y[], int n, int NoOfY[])
  {
      if (x == 0) return 0;
      if (x == 1) return NoOfY[0];
      int* id = upper_bound(Y, Y + n, x);
      cout &lt;&lt; x&lt;&lt;"  "&lt;&lt;*id&lt;&lt;endl;
      int ans = (Y + n) - id;
      ans += (NoOfY[0] + NoOfY[1]);
      if (x == 2)  ans -= (NoOfY[3] + NoOfY[4]);
      if (x == 3)  ans += NoOfY[2];
      return ans;
  }
  int countPairs(int X[], int Y[], int m, int n)
  {
      int NoOfY[5] = {0};
      for (int i = 0; i &lt; n; i++)
          if (Y[i] &lt; 5)
              NoOfY[Y[i]]++;
      sort(Y, Y + n);
      int total_pairs = 0; 
      for (int i=0; i&lt;m; i++)
          total_pairs += count(X[i], Y, n, NoOfY);
      return total_pairs;
  }
  </code></pre>
  
  <p>Please Help</p>