




import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam



class    lowercase_		(datasets.BeamBasedBuilder ):



						def 	__a					(			self	:   Any  ):

								"""simple docstring"""

								return datasets.DatasetInfo(
								    features=datasets.Features({'content': datasets.Value('string'  )}  )					,							supervised_keys=snake_case__					,							)



						def 	__a					(			self	:   List[str]					,							snake_case__	:   Union[str, Any]					,							snake_case__	:   Dict  ):

								"""simple docstring"""

								return [datasets.SplitGenerator(name=datasets.Split.TRAIN					,							gen_kwargs={'examples': get_test_dummy_examples()}  )]






						def 	__a					(			self	:   str					,							snake_case__	:   str					,							snake_case__	:   Optional[Any]  ):

								"""simple docstring"""

								import apache_beam as beam

								return pipeline | "Load Examples" >> beam.Create(snake_case__  )



class    lowercase_		(datasets.BeamBasedBuilder ):



						def 	__a					(			self	:   Tuple  ):

								"""simple docstring"""

								return datasets.DatasetInfo(
								    features=datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'  )}  )}  )					,							supervised_keys=snake_case__					,							)



						def 	__a					(			self	:   Any					,							snake_case__	:   Optional[int]					,							snake_case__	:   Union[str, Any]  ):

								"""simple docstring"""

								return [
								    datasets.SplitGenerator(name=datasets.Split.TRAIN					,							gen_kwargs={'examples': get_test_nested_examples()}  )
								]






						def 	__a					(			self	:   Dict					,							snake_case__	:   int					,							snake_case__	:   List[Any]  ):

								"""simple docstring"""

								import apache_beam as beam

								return pipeline | "Load Examples" >> beam.Create(snake_case__  )


def 					_a							(					)->	Dict:
		return [(i, {"content": content}) for i, content in enumerate(['foo', 'bar', 'foobar'] )]


def 					_a							(					)->	Optional[int]:
		return [(i, {"a": {"b": [content]}}) for i, content in enumerate(['foo', 'bar', 'foobar'] )]




class    lowercase_		(SCREAMING_SNAKE_CASE__ ):



						@require_beam
						def 	__a					(			self	:   Union[str, Any]  ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							len(get_test_dummy_examples()  )
								with tempfile.TemporaryDirectory() as tmp_cache_dir:
										SCREAMING_SNAKE_CASE_					      =							DummyBeamDataset(cache_dir=snake_case__					,							beam_runner='DirectRunner'  )
										builder.download_and_prepare()
										self.assertTrue(
										    os.path.exists(
										        os.path.join(snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							f'''{builder.name}-train.arrow'''  )  )  )
										self.assertDictEqual(builder.info.features					,							datasets.Features({'content': datasets.Value('string'  )}  )  )
										SCREAMING_SNAKE_CASE_					      =							builder.as_dataset()
										self.assertEqual(dset['train'].num_rows					,							snake_case__  )
										self.assertEqual(dset['train'].info.splits['train'].num_examples					,							snake_case__  )
										self.assertDictEqual(dset['train'][0]					,							get_test_dummy_examples()[0][1]  )
										self.assertDictEqual(
										    dset['train'][expected_num_examples - 1]					,							get_test_dummy_examples()[expected_num_examples - 1][1]  )
										self.assertTrue(
										    os.path.exists(os.path.join(snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							'dataset_info.json'  )  )  )
										del dset



						@require_beam
						def 	__a					(			self	:   Union[str, Any]  ):

								"""simple docstring"""

								import apache_beam as beam

								SCREAMING_SNAKE_CASE_					      =							beam.io.parquetio.WriteToParquet

								SCREAMING_SNAKE_CASE_					      =							len(get_test_dummy_examples()  )
								with tempfile.TemporaryDirectory() as tmp_cache_dir:
										SCREAMING_SNAKE_CASE_					      =							DummyBeamDataset(cache_dir=snake_case__					,							beam_runner='DirectRunner'  )
										with patch('apache_beam.io.parquetio.WriteToParquet'  ) as write_parquet_mock:
												SCREAMING_SNAKE_CASE_					      =							partial(snake_case__					,							num_shards=2  )
												builder.download_and_prepare()
										self.assertTrue(
										    os.path.exists(
										        os.path.join(
										            snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							f'''{builder.name}-train-00000-of-00002.arrow'''  )  )  )
										self.assertTrue(
										    os.path.exists(
										        os.path.join(
										            snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							f'''{builder.name}-train-00000-of-00002.arrow'''  )  )  )
										self.assertDictEqual(builder.info.features					,							datasets.Features({'content': datasets.Value('string'  )}  )  )
										SCREAMING_SNAKE_CASE_					      =							builder.as_dataset()
										self.assertEqual(dset['train'].num_rows					,							snake_case__  )
										self.assertEqual(dset['train'].info.splits['train'].num_examples					,							snake_case__  )
										# Order is not preserved when sharding, so we just check that all the elements are there
										self.assertListEqual(sorted(dset['train']['content']  )					,							sorted(['foo', 'bar', 'foobar']  )  )
										self.assertTrue(
										    os.path.exists(os.path.join(snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							'dataset_info.json'  )  )  )
										del dset



						@require_beam
						def 	__a					(			self	:   Dict  ):

								"""simple docstring"""

								with tempfile.TemporaryDirectory() as tmp_cache_dir:
										SCREAMING_SNAKE_CASE_					      =							DummyBeamDataset(cache_dir=snake_case__  )
										self.assertRaises(datasets.builder.MissingBeamOptions					,							builder.download_and_prepare  )






						@require_beam
						def 	__a					(			self	:   List[Any]  ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							len(get_test_nested_examples()  )
								with tempfile.TemporaryDirectory() as tmp_cache_dir:
										SCREAMING_SNAKE_CASE_					      =							NestedBeamDataset(cache_dir=snake_case__					,							beam_runner='DirectRunner'  )
										builder.download_and_prepare()
										self.assertTrue(
										    os.path.exists(
										        os.path.join(snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							f'''{builder.name}-train.arrow'''  )  )  )
										self.assertDictEqual(
										    builder.info.features					,							datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'  )}  )}  )  )
										SCREAMING_SNAKE_CASE_					      =							builder.as_dataset()
										self.assertEqual(dset['train'].num_rows					,							snake_case__  )
										self.assertEqual(dset['train'].info.splits['train'].num_examples					,							snake_case__  )
										self.assertDictEqual(dset['train'][0]					,							get_test_nested_examples()[0][1]  )
										self.assertDictEqual(
										    dset['train'][expected_num_examples - 1]					,							get_test_nested_examples()[expected_num_examples - 1][1]  )
										self.assertTrue(
										    os.path.exists(os.path.join(snake_case__					,							builder.name					,							'default'					,							'0.0.0'					,							'dataset_info.json'  )  )  )
										del dset





SCREAMING_SNAKE_CASE:     dict[tuple[int, int, int], int]									= {}


def 					_a							(					lowerCAmelCase    ,						lowerCAmelCase    ,						lowerCAmelCase )->	int:

		# if we are absent twice, or late 3 consecutive days,
		# no further prize strings are possible
		if late == 3 or absent == 2:
				return 0

		# if we have no days left, and have not failed any other rules,
		# we have a prize string
		if days == 0:
				return 1

		# No easy solution, so now we need to do the recursive calculation

		# First, check if the combination is already in the cache, and
		# if yes, return the stored value from there since we already
		# know the number of possible prize strings from this point on
		SCREAMING_SNAKE_CASE_					      =							(days, absent, late)
		if key in cache:
				return cache[key]

		# now we calculate the three possible ways that can unfold from
		# this point on, depending on our attendance today

		# 1) if we are late (but not absent), the "absent" counter stays as
		# it is, but the "late" counter increases by one
		SCREAMING_SNAKE_CASE_					      =							_calculate(days - 1    ,						lowerCAmelCase    ,						late + 1 )

		# 2) if we are absent, the "absent" counter increases by 1, and the
		# "late" counter resets to 0
		SCREAMING_SNAKE_CASE_					      =							_calculate(days - 1    ,						absent + 1    ,						0 )

		# 3) if we are on time, this resets the "late" counter and keeps the
		# absent counter
		SCREAMING_SNAKE_CASE_					      =							_calculate(days - 1    ,						lowerCAmelCase    ,						0 )

		SCREAMING_SNAKE_CASE_					      =							state_late + state_absent + state_ontime

		SCREAMING_SNAKE_CASE_					      =							prizestrings
		return prizestrings


def 					_a							(					lowerCAmelCase = 30 )->	int:
		return _calculate(lowerCAmelCase    ,						absent=0    ,						late=0 )


if __name__ == "__main__":
						print(solution())