Condition to check if second row was painted in previous column
else if ( prev == 2 ) { vis [ col ] = true ; res += ( helper ( col + 1 , 0 , painted + 1 , 1 , N , P , K ) ) % mod ; res += ( helper ( col + 1 , 0 , painted + 1 , 3 , N , P , K ) ) % mod ;