Function to the find element at ( i , j ) index
def findInGrid ( i , j ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT return ( i * i - ( i - 1 ) ) NEW_LINE DEDENT elif ( i > j ) : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT return i * i - ( j - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( ( i - 1 ) * ( i - 1 ) + 1 + ( j - 1 ) ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( j % 2 == 0 ) : NEW_LINE INDENT return ( ( j - 1 ) * ( j - 1 ) + 1 + ( i - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return j * j - ( i - 1 ) NEW_LINE DEDENT DEDENT DEDENT