<codility> solution to flags, min perimeter rectangle