rewrite longest substring