




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  __lowerCAmelCase							:






       def __init__( self:       Optional[Any]							,       _lowerCAmelCase:       Tuple					):
         lowercase     :Optional[Any]   						=    foo






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







class  __lowerCAmelCase							(				datasets.Dataset):






       @fingerprint_transform(inplace=_lowerCAmelCase					)
       def        SCREAMING_SNAKE_CASE     ( self:       List[str]							,       _lowerCAmelCase:       List[str]							,       *_lowerCAmelCase:       List[Any]							,       **_lowerCAmelCase:       Optional[Any]					):
         return DatasetChild(self.data							,       fingerprint=_lowerCAmelCase					)






       @fingerprint_transform(inplace=_lowerCAmelCase					)
       def        SCREAMING_SNAKE_CASE     ( self:       Any							,       _lowerCAmelCase:       List[Any]							,       *_lowerCAmelCase:       List[str]							,       **_lowerCAmelCase:       Optional[Any]					):
         return DatasetChild(self.data							,       fingerprint=_lowerCAmelCase					)







class  __lowerCAmelCase							:






       def __init__( self:       int							,       _lowerCAmelCase:       int					):
         lowercase     :List[Any]   						=    callable






       def __call__( self:       Optional[Any]							,       *_lowerCAmelCase:       Dict							,       **_lowerCAmelCase:       Optional[Any]					):
         if self.callable is not None:
           return self.callable(*_lowerCAmelCase							,       **_lowerCAmelCase					)






       def __getstate__( self:       int					):
         raise pickle.PicklingError()







class  __lowerCAmelCase							(				lowerCAmelCase):






       @require_transformers
       @pytest.mark.integration
       def        SCREAMING_SNAKE_CASE     ( self:       int					):
         from transformers import AutoTokenizer

         def encode(_lowerCAmelCase:       Tuple					):
           return tokenizer(_lowerCAmelCase					)

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






       @require_transformers
       @pytest.mark.integration
       def        SCREAMING_SNAKE_CASE     ( self:       int					):
         from transformers import AutoTokenizer

         lowercase     :Dict   						=    AutoTokenizer.from_pretrained("gpt2"					)
         lowercase     :Optional[Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         tokenizer("Hello world !"					)  # call once to change the tokenizer's cache
         lowercase     :Optional[int]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       @require_regex
       def        SCREAMING_SNAKE_CASE     ( self:       int					):
         import regex

         lowercase     :Optional[int]   						=    regex.Regex("foo"					)
         lowercase     :Union[str, Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :List[Any]   						=    regex.Regex("bar"					)
         lowercase     :List[Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Tuple   						=    regex.Regex("foo"					)
         lowercase     :Tuple   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)







class  __lowerCAmelCase							(				lowerCAmelCase):






       def        SCREAMING_SNAKE_CASE     ( self:       str					):
         def func():
           return foo

         lowercase     :Optional[Any]   						=    [0]
         lowercase     :Union[str, Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :int   						=    [1]
         lowercase     :Dict   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Optional[Any]   						=    [0]
         lowercase     :Tuple   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       Union[str, Any]					):
         def func():
           pass

         lowercase     :int   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()

         def func():
           pass

         lowercase     :str   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       Dict					):
         lowercase     :Union[str, Any]   						=    mda(datasets.utils.py_utils.dumps(Foo([0]					)					)					).hexdigest()
         lowercase     :Optional[int]   						=    mda(datasets.utils.py_utils.dumps(Foo([1]					)					)					).hexdigest()
         lowercase     :Any   						=    mda(datasets.utils.py_utils.dumps(Foo([0]					)					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       str					):
         lowercase     :int   						=    mda(datasets.utils.py_utils.dumps(Foo([0]					).__call__					)					).hexdigest()
         lowercase     :List[str]   						=    mda(datasets.utils.py_utils.dumps(Foo([1]					).__call__					)					).hexdigest()
         lowercase     :Union[str, Any]   						=    mda(datasets.utils.py_utils.dumps(Foo([0]					).__call__					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       Union[str, Any]					):
         lowercase     :Optional[int]   						=    (
             "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(*_lowerCAmelCase:       Optional[Any]					):
           if hasattr(args[-3]							,       "encode"					):
             lowercase     :Any   						=    list(_lowerCAmelCase					)
             lowercase     :str   						=    args[-3].encode()  # co_lnotab
             lowercase     :List[Any]   						=    args[-10].encode()  # co_code
           if hasattr(_lowerCAmelCase							,       "co_posonlyargcount"					):
             if len(_lowerCAmelCase					) == 16:
               return CodeType(*_lowerCAmelCase					)
             elif len(_lowerCAmelCase					) == 15:
               return CodeType(args[0]							,       0							,       *args[1:]					)
             return CodeType(args[0]							,       0							,       0							,       *args[1:]					)
           elif hasattr(_lowerCAmelCase							,       "co_kwonlyargcount"					):
             if len(_lowerCAmelCase					) == 16:
               return CodeType(args[0]							,       *args[2:]					)
             elif len(_lowerCAmelCase					) == 15:
               return CodeType(*_lowerCAmelCase					)
             return CodeType(args[0]							,       0							,       *args[1:]					)
           if len(_lowerCAmelCase					) == 16:
             return CodeType(args[0]							,       *args[3:]					)
           elif len(_lowerCAmelCase					) == 15:
             return CodeType(args[0]							,       *args[2:]					)
           return CodeType(*_lowerCAmelCase					)

         def create_ipython_func(_lowerCAmelCase:       Dict							,       _lowerCAmelCase:       Dict					):
           def func():
             return returned_obj

           lowercase     :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"					):
             lowercase     :Union[str, Any]   						=    _create_code_pyaa(
                 *[getattr(_lowerCAmelCase							,       _lowerCAmelCase					) if k != "co_filename" else co_filename for k in code_args_pyaa]					)
           else:
             lowercase     :str   						=    code.replace(co_filename=_lowerCAmelCase					)
           return FunctionType(_lowerCAmelCase							,       func.__globals__							,       func.__name__							,       func.__defaults__							,       func.__closure__					)

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

         lowercase						,     lowercase     :Tuple   						=    os.path.join(gettempdir()							,       "ipykernel_12345"							,       "321456789.py"					), [0]
         lowercase     :List[str]   						=    mda(datasets.utils.py_utils.dumps(create_ipython_func(_lowerCAmelCase							,       _lowerCAmelCase					)					)					).hexdigest()
         lowercase						,     lowercase     :Tuple   						=    os.path.join(gettempdir()							,       "ipykernel_12345"							,       "321456789.py"					), [1]
         lowercase     :Dict   						=    mda(datasets.utils.py_utils.dumps(create_ipython_func(_lowerCAmelCase							,       _lowerCAmelCase					)					)					).hexdigest()
         lowercase						,     lowercase     :Union[str, Any]   						=    os.path.join(gettempdir()							,       "ipykernel_12345"							,       "654123987.py"					), [0]
         lowercase     :Tuple   						=    mda(datasets.utils.py_utils.dumps(create_ipython_func(_lowerCAmelCase							,       _lowerCAmelCase					)					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       Optional[Any]					):
         lowercase						,     lowercase     :List[Any]   						=    [0], [1]

         def func():
           return foo, bar

         lowercase     :Tuple   						=    "__main__"

         def globalvars_mocka_side_effect(_lowerCAmelCase:       List[Any]							,       *_lowerCAmelCase:       Dict							,       **_lowerCAmelCase:       int					):
           return {"foo": foo, "bar": bar}

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

         with patch("dill.detect.globalvars"							,       side_effect=_lowerCAmelCase					) as globalvars_mocka:
           lowercase     :Union[str, Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
           self.assertGreater(globalvars_mocka.call_count							,       0					)
         with patch("dill.detect.globalvars"							,       side_effect=_lowerCAmelCase					) as globalvars_mocka:
           lowercase     :int   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
           self.assertGreater(globalvars_mocka.call_count							,       0					)
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)







class  __lowerCAmelCase							(				lowerCAmelCase):






       def        SCREAMING_SNAKE_CASE     ( self:       Any					):
         lowercase     :Optional[int]   						=    Hasher.hash("hello"					)
         lowercase     :str   						=    Hasher.hash("hello"					)
         lowercase     :Tuple   						=    Hasher.hash("there"					)
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       Optional[Any]					):
         lowercase     :int   						=    Hasher.hash(Foo("hello"					)					)
         lowercase     :List[str]   						=    Hasher.hash(Foo("hello"					)					)
         lowercase     :int   						=    Hasher.hash(Foo("there"					)					)
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       List[str]					):
         lowercase     :Dict   						=    Hasher()
         for x in ["hello", Foo("hello"					)]:
           hasher.update(_lowerCAmelCase					)
         lowercase     :List[Any]   						=    hasher.hexdigest()
         lowercase     :Optional[int]   						=    Hasher()
         for x in ["hello", Foo("hello"					)]:
           hasher.update(_lowerCAmelCase					)
         lowercase     :str   						=    hasher.hexdigest()
         lowercase     :Optional[int]   						=    Hasher()
         for x in ["there", Foo("there"					)]:
           hasher.update(_lowerCAmelCase					)
         lowercase     :Dict   						=    hasher.hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       int					):
         with self.assertRaises(pickle.PicklingError					):
           Hasher.hash(UnpicklableCallable(Foo("hello"					)					)					)






       def        SCREAMING_SNAKE_CASE     ( self:       Tuple					):
         lowercase     :str   						=    "abc"
         lowercase     :Optional[int]   						=    [string, string]  # two strings have the same ids
         lowercase     :Any   						=    [string, string]
         lowercase     :str   						=    json.loads(F"[\"{string}\", \"{string}\"]"					)  # two strings have different ids
         self.assertIs(obja[0]							,       _lowerCAmelCase					)
         self.assertIs(obja[0]							,       obja[1]					)
         self.assertIs(obja[0]							,       _lowerCAmelCase					)
         self.assertIs(obja[0]							,       obja[1]					)
         self.assertIsNot(obja[0]							,       _lowerCAmelCase					)
         self.assertIsNot(obja[0]							,       obja[1]					)
         lowercase     :str   						=    Hasher.hash(_lowerCAmelCase					)
         lowercase     :Dict   						=    Hasher.hash(_lowerCAmelCase					)
         lowercase     :Optional[Any]   						=    Hasher.hash(_lowerCAmelCase					)
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       @require_tiktoken
       def        SCREAMING_SNAKE_CASE     ( self:       Any					):
         import tiktoken

         lowercase     :Any   						=    tiktoken.get_encoding("gpt2"					)
         lowercase     :List[Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Optional[Any]   						=    tiktoken.get_encoding("r50k_base"					)
         lowercase     :Optional[Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Dict   						=    tiktoken.get_encoding("gpt2"					)
         lowercase     :Dict   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       @require_torch
       def        SCREAMING_SNAKE_CASE     ( self:       Optional[Any]					):
         import torch

         lowercase     :str   						=    torch.tensor([1.0]					)
         lowercase     :Tuple   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :int   						=    torch.tensor([2.0]					)
         lowercase     :Any   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Any   						=    torch.tensor([1.0]					)
         lowercase     :str   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)






       @require_spacy
       @require_spacy_model("en_core_web_sm"					)
       @require_spacy_model("fr_core_news_sm"					)
       @pytest.mark.integration
       def        SCREAMING_SNAKE_CASE     ( self:       Optional[int]					):
         import spacy

         lowercase     :List[Any]   						=    spacy.load("en_core_web_sm"					)
         lowercase     :List[Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Dict   						=    spacy.load("fr_core_news_sm"					)
         lowercase     :Optional[Any]   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         lowercase     :Union[str, Any]   						=    spacy.load("en_core_web_sm"					)
         lowercase     :Dict   						=    mda(datasets.utils.py_utils.dumps(_lowerCAmelCase					)					).hexdigest()
         self.assertEqual(_lowerCAmelCase							,       _lowerCAmelCase					)
         self.assertNotEqual(_lowerCAmelCase							,       _lowerCAmelCase					)







@pytest.mark.integration
def    UpperCAmelCase__	(  lowerCamelCase ):
  lowercase     :List[Any]   						=    tmp_path / "dir1"
  lowercase     :Dict   						=    tmp_path / "dir2"
  dira.mkdir()
  dira.mkdir()
  lowercase     :Optional[int]   						=    "script.py"
  lowercase     :Union[str, Any]   						=    dedent(
      "\n    from datasets.fingerprint import Hasher\n    def foo():\n        pass\n    print(Hasher.hash(foo))\n    " )
  lowercase     :Optional[int]   						=    dira / script_filename
  lowercase     :str   						=    dira / script_filename
  with script_patha.open("w" ) as f:
    f.write(lowerCamelCase )
  with script_patha.open("w" ) as f:
    f.write(lowerCamelCase )
  lowercase     :int   						=    subprocess.check_output(["python", str(lowerCamelCase )] )
  lowercase     :int   						=    subprocess.check_output(["python", str(lowerCamelCase )] )
  assert fingerprinta == fingerprinta



def    UpperCAmelCase__	(  ):
  lowercase     :Union[str, Any]   						=    {"a": [0, 1, 2]}
  lowercase     :Optional[int]   						=    DatasetChild(InMemoryTable.from_pydict(lowerCamelCase ) )
  lowercase     :Union[str, Any]   						=    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    UpperCAmelCase__	(  ):
  lowercase     :Optional[Any]   						=    {"a": [0, 1, 2]}




  class  __lowerCAmelCase							(				datasets.Dataset):






         @fingerprint_transform(inplace=_lowerCAmelCase					)
         def        SCREAMING_SNAKE_CASE     ( self:       Any							,       _lowerCAmelCase:       Tuple					):
           return DummyDatasetChild(self.data							,       fingerprint=_lowerCAmelCase					)







  lowercase     :Optional[int]   						=    DummyDatasetChild(InMemoryTable.from_pydict(lowerCamelCase ) ).func()




  class  __lowerCAmelCase							(				datasets.Dataset):






         @fingerprint_transform(inplace=_lowerCAmelCase							,       version="1.0.0"					)
         def        SCREAMING_SNAKE_CASE     ( self:       List[str]							,       _lowerCAmelCase:       List[str]					):
           return DummyDatasetChild(self.data							,       fingerprint=_lowerCAmelCase					)







  lowercase     :str   						=    DummyDatasetChild(InMemoryTable.from_pydict(lowerCamelCase ) ).func()




  class  __lowerCAmelCase							(				datasets.Dataset):






         @fingerprint_transform(inplace=_lowerCAmelCase							,       version="2.0.0"					)
         def        SCREAMING_SNAKE_CASE     ( self:       Tuple							,       _lowerCAmelCase:       Union[str, Any]					):
           return DummyDatasetChild(self.data							,       fingerprint=_lowerCAmelCase					)







  lowercase     :Optional[Any]   						=    DummyDatasetChild(InMemoryTable.from_pydict(lowerCamelCase ) ).func()

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







def    UpperCAmelCase__	(  ):
  # AttributeError: module 'dill._dill' has no attribute 'stack'
  lowercase     :Optional[int]   						=    Hasher()
  hasher.update(lambda lowerCamelCase : x )









def    UpperCAmelCase__	(  lowerCamelCase ):
  lowercase     :Optional[int]   						=    len(lowerCamelCase )
  if n in (0, 1):
    return 0
  return sum(query * (n - i - 1) for i, query in enumerate(sorted(lowerCamelCase ) ) )


if __name__ == "__main__":
     import doctest

     doctest.testmod()



