A formation mechanism of magnetic elements in regions of mixed polarity