build valid connect map list valid connect element connect type element connect valid connect length connect valid connect list valid item valid connect map connect valid item valid item arrai list valid connect map connect valid item valid connect length isn rd column repres connect element type mode element pair mode element pair valid connect mode element pair valid connect valid item add mode element pair rd column repres connect differ type element mode element pair mode element pair valid connect mode element pair valid connect valid item add mode element pair arrai hasn flag indic swap element element add valid connect length revers mode element pair revers mode element pair valid connect revers mode element pair valid connect valid item add revers mode element pair 