

import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)






class 							A_				:


     def __init__(							self    :	Union[str, Any]    ,						UpperCAmelCase    :	List[Any]      )							->			int:
      __lowerCAmelCase:     Union[str, Any]     			=   foo


     def __call__(							self    :	List[Any]      )							->			Optional[Any]:
      return self.foo







class 							A_				(	datasets.Dataset      ):


     @fingerprint_transform(inplace=UpperCAmelCase      )
     def 						UpperCAmelCase						(							self    :	int    ,						UpperCAmelCase    :	Optional[int]    ,						*UpperCAmelCase    :	Dict    ,						**UpperCAmelCase    :	int      )							->			List[str]:
      return DatasetChild(self.data    ,						fingerprint=UpperCAmelCase      )


     @fingerprint_transform(inplace=UpperCAmelCase      )
     def 						UpperCAmelCase						(							self    :	Tuple    ,						UpperCAmelCase    :	Tuple    ,						*UpperCAmelCase    :	Union[str, Any]    ,						**UpperCAmelCase    :	Any      )							->			Tuple:
      return DatasetChild(self.data    ,						fingerprint=UpperCAmelCase      )







class 							A_				:


     def __init__(							self    :	List[Any]    ,						UpperCAmelCase    :	List[Any]      )							->			Optional[Any]:
      __lowerCAmelCase:     Dict     			=   callable


     def __call__(							self    :	Dict    ,						*UpperCAmelCase    :	List[Any]    ,						**UpperCAmelCase    :	Any      )							->			int:
      if self.callable is not None:
       return self.callable(*UpperCAmelCase    ,						**UpperCAmelCase      )


     def __getstate__(							self    :	int      )							->			Union[str, Any]:
      raise pickle.PicklingError()







class 							A_				(	snake_case__      ):


     @require_transformers
     @pytest.mark.integration
     def 						UpperCAmelCase						(							self    :	Optional[int]      )							->			List[str]:
      from transformers import AutoTokenizer

      def encode(UpperCAmelCase    :	Any      ):
       return tokenizer(UpperCAmelCase      )

      # TODO: add hash consistency tests across sessions
      __lowerCAmelCase:     Dict     			=   AutoTokenizer.from_pretrained('bert-base-uncased'      )
      __lowerCAmelCase:     Optional[Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(lambda UpperCAmelCase      : tokenizer(UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase:     int     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     List[Any]     			=   AutoTokenizer.from_pretrained('bert-base-cased'      )
      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     str     			=   mda(datasets.utils.py_utils.dumps(lambda UpperCAmelCase      : tokenizer(UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase:     Tuple     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     List[Any]     			=   AutoTokenizer.from_pretrained('bert-base-uncased'      )
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     List[Any]     			=   mda(datasets.utils.py_utils.dumps(lambda UpperCAmelCase      : tokenizer(UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase:     int     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     @require_transformers
     @pytest.mark.integration
     def 						UpperCAmelCase						(							self    :	Dict      )							->			int:
      from transformers import AutoTokenizer

      __lowerCAmelCase:     str     			=   AutoTokenizer.from_pretrained('gpt2'      )
      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      tokenizer('Hello world !'      )  # call once to change the tokenizer's cache
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     @require_regex
     def 						UpperCAmelCase						(							self    :	Dict      )							->			Tuple:
      import regex

      __lowerCAmelCase:     Dict     			=   regex.Regex('foo'      )
      __lowerCAmelCase:     str     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Optional[int]     			=   regex.Regex('bar'      )
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     int     			=   regex.Regex('foo'      )
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )







class 							A_				(	snake_case__      ):


     def 						UpperCAmelCase						(							self    :	List[str]      )							->			Any:
      def func():
       return foo

      __lowerCAmelCase:     Any     			=   [0]
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Any     			=   [1]
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Optional[Any]     			=   [0]
      __lowerCAmelCase:     Any     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	int      )							->			Any:
      def func():
       pass

      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()

      def func():
       pass

      __lowerCAmelCase:     Tuple     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	int      )							->			Optional[Any]:
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(Foo([0]      )      )      ).hexdigest()
      __lowerCAmelCase:     str     			=   mda(datasets.utils.py_utils.dumps(Foo([1]      )      )      ).hexdigest()
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(Foo([0]      )      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Optional[Any]      )							->			Optional[Any]:
      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(Foo([0]      ).__call__      )      ).hexdigest()
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(Foo([1]      ).__call__      )      ).hexdigest()
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(Foo([0]      ).__call__      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Optional[Any]      )							->			Optional[Any]:
      __lowerCAmelCase:     str     			=   (
          'co_argcount',
          'co_kwonlyargcount',
          'co_nlocals',
          'co_stacksize',
          'co_flags',
          'co_code',
          'co_consts',
          'co_names',
          'co_varnames',
          'co_filename',
          'co_name',
          'co_firstlineno',
          'co_lnotab',
          'co_freevars',
          'co_cellvars',
      )

      def _create_code_pyaa(*UpperCAmelCase    :	Optional[Any]      ):
       if hasattr(args[-3]    ,						'encode'      ):
        __lowerCAmelCase:     Any     			=   list(UpperCAmelCase      )
        __lowerCAmelCase:     str     			=   args[-3].encode()  # co_lnotab
        __lowerCAmelCase:     str     			=   args[-1_0].encode()  # co_code
       if hasattr(UpperCAmelCase    ,						'co_posonlyargcount'      ):
        if len(UpperCAmelCase      ) == 1_6:
         return CodeType(*UpperCAmelCase      )
        elif len(UpperCAmelCase      ) == 1_5:
         return CodeType(args[0]    ,						0    ,						*args[1:]      )
        return CodeType(args[0]    ,						0    ,						0    ,						*args[1:]      )
       elif hasattr(UpperCAmelCase    ,						'co_kwonlyargcount'      ):
        if len(UpperCAmelCase      ) == 1_6:
         return CodeType(args[0]    ,						*args[2:]      )
        elif len(UpperCAmelCase      ) == 1_5:
         return CodeType(*UpperCAmelCase      )
        return CodeType(args[0]    ,						0    ,						*args[1:]      )
       if len(UpperCAmelCase      ) == 1_6:
        return CodeType(args[0]    ,						*args[3:]      )
       elif len(UpperCAmelCase      ) == 1_5:
        return CodeType(args[0]    ,						*args[2:]      )
       return CodeType(*UpperCAmelCase      )

      def create_ipython_func(UpperCAmelCase    :	Dict    ,						UpperCAmelCase    :	Tuple      ):
       def func():
        return returned_obj

       __lowerCAmelCase:     Any     			=   func.__code__
       # Use _create_code from dill in order to make it work for different python versions
       if datasets.config.PY_VERSION < version.parse('3.8'      ):
        __lowerCAmelCase:     Any     			=   _create_code_pyaa(
            *[getattr(UpperCAmelCase    ,						UpperCAmelCase      ) if k != 'co_filename' else co_filename for k in code_args_pyaa]      )
       else:
        __lowerCAmelCase:     List[Any]     			=   code.replace(co_filename=UpperCAmelCase      )
       return FunctionType(UpperCAmelCase    ,						func.__globals__    ,						func.__name__    ,						func.__defaults__    ,						func.__closure__      )

      __lowerCAmelCase			,							__lowerCAmelCase:     str     			=   '<ipython-input-2-e0383a102aae>', [0]
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCAmelCase    ,						UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase			,							__lowerCAmelCase:     str     			=   '<ipython-input-2-e0383a102aae>', [1]
      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCAmelCase    ,						UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase			,							__lowerCAmelCase:     Dict     			=   '<ipython-input-5-713f6613acf3>', [0]
      __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCAmelCase    ,						UpperCAmelCase      )      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )

      __lowerCAmelCase			,							__lowerCAmelCase:     Union[str, Any]     			=   os.path.join(gettempdir()    ,						'ipykernel_12345'    ,						'321456789.py'      ), [0]
      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCAmelCase    ,						UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase			,							__lowerCAmelCase:     Union[str, Any]     			=   os.path.join(gettempdir()    ,						'ipykernel_12345'    ,						'321456789.py'      ), [1]
      __lowerCAmelCase:     Optional[int]     			=   mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCAmelCase    ,						UpperCAmelCase      )      )      ).hexdigest()
      __lowerCAmelCase			,							__lowerCAmelCase:     List[Any]     			=   os.path.join(gettempdir()    ,						'ipykernel_12345'    ,						'654123987.py'      ), [0]
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCAmelCase    ,						UpperCAmelCase      )      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Union[str, Any]      )							->			Dict:
      __lowerCAmelCase			,							__lowerCAmelCase:     Dict     			=   [0], [1]

      def func():
       return foo, bar

      __lowerCAmelCase:     Dict     			=   '__main__'

      def globalvars_mocka_side_effect(UpperCAmelCase    :	Dict    ,						*UpperCAmelCase    :	str    ,						**UpperCAmelCase    :	Union[str, Any]      ):
       return {"foo": foo, "bar": bar}

      def globalvars_mocka_side_effect(UpperCAmelCase    :	Union[str, Any]    ,						*UpperCAmelCase    :	Dict    ,						**UpperCAmelCase    :	List[str]      ):
       return {"bar": bar, "foo": foo}

      with patch('dill.detect.globalvars'    ,						side_effect=UpperCAmelCase      ) as globalvars_mocka:
       __lowerCAmelCase:     List[Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
       self.assertGreater(globalvars_mocka.call_count    ,						0      )
      with patch('dill.detect.globalvars'    ,						side_effect=UpperCAmelCase      ) as globalvars_mocka:
       __lowerCAmelCase:     Dict     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
       self.assertGreater(globalvars_mocka.call_count    ,						0      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )







class 							A_				(	snake_case__      ):


     def 						UpperCAmelCase						(							self    :	Dict      )							->			Dict:
      __lowerCAmelCase:     int     			=   Hasher.hash('hello'      )
      __lowerCAmelCase:     Optional[Any]     			=   Hasher.hash('hello'      )
      __lowerCAmelCase:     Tuple     			=   Hasher.hash('there'      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	str      )							->			List[Any]:
      __lowerCAmelCase:     Optional[int]     			=   Hasher.hash(Foo('hello'      )      )
      __lowerCAmelCase:     List[Any]     			=   Hasher.hash(Foo('hello'      )      )
      __lowerCAmelCase:     str     			=   Hasher.hash(Foo('there'      )      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Any      )							->			Optional[Any]:
      __lowerCAmelCase:     Optional[Any]     			=   Hasher()
      for x in ["hello", Foo('hello'      )]:
       hasher.update(UpperCAmelCase      )
      __lowerCAmelCase:     Union[str, Any]     			=   hasher.hexdigest()
      __lowerCAmelCase:     Dict     			=   Hasher()
      for x in ["hello", Foo('hello'      )]:
       hasher.update(UpperCAmelCase      )
      __lowerCAmelCase:     int     			=   hasher.hexdigest()
      __lowerCAmelCase:     Dict     			=   Hasher()
      for x in ["there", Foo('there'      )]:
       hasher.update(UpperCAmelCase      )
      __lowerCAmelCase:     int     			=   hasher.hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	str      )							->			List[str]:
      with self.assertRaises(pickle.PicklingError      ):
       Hasher.hash(UnpicklableCallable(Foo('hello'      )      )      )


     def 						UpperCAmelCase						(							self    :	Optional[int]      )							->			Tuple:
      __lowerCAmelCase:     Tuple     			=   'abc'
      __lowerCAmelCase:     Optional[int]     			=   [string, string]  # two strings have the same ids
      __lowerCAmelCase:     List[Any]     			=   [string, string]
      __lowerCAmelCase:     int     			=   json.loads(F'''["{string}", "{string}"]'''      )  # two strings have different ids
      self.assertIs(obja[0]    ,						UpperCAmelCase      )
      self.assertIs(obja[0]    ,						obja[1]      )
      self.assertIs(obja[0]    ,						UpperCAmelCase      )
      self.assertIs(obja[0]    ,						obja[1]      )
      self.assertIsNot(obja[0]    ,						UpperCAmelCase      )
      self.assertIsNot(obja[0]    ,						obja[1]      )
      __lowerCAmelCase:     List[str]     			=   Hasher.hash(UpperCAmelCase      )
      __lowerCAmelCase:     Union[str, Any]     			=   Hasher.hash(UpperCAmelCase      )
      __lowerCAmelCase:     Dict     			=   Hasher.hash(UpperCAmelCase      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     @require_tiktoken
     def 						UpperCAmelCase						(							self    :	Dict      )							->			str:
      import tiktoken

      __lowerCAmelCase:     Tuple     			=   tiktoken.get_encoding('gpt2'      )
      __lowerCAmelCase:     Union[str, Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Optional[int]     			=   tiktoken.get_encoding('r50k_base'      )
      __lowerCAmelCase:     Tuple     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     str     			=   tiktoken.get_encoding('gpt2'      )
      __lowerCAmelCase:     Optional[int]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     @require_torch
     def 						UpperCAmelCase						(							self    :	List[Any]      )							->			Any:
      import torch

      __lowerCAmelCase:     Any     			=   torch.tensor([1.0]      )
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     List[str]     			=   torch.tensor([2.0]      )
      __lowerCAmelCase:     Optional[int]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Optional[int]     			=   torch.tensor([1.0]      )
      __lowerCAmelCase:     List[str]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )


     @require_spacy
     @require_spacy_model('en_core_web_sm'      )
     @require_spacy_model('fr_core_news_sm'      )
     @pytest.mark.integration
     def 						UpperCAmelCase						(							self    :	List[str]      )							->			Any:
      import spacy

      __lowerCAmelCase:     List[Any]     			=   spacy.load('en_core_web_sm'      )
      __lowerCAmelCase:     Tuple     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     Union[str, Any]     			=   spacy.load('fr_core_news_sm'      )
      __lowerCAmelCase:     int     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      __lowerCAmelCase:     List[str]     			=   spacy.load('en_core_web_sm'      )
      __lowerCAmelCase:     List[Any]     			=   mda(datasets.utils.py_utils.dumps(UpperCAmelCase      )      ).hexdigest()
      self.assertEqual(UpperCAmelCase    ,						UpperCAmelCase      )
      self.assertNotEqual(UpperCAmelCase    ,						UpperCAmelCase      )







@pytest.mark.integration
def _a				( SCREAMING_SNAKE_CASE	:    Path	)					->					List[Any]:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   tmp_path / 'dir1'
 __lowerCAmelCase:     Dict     			=   tmp_path / 'dir2'
 dira.mkdir()
 dira.mkdir()
 __lowerCAmelCase:     List[str]     			=   'script.py'
 __lowerCAmelCase:     int     			=   dedent(
     '\n    from datasets.fingerprint import Hasher\n    def foo():\n        pass\n    print(Hasher.hash(foo))\n    '	)
 __lowerCAmelCase:     List[str]     			=   dira / script_filename
 __lowerCAmelCase:     Dict     			=   dira / script_filename
 with script_patha.open('w'	) as f:
  f.write(SCREAMING_SNAKE_CASE	)
 with script_patha.open('w'	) as f:
  f.write(SCREAMING_SNAKE_CASE	)
 __lowerCAmelCase:     Tuple     			=   subprocess.check_output(['python', str(SCREAMING_SNAKE_CASE	)]	)
 __lowerCAmelCase:     int     			=   subprocess.check_output(['python', str(SCREAMING_SNAKE_CASE	)]	)
 assert fingerprinta == fingerprinta







def _a				( )					->					List[Any]:

 """simple docstring"""






 __lowerCAmelCase:     Any     			=   {'a': [0, 1, 2]}
 __lowerCAmelCase:     List[str]     			=   DatasetChild(InMemoryTable.from_pydict(SCREAMING_SNAKE_CASE	)	)
 __lowerCAmelCase:     Tuple     			=   dataset.funca()._fingerprint
 assert expected_fingerprint == dataset.funca()._fingerprint
 assert expected_fingerprint != dataset.funca()._fingerprint

 with Pool(2	) as p:
  assert expected_fingerprint == p.apply_async(dataset.funca	).get()._fingerprint
  assert expected_fingerprint != p.apply_async(dataset.funca	).get()._fingerprint







def _a				( )					->					List[str]:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   {'a': [0, 1, 2]}






 class 							A_				(	datasets.Dataset      ):


      @fingerprint_transform(inplace=UpperCAmelCase      )
      def 						UpperCAmelCase						(							self    :	Any    ,						UpperCAmelCase    :	List[str]      )							->			Dict:
       return DummyDatasetChild(self.data    ,						fingerprint=UpperCAmelCase      )







 __lowerCAmelCase:     str     			=   DummyDatasetChild(InMemoryTable.from_pydict(SCREAMING_SNAKE_CASE	)	).func()






 class 							A_				(	datasets.Dataset      ):


      @fingerprint_transform(inplace=UpperCAmelCase    ,						version='1.0.0'      )
      def 						UpperCAmelCase						(							self    :	Dict    ,						UpperCAmelCase    :	Optional[int]      )							->			List[Any]:
       return DummyDatasetChild(self.data    ,						fingerprint=UpperCAmelCase      )







 __lowerCAmelCase:     Dict     			=   DummyDatasetChild(InMemoryTable.from_pydict(SCREAMING_SNAKE_CASE	)	).func()






 class 							A_				(	datasets.Dataset      ):


      @fingerprint_transform(inplace=UpperCAmelCase    ,						version='2.0.0'      )
      def 						UpperCAmelCase						(							self    :	int    ,						UpperCAmelCase    :	Optional[int]      )							->			Any:
       return DummyDatasetChild(self.data    ,						fingerprint=UpperCAmelCase      )







 __lowerCAmelCase:     Any     			=   DummyDatasetChild(InMemoryTable.from_pydict(SCREAMING_SNAKE_CASE	)	).func()

 assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}	) == 3







def _a				( )					->					str:

 """simple docstring"""






 __lowerCAmelCase:     int     			=   Hasher()
 hasher.update(lambda SCREAMING_SNAKE_CASE	: x	)








from math import floor, sqrt







def _a				( SCREAMING_SNAKE_CASE	:    int	)					->					int:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   0.0
 __lowerCAmelCase:     Any     			=   1.0
 __lowerCAmelCase:     List[str]     			=   int(sqrt(SCREAMING_SNAKE_CASE	)	)
 __lowerCAmelCase:     Union[str, Any]     			=   root
 __lowerCAmelCase:     List[str]     			=   0
 while integer_part != 2 * root:
  __lowerCAmelCase:     List[str]     			=   denominator * integer_part - numerator
  __lowerCAmelCase:     Optional[int]     			=   (n - numerator**2) / denominator
  __lowerCAmelCase:     Union[str, Any]     			=   int((root + numerator) / denominator	)
  period += 1
 return period







def _a				( SCREAMING_SNAKE_CASE	:    int = 1_00_00	)					->					int:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   0
 for i in range(2					,      n + 1	):
  __lowerCAmelCase:     List[str]     			=   sqrt(SCREAMING_SNAKE_CASE	)
  if sr - floor(SCREAMING_SNAKE_CASE	) != 0 and continuous_fraction_period(SCREAMING_SNAKE_CASE	) % 2 == 1:
   count_odd_periods += 1
 return count_odd_periods


if __name__ == "__main__":
  print(f"{solution(int(input().strip()))}")





