Selecting the width of rectangle so that difference between any two number is 1 only . Here width is selected so now flag is again unset for next rectangle
else if ( ( $ a [ $ i ] == $ a [ $ i + 1 ] or $ a [ $ i ] - $ a [ $ i + 1 ] == 1 ) and ( $ flag ) ) {