



import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


lowerCAmelCase__		:     List[str]       						='''\
    Text data.
    Second line of data.'''

lowerCAmelCase__		:     Tuple       						='''file'''






@pytest.fixture(scope='session'   )
def 	__lowercase   ( a__   )				-> Union[str, Any]:
							__SCREAMING_SNAKE_CASE									=					tmp_path_factory.mktemp('data'   ) / (FILE_PATH + """.zstd""")
							__SCREAMING_SNAKE_CASE									=					bytes(lowerCAmelCase_							,   'utf-8'   )
							with zstd.open(lowerCAmelCase_							,   'wb'   ) as f:
														f.write(lowerCAmelCase_   )
							return path






@pytest.fixture
def 	__lowercase   ( a__   )				-> int:
							with open(os.path.join(tmpfs.local_root_dir							,   lowerCAmelCase_   )							,   'w'   ) as f:
														f.write(lowerCAmelCase_   )
							return FILE_PATH






@pytest.mark.parametrize('compression_format'							,   ['gzip', 'xz', 'zstd']   )
def 	__lowercase   ( a__							,   a__							,   a__							,   a__							,   a__							,   a__   )				-> Any:
							__SCREAMING_SNAKE_CASE									=					{"""gzip""": gz_file, """xz""": xz_file, """zstd""": zstd_path}
							__SCREAMING_SNAKE_CASE									=					input_paths[compression_format]
							__SCREAMING_SNAKE_CASE									=					tmp_path / """cache"""
							__SCREAMING_SNAKE_CASE									=					DownloadConfig(cache_dir=lowerCAmelCase_							,   extract_compressed_file=lowerCAmelCase_   )
							__SCREAMING_SNAKE_CASE									=					cached_path(lowerCAmelCase_							,   download_config=lowerCAmelCase_   )
							with open(lowerCAmelCase_   ) as f:
														__SCREAMING_SNAKE_CASE									=					f.read()
							with open(lowerCAmelCase_   ) as f:
														__SCREAMING_SNAKE_CASE									=					f.read()
							assert extracted_file_content == expected_file_content






@pytest.mark.parametrize('default_extracted'							,   [True, False]   )
@pytest.mark.parametrize('default_cache_dir'							,   [True, False]   )
def 	__lowercase   ( a__							,   a__							,   a__							,   a__							,   a__   )				-> Tuple:
							__SCREAMING_SNAKE_CASE									=					"""custom_cache"""
							__SCREAMING_SNAKE_CASE									=					"""custom_extracted_dir"""
							__SCREAMING_SNAKE_CASE									=					tmp_path / """custom_extracted_path"""
							if default_extracted:
														__SCREAMING_SNAKE_CASE									=					("""downloads""" if default_cache_dir else custom_cache_dir, """extracted""")
							else:
														monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_DIR'							,   lowerCAmelCase_   )
														monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'							,   str(lowerCAmelCase_   )   )
														__SCREAMING_SNAKE_CASE									=					custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

							__SCREAMING_SNAKE_CASE									=					xz_file
							__SCREAMING_SNAKE_CASE									=					(
							    DownloadConfig(extract_compressed_file=lowerCAmelCase_   )
							    if default_cache_dir
							    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir							,   extract_compressed_file=lowerCAmelCase_   )
							)
							__SCREAMING_SNAKE_CASE									=					cached_path(lowerCAmelCase_							,   download_config=lowerCAmelCase_   )
							assert Path(lowerCAmelCase_   ).parent.parts[-2:] == expected






def 	__lowercase   ( a__   )				-> Optional[int]:
							# absolute path
							__SCREAMING_SNAKE_CASE									=					str(Path(lowerCAmelCase_   ).resolve()   )
							assert cached_path(lowerCAmelCase_   ) == text_file
							# relative path
							__SCREAMING_SNAKE_CASE									=					str(Path(lowerCAmelCase_   ).resolve().relative_to(Path(os.getcwd()   )   )   )
							assert cached_path(lowerCAmelCase_   ) == text_file






def 	__lowercase   ( a__   )				-> str:
							# absolute path
							__SCREAMING_SNAKE_CASE									=					str(tmp_path.resolve() / '__missing_file__.txt'   )
							with pytest.raises(lowerCAmelCase_   ):
														cached_path(lowerCAmelCase_   )
							# relative path
							__SCREAMING_SNAKE_CASE									=					"""./__missing_file__.txt"""
							with pytest.raises(lowerCAmelCase_   ):
														cached_path(lowerCAmelCase_   )






def 	__lowercase   ( a__   )				-> Any:
							__SCREAMING_SNAKE_CASE									=					get_from_cache(f"""tmp://{tmpfs_file}"""   )
							with open(lowerCAmelCase_   ) as f:
														__SCREAMING_SNAKE_CASE									=					f.read()
							assert output_file_content == FILE_CONTENT






@patch('datasets.config.HF_DATASETS_OFFLINE'							,   lowerCAmelCase_   )
def 	__lowercase   ( )				-> Tuple:
							with pytest.raises(lowerCAmelCase_   ):
														cached_path('https://huggingface.co'   )






@patch('datasets.config.HF_DATASETS_OFFLINE'							,   lowerCAmelCase_   )
def 	__lowercase   ( a__   )				-> List[Any]:
							__SCREAMING_SNAKE_CASE									=					tmp_path_factory.mktemp('data'   ) / """file.html"""
							with pytest.raises(lowerCAmelCase_   ):
														http_get('https://huggingface.co'							,   temp_file=lowerCAmelCase_   )
							with pytest.raises(lowerCAmelCase_   ):
														http_head('https://huggingface.co'   )






@patch('datasets.config.HF_DATASETS_OFFLINE'							,   lowerCAmelCase_   )
def 	__lowercase   ( a__   )				-> Union[str, Any]:
							__SCREAMING_SNAKE_CASE									=					tmp_path_factory.mktemp('data'   ) / """file.html"""
							with pytest.raises(lowerCAmelCase_   ):
														ftp_get('ftp://huggingface.co'							,   temp_file=lowerCAmelCase_   )
							with pytest.raises(lowerCAmelCase_   ):
														ftp_head('ftp://huggingface.co'   )






@patch('datasets.config.HF_DATASETS_OFFLINE'							,   lowerCAmelCase_   )
def 	__lowercase   ( a__   )				-> int:
							__SCREAMING_SNAKE_CASE									=					tmp_path_factory.mktemp('data'   ) / """file.html"""
							with pytest.raises(lowerCAmelCase_   ):
														fsspec_get('s3://huggingface.co'							,   temp_file=lowerCAmelCase_   )
							with pytest.raises(lowerCAmelCase_   ):
														fsspec_head('s3://huggingface.co'   )














def 					snake_case_						(   lowerCAmelCase_				:  list					):

							if len(lowerCAmelCase_					) <= 1:
														return [tuple(lowerCAmelCase_					)]

							__lowercase					:							Any			=   []

							def generate(lowerCAmelCase_				:  int				,				lowerCAmelCase_				:  list					):
														if k == 1:
																					res.append(tuple(arr[:]					)					)
																					return

														generate(k - 1				,				lowerCAmelCase_					)

														for i in range(k - 1					):
																					if k % 2 == 0:  # k is even
																												__lowercase	,	__lowercase					:							List[str]			=   arr[k - 1], arr[i]
																					else:  # k is odd
																												__lowercase	,	__lowercase					:							Any			=   arr[k - 1], arr[0]
																					generate(k - 1				,				lowerCAmelCase_					)

							generate(len(lowerCAmelCase_					)				,				lowerCAmelCase_					)
							return res


if __name__ == "__main__":
	lowerCamelCase       :       Union[str, Any]        =				input('''Enter numbers separated by a comma:\n''').strip()
	lowerCamelCase       :       Optional[Any]        =				[int(item) for item in user_input.split(''',''')]
	print(heaps(arr))