title: Google Jam test cases passes but submission shows "Wrong Answer"
body: <blockquote>
  <p>Note: The main parts of the statements of the problems &quot;Reversort&quot; and
  &quot;Reversort Engineering&quot; are identical, except for the last paragraph.
  The problems can otherwise be solved independently.</p>
  <p>Reversort is an algorithm to sort a list of distinct integers in
  increasing order. The algorithm is based on the &quot;Reverse&quot; operation.
  Each application of this operation reverses the order of some
  contiguous part of the list.</p>
  <p>After i−1 iterations, the positions 1,2,…,i−1 of the list contain the
  i−1 smallest elements of L, in increasing order. During the i-th
  iteration, the process reverses the sublist going from the i-th
  position to the current position of the i-th minimum element. That
  makes the i-th minimum element end up in the i-th position.</p>
  <p>For example, for a list with 4 elements, the algorithm would perform 3
  iterations. Here is how it would process L=[4,2,1,3]:</p>
  <p>i=1, j=3⟶L=[1,2,4,3] i=2, j=2⟶L=[1,2,4,3] i=3, j=4⟶L=[1,2,3,4] The
  most expensive part of executing the algorithm on our architecture is
  the Reverse operation. Therefore, our measure for the cost of each
  iteration is simply the length of the sublist passed to Reverse, that
  is, the value j−i+1. The cost of the whole algorithm is the sum of the
  costs of each iteration.</p>
  <p>In the example above, the iterations cost 3, 1, and 2, in that order,
  for a total of 6.</p>
  <p>Given the initial list, compute the cost of executing Reversort on it.</p>
  <p>Input The first line of the input gives the number of test cases, T. T
  test cases follow. Each test case consists of 2 lines. The first line
  contains a single integer N, representing the number of elements in
  the input list. The second line contains N distinct integers L1, L2,
  ..., LN, representing the elements of the input list L, in order.</p>
  <p>Output For each test case, output one line containing Case #x: y,
  where x is the test case number (starting from 1) and y is the total
  cost of executing Reversort on the list given as input.</p>
  <p>Limits Time limit: 10 seconds. Memory limit: 1 GB. Test Set 1 (Visible
  Verdict) 1≤T≤100. 2≤N≤100. 1≤Li≤N, for all i. Li≠Lj, for all i≠j.
  Sample Sample Input 3 4 4 2 1 3 2 1 2 7 7 6 5 4 3 2 1 Sample Output
  Case #1: 6 Case #2: 1 Case #3: 12 Sample Case #1 is described in the
  statement above.</p>
  <p>In Sample Case #2, there is a single iteration, in which Reverse is
  applied to a sublist of size 1. Therefore, the total cost is 1.</p>
  <p>In Sample Case #3, the first iteration reverses the full list, for a
  cost of 7. After that, the list is already sorted, but there are 5
  more iterations, each of which contributes a cost of 1.</p>
  </blockquote>
  <pre><code>def Reversort(L):
      sort = 0
      for i in range(len(L)-1):
          small = L[i]
          x = L[i]
          y = L[i]
          for j in range(i, len(L)):
              if L[j] &lt; small :
                  small = L[j]
          sort = sort + (L.index(small) - L.index(y) + 1) 
          L[L.index(small)] = x
          L[L.index(y)] = small
          print(L) #For debugging purpose
      return sort
  
  T = int(input())
  for i in range(T):
      N = int(input())
      L = list(map(int, input().rstrip().split()))
      s = Reversort(L)
      print(f&quot;Case #{i+1}: {s}&quot;)
  </code></pre>