Condition to check if first row was painted in previous column
elif ( prev == 1 ) : NEW_LINE INDENT vis [ col ] = True NEW_LINE res += ( ( helper ( col + 1 , 0 , painted + 1 , 2 , N , P , K ) ) % mod ) NEW_LINE res += ( ( helper ( col + 1 , 0 , painted + 1 , 3 , N , P , K ) ) % mod ) NEW_LINE vis [ col ] = False NEW_LINE if ( prevCol + 1 < P ) : NEW_LINE INDENT res += ( ( helper ( col + 1 , prevCol + 1 , painted , 0 , N , P , K ) ) % mod ) NEW_LINE DEDENT DEDENT