title: Magic Square in Python Debugging
body: <p>Problem originally is in <a href="https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/magic-square" rel="nofollow">this</a> link. I wrote a Python code but I got 64 points (total points is 100) and this indicates that my code has some missing points. I passed 11 of 16 test cases but 5 test cases have problematic for me. Could you say where my code has some missing points and how can I fix it? </p>
  
  <pre><code>import math
  
  m = int(raw_input())
  liste = []
  y_liste = []
  md = 0
  ad = 0
  sum = 0
  sum2 = 0
  
  for k in range(m):
      temp = str(raw_input())
      liste.append(temp)
      liste[k] = liste[k].split(" ")
      liste[k] = [int(i) for i in liste[k]]
  
  for k in range(m):
      md += liste[k][k]
      ad += liste[k][m-k-1]
  
  
  
  if md == ad:
      print 0
  else:
      for k in range(m):
          for l in range(m):
              sum2 += liste[l][k]
              sum += liste[k][l]
          if sum2 != md and -(k+1) is not y_liste:
              y_liste.append(-(k+1))
          if sum != md and (k+1) is not y_liste:
              y_liste.append(k+1)
          sum2 = 0
          sum = 0
  
      if md != ad:
          y_liste.append(0)
      print len(y_liste)
      y_liste.sort()
      for i in y_liste:
          print i
  </code></pre>
  
  <p><strong>Problem Statement</strong></p>
  
  <h1>Magic Square</h1>
  
  <p>Johnny designed a magic square (square of numbers with the same sum for all rows, columns and diagonals i.e. both the main diagonal - meaning the diagonal that leads from the top-left corner towards bottom-right corner - and the antidiagonal - meaning the diagonal that leads from top-right corner towards bottom-left corner). Write a program to test it.</p>
  
  <p><strong>Task</strong><br>
  Write a program that will check if the given square is magic (i.e. has the same sum for all rows, columns and diagonals).</p>
  
  <p><strong>Input</strong><br>
  First line: N , the size of the square (1 &lt;= N &lt;= 600).
  Next N lines: The square, N space separated integers pre line, representing the entries per each row of the square.</p>
  
  <p><strong>Output</strong><br>
  First line: M , the number of lines that do not sum up to the sum of the main diagonal (i.e. the one that contains the first element of the square). If the Square is magic, the program should output 0.
  Next M lines: A sorted (in incremental order ) list of the lines that do not sum up to the sum of the main diagonal. The rows are numbered 1,2,…,N; the columns are numbered -1,-2,…,-N; and the antidiagonal is numbered zero.</p>
  
  <p>Note: There is a newline character at the end of the last line of the output.<br>
  <strong>Sample Input 1</strong><br>
  3<br>
  8 1 6<br>
  3 5 7<br>
  4 9 2<br></p>
  
  <p><strong>Sample Output 1</strong><br>
  0<br></p>
  
  <p><strong>Sample Input 2</strong><br>
  4<br>
  16 3 2 13<br>
  5 10 11 8<br>
  6 9 7 12<br>
  4 15 14 1<br></p>
  
  <p><strong>Sample Output 2</strong><br>
  3<br>
  -2<br>
  -1<br>
  0<br></p>
  
  <p><strong>Explanation of Sample Output 2</strong><br>
  The input square looks as follows:  <a href="http://i.stack.imgur.com/JyMgc.png" rel="nofollow">http://i.stack.imgur.com/JyMgc.png</a>
  (Sorry for link but I cannot add image due to reputation)</p>
  
  <p>The square has 4 rows (labeled from 1 to 4 in orange) and 4 columns (labeled from -1 to -4 in green) as depicted in the image above. The main diagonal and antidiagonal of the square are highlighted in red and blue respectively.<br></p>
  
  <p>The main diagonal has sum = 16 + 10 + 7 +1 = 34.<br>
  The antidiagonal has sum = 13 + 11 + 9 + 4 = 37. This is different to the sum of the main diagonal so value 0 corresponding to the antidiagonal should be reported.<br>
  Row 1 has sum = 16 + 3 + 2 + 13 = 34.<br>
  Row 2 has sum = 5 + 10 + 11 + 8 = 34.<br>
  Row 3 has sum = 6 + 9 + 7 + 12 = 34.<br>
  Row 4 has sum = 4 + 15 + 14 + 1 = 34.<br>
  Column -1 has sum = 16 + 5 + 6 + 4 = 31. This is different to the sum of the main diagonal so value -1 should be reported.<br>
  Column -2 has sum = 3 + 10 + 9 + 15 = 37. This is different to the sum of the main diagonal so value -2 should be reported.<br>
  Column -3 has sum = 2 + 11 + 7 + 14 = 34.<br>
  Column -4 has sum = 13 + 8 + 12 + 1 = 34.<br>
  Based on the above, there are 3 lines that do not sum up to the sum of the elements of the main diagonal. Since they should be sorted in incremental order, the output should be:<br>
  3<br>
  -2<br>
  -1<br>
  0<br></p>