Solve longest_lines (moderate)