If there is an element after the last element of the sub - matrix then decrement it by 1
if ( $ Y2 + 1 < $ n ) $ mat [ $ X2 ] [ $ Y2 + 1 ] -- ; else if ( $ X2 + 1 < $ n ) $ mat [ $ X2 + 1 ] [ 0 ] -- ; }