#CJam, 58 56 bytes
CJam, 58 56 bytes
I am sure this can be golfed a lot, but here it goes:
L'i'-"-i"]q{+:G$i:XA<X{GiB%_2m8%!+m<XB%gX3%3-z*}?s}*\0=o Try it online here or "+\@N]o}*&input=1 => 113 => -i2123 => i003022 => 302132230 => -i31320130100032 => i2311220321030322113103 => -20223202330203313021301011023230323 => -i01323130203022111323321112122313213130330103202032222223 => -1" rel="nofollow noreferrer">run the complete suite here