


'''simple docstring'''







# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import ast
import difflib
from collections.abc import Mapping
from typing import Any, Callable, Dict


class  __lowerCamelCase (       a_       ):
    """simple docstring"""
    pass






def       lowerCAmelCase__       (				lowerCamelCase     :			str  ,lowerCamelCase     :			Dict[str, Callable]  ,lowerCamelCase     :			Dict=None  ,lowerCamelCase     :			str=False   ):
       try:
              _A     :	int      =					ast.parse(lowerCamelCase   )
       except SyntaxError as e:
              print('The code generated by the agent is not valid.\n'  ,lowerCamelCase   )
              return
       if state is None:
              _A     :	Dict      =					{}
       _A     :	Tuple      =					None
       for idx, node in enumerate(expression.body   ):
              try:
                     _A     :	List[str]      =					evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
              except InterpretorError as e:
                     _A     :	Tuple      =					F'Evaluation of the code stopped at line {idx} before the end because of the following error'
                     if chat_mode:
                            msg += (
                                F'. Copy paste the following error message and send it back to the agent:\nI get an error: \'{e}\''
                            )
                     else:
                            msg += F':\n{e}'
                     print(lowerCamelCase   )
                     break
              if line_result is not None:
                     _A     :	Tuple      =					line_result

       return result






def       lowerCAmelCase__       (				lowerCamelCase     :			ast.AST  ,lowerCamelCase     :			Dict[str, Any]  ,lowerCamelCase     :			Dict[str, Callable]   ):
       if isinstance(lowerCamelCase  ,ast.Assign   ):
              # Assignement -> we evaluate the assignement which should update the state
              # We return the variable assigned as it may be used to determine the final result.
              return evaluate_assign(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.Call   ):
              # Function call -> we return the value of the function call
              return evaluate_call(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.Constant   ):
              # Constant -> just return the value
              return expression.value
       elif isinstance(lowerCamelCase  ,ast.Dict   ):
              # Dict -> evaluate all keys and values
              _A     :	Optional[Any]      =					[evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   ) for k in expression.keys]
              _A     :	Optional[int]      =					[evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   ) for v in expression.values]
              return dict(zip(lowerCamelCase  ,lowerCamelCase   )   )
       elif isinstance(lowerCamelCase  ,ast.Expr   ):
              # Expression -> evaluate the content
              return evaluate_ast(expression.value  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.For   ):
              # For loop -> execute the loop
              return evaluate_for(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.FormattedValue   ):
              # Formatted value (part of f-string) -> evaluate the content and return
              return evaluate_ast(expression.value  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.If   ):
              # If -> execute the right branch
              return evaluate_if(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
       elif hasattr(lowerCamelCase  ,'Index'   ) and isinstance(lowerCamelCase  ,ast.Index   ):
              return evaluate_ast(expression.value  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.JoinedStr   ):
              return "".join([str(evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )   ) for v in expression.values]   )
       elif isinstance(lowerCamelCase  ,ast.List   ):
              # List -> evaluate all elements
              return [evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   ) for elt in expression.elts]
       elif isinstance(lowerCamelCase  ,ast.Name   ):
              # Name -> pick up the value in the state
              return evaluate_name(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
       elif isinstance(lowerCamelCase  ,ast.Subscript   ):
              # Subscript -> return the value of the indexing
              return evaluate_subscript(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
       else:
              # For now we refuse anything else. Let's add things as we need them.
              raise InterpretorError(F'{expression.__class__.__name__} is not supported.'   )






def       lowerCAmelCase__       (				lowerCamelCase     :			str  ,lowerCamelCase     :			Optional[int]  ,lowerCamelCase     :			str   ):
       _A     :	str      =					assign.targets
       _A     :	Union[str, Any]      =					evaluate_ast(assign.value  ,lowerCamelCase  ,lowerCamelCase   )

       if len(lowerCamelCase   ) == 1:
              _A     :	List[Any]      =					result
       else:
              if len(lowerCamelCase   ) != len(lowerCamelCase   ):
                     raise InterpretorError(F'Expected {len(lowerCamelCase   )} values but got {len(lowerCamelCase   )}.'   )
              for var_name, r in zip(lowerCamelCase  ,lowerCamelCase   ):
                     _A     :	Optional[int]      =					r
       return result






def       lowerCAmelCase__       (				lowerCamelCase     :			Dict  ,lowerCamelCase     :			Dict  ,lowerCamelCase     :			str   ):
       if not isinstance(call.func  ,ast.Name   ):
              raise InterpretorError(
                  F'It is not permitted to evaluate other functions than the provided tools (tried to execute {call.func} of '
                  F'type {type(call.func   )}.'   )
       _A     :	str      =					call.func.id
       if func_name not in tools:
              raise InterpretorError(
                  F'It is not permitted to evaluate other functions than the provided tools (tried to execute {call.func.id}).'   )

       _A     :	Any      =					tools[func_name]
       # Todo deal with args
       _A     :	List[str]      =					[evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   ) for arg in call.args]
       _A     :	str      =					{keyword.arg: evaluate_ast(keyword.value  ,lowerCamelCase  ,lowerCamelCase   ) for keyword in call.keywords}
       return func(*lowerCamelCase  ,**lowerCamelCase   )






def       lowerCAmelCase__       (				lowerCamelCase     :			Any  ,lowerCamelCase     :			Optional[Any]  ,lowerCamelCase     :			List[Any]   ):
       _A     :	str      =					evaluate_ast(subscript.slice  ,lowerCamelCase  ,lowerCamelCase   )
       _A     :	Tuple      =					evaluate_ast(subscript.value  ,lowerCamelCase  ,lowerCamelCase   )
       if isinstance(lowerCamelCase  ,(list, tuple)   ):
              return value[int(lowerCamelCase   )]
       if index in value:
              return value[index]
       if isinstance(lowerCamelCase  ,lowerCamelCase   ) and isinstance(lowerCamelCase  ,lowerCamelCase   ):
              _A     :	Dict      =					difflib.get_close_matches(lowerCamelCase  ,list(value.keys()   )   )
              if len(lowerCamelCase   ) > 0:
                     return value[close_matches[0]]

       raise InterpretorError(F'Could not index {value} with \'{index}\'.'   )






def       lowerCAmelCase__       (				lowerCamelCase     :			List[str]  ,lowerCamelCase     :			Union[str, Any]  ,lowerCamelCase     :			Optional[int]   ):
       if name.id in state:
              return state[name.id]
       _A     :	Union[str, Any]      =					difflib.get_close_matches(name.id  ,list(state.keys()   )   )
       if len(lowerCamelCase   ) > 0:
              return state[close_matches[0]]
       raise InterpretorError(F'The variable `{name.id}` is not defined.'   )






def       lowerCAmelCase__       (				lowerCamelCase     :			str  ,lowerCamelCase     :			Any  ,lowerCamelCase     :			Dict   ):
       if len(condition.ops   ) > 1:
              raise InterpretorError('Cannot evaluate conditions with multiple operators'   )

       _A     :	int      =					evaluate_ast(condition.left  ,lowerCamelCase  ,lowerCamelCase   )
       _A     :	List[str]      =					condition.ops[0]
       _A     :	Tuple      =					evaluate_ast(condition.comparators[0]  ,lowerCamelCase  ,lowerCamelCase   )

       if isinstance(lowerCamelCase  ,ast.Eq   ):
              return left == right
       elif isinstance(lowerCamelCase  ,ast.NotEq   ):
              return left != right
       elif isinstance(lowerCamelCase  ,ast.Lt   ):
              return left < right
       elif isinstance(lowerCamelCase  ,ast.LtE   ):
              return left <= right
       elif isinstance(lowerCamelCase  ,ast.Gt   ):
              return left > right
       elif isinstance(lowerCamelCase  ,ast.GtE   ):
              return left >= right
       elif isinstance(lowerCamelCase  ,ast.Is   ):
              return left is right
       elif isinstance(lowerCamelCase  ,ast.IsNot   ):
              return left is not right
       elif isinstance(lowerCamelCase  ,ast.In   ):
              return left in right
       elif isinstance(lowerCamelCase  ,ast.NotIn   ):
              return left not in right
       else:
              raise InterpretorError(F'Operator not supported: {comparator}'   )






def       lowerCAmelCase__       (				lowerCamelCase     :			str  ,lowerCamelCase     :			Optional[Any]  ,lowerCamelCase     :			List[Any]   ):
       _A     :	Optional[int]      =					None
       if evaluate_condition(if_statement.test  ,lowerCamelCase  ,lowerCamelCase   ):
              for line in if_statement.body:
                     _A     :	Any      =					evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
                     if line_result is not None:
                            _A     :	Optional[Any]      =					line_result
       else:
              for line in if_statement.orelse:
                     _A     :	Dict      =					evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
                     if line_result is not None:
                            _A     :	Union[str, Any]      =					line_result
       return result






def       lowerCAmelCase__       (				lowerCamelCase     :			Optional[int]  ,lowerCamelCase     :			Tuple  ,lowerCamelCase     :			Union[str, Any]   ):
       _A     :	Optional[int]      =					None
       _A     :	List[str]      =					evaluate_ast(for_loop.iter  ,lowerCamelCase  ,lowerCamelCase   )
       for counter in iterator:
              _A     :	List[str]      =					counter
              for expression in for_loop.body:
                     _A     :	Union[str, Any]      =					evaluate_ast(lowerCamelCase  ,lowerCamelCase  ,lowerCamelCase   )
                     if line_result is not None:
                            _A     :	Optional[Any]      =					line_result
       return result










'''simple docstring'''







import sys

sys.set_int_max_str_digits(0)  # type: ignore






def       lowerCAmelCase__       (				lowerCamelCase     :			int   ):
       _A     :	Optional[Any]      =					[0] * 11
       _A     :	str      =					[0] * 11

       # mark last 9 numbers
       for _ in range(9   ):
              _A     :	int      =					1
              _A     :	Optional[int]      =					number // 10
       # flag
       _A     :	List[Any]      =					True

       # check last 9 numbers for pandigitality

       for x in range(9   ):
              if not check_last[x + 1]:
                     _A     :	Optional[int]      =					False
       if not f:
              return f

       # mark first 9 numbers
       _A     :	Optional[int]      =					int(str(lowerCamelCase   )[:9]   )

       for _ in range(9   ):
              _A     :	Optional[Any]      =					1
              _A     :	str      =					number // 10

       # check first 9 numbers for pandigitality

       for x in range(9   ):
              if not check_front[x + 1]:
                     _A     :	Optional[Any]      =					False
       return f






def       lowerCAmelCase__       (				lowerCamelCase     :			int   ):
       _A     :	Dict      =					[0] * 11

       # mark last 9 numbers
       for _ in range(9   ):
              _A     :	List[str]      =					1
              _A     :	Dict      =					number // 10
       # flag
       _A     :	Optional[int]      =					True

       # check last 9 numbers for pandigitality

       for x in range(9   ):
              if not check_last[x + 1]:
                     _A     :	List[str]      =					False
       return f






def       lowerCAmelCase__       (				):
       _A     :	List[Any]      =					1
       _A     :	Dict      =					1
       _A     :	Dict      =					2
       # temporary Fibonacci numbers

       _A     :	List[Any]      =					1
       _A     :	Union[str, Any]      =					1
       _A     :	List[Any]      =					2
       # temporary Fibonacci numbers mod 1e9

       # mod m=1e9, done for fast optimisation
       _A     :	Tuple      =					[0] * 1000000
       _A     :	Any      =					1000000000

       for x in range(1000000   ):
              _A     :	Tuple      =					(aa + ba) % m
              _A     :	Optional[Any]      =					ba % m
              _A     :	str      =					ca % m
              if checka(lowerCamelCase   ):
                     _A     :	Dict      =					1

       for x in range(1000000   ):
              _A     :	List[str]      =					a + b
              _A     :	Optional[int]      =					b
              _A     :	str      =					c
              # perform check only if in tocheck
              if tocheck[x + 3] and check(lowerCamelCase   ):
                     return x + 3  # first 2 already done
       return -1


if __name__ == "__main__":
   print(f"""{solution() = }""")






