



"""simple docstring"""
import os

import numpy
import onnx


def 			_SCREAMING_SNAKE_CASE						(__lowerCAmelCase ,  __lowerCAmelCase							) ->						List[str]:







  '''simple docstring'''


  lowercase_								= a.name
  lowercase_								= b.name

  lowercase_								= ''''''
  lowercase_								= ''''''

  lowercase_								= a == b

  lowercase_								= name_a
  lowercase_								= name_b

  return res


def 			_SCREAMING_SNAKE_CASE						(__lowerCAmelCase ,  __lowerCAmelCase ,  __lowerCAmelCase							) ->						Dict:







  '''simple docstring'''


  for i, input_name in enumerate(node_proto.input							):
    if input_name == name:
      node_proto.input.insert(__lowerCAmelCase ,  __lowerCAmelCase							)
      node_proto.input.pop(i + 1							)

  if node_proto.op_type == "If":
    _graph_replace_input_with(node_proto.attribute[0].g ,  __lowerCAmelCase ,  __lowerCAmelCase							)
    _graph_replace_input_with(node_proto.attribute[1].g ,  __lowerCAmelCase ,  __lowerCAmelCase							)
  if node_proto.op_type == "Loop":
    _graph_replace_input_with(node_proto.attribute[0].g ,  __lowerCAmelCase ,  __lowerCAmelCase							)


def 			_SCREAMING_SNAKE_CASE						(__lowerCAmelCase ,  __lowerCAmelCase ,  __lowerCAmelCase							) ->						Union[str, Any]:







  '''simple docstring'''


  for n in graph_proto.node:
    _node_replace_input_with(__lowerCAmelCase ,  __lowerCAmelCase ,  __lowerCAmelCase							)


def 			_SCREAMING_SNAKE_CASE						(__lowerCAmelCase ,  __lowerCAmelCase ,  __lowerCAmelCase							) ->						Tuple:







  '''simple docstring'''


  lowercase_								= list(model.graph.initializer							)
  lowercase_								= list(model_without_ext.graph.initializer							)
  for i, ref_i in ind_to_replace:
    assert inits_with_data[i].name == inits[i].name
    assert inits_with_data[ref_i].name == inits[ref_i].name
    assert i > ref_i

    lowercase_								= inits[i].name
    lowercase_								= inits[ref_i].name

    model_without_ext.graph.initializer.remove(inits[i]							)

    # for n in model.graph.node:
    _graph_replace_input_with(model_without_ext.graph ,  __lowerCAmelCase ,  __lowerCAmelCase							)


def 			_SCREAMING_SNAKE_CASE						(__lowerCAmelCase							) ->						Optional[Any]:







  '''simple docstring'''


  lowercase_								= os.path.dirname(__lowerCAmelCase							)
  lowercase_								= os.path.basename(__lowerCAmelCase							)

  lowercase_								= onnx.load(os.path.join(__lowerCAmelCase ,  __lowerCAmelCase							)							)

  lowercase_								= list(model.graph.initializer							)

  lowercase_								= set()
  lowercase_								= {}
  lowercase_								= []

  lowercase_								= 0

  for i in range(len(__lowerCAmelCase							)							):
    if i in dup_set:
      continue

    for j in range(i + 1 ,  len(__lowerCAmelCase							)							):
      if j in dup_set:
        continue
      if _is_equal_tensor_proto(inits[i] ,  inits[j]							):
        dup_set.add(__lowerCAmelCase							)
        dup_set.add(__lowerCAmelCase							)

        lowercase_								= inits[j].data_type
        lowercase_								= numpy.prod(inits[j].dims							)
        if dtype == 1:
          mem_size *= 4
        elif dtype == 6:
          mem_size *= 4
        elif dtype == 7 or dtype == 11:
          mem_size *= 8
        else:
          print("""unexpected data type: """ ,  __lowerCAmelCase							)
        total_reduced_size += mem_size

        lowercase_								= inits[i].name
        lowercase_								= inits[j].name

        if name_i in dup_map:
          dup_map[name_i].append(__lowerCAmelCase							)
        else:
          lowercase_								= [name_j]
        ind_to_replace.append((j, i)							)

  print("""total reduced size: """ ,  total_reduced_size / 10_24 / 10_24 / 10_24 ,  """GB"""							)

  lowercase_								= sorted(__lowerCAmelCase							)
  _remove_dup_initializers_from_model(__lowerCAmelCase ,  __lowerCAmelCase ,  __lowerCAmelCase							)

  lowercase_								= '''optimized_''' + model_file_name
  lowercase_								= os.path.join(__lowerCAmelCase ,  __lowerCAmelCase							)
  onnx.save(__lowerCAmelCase ,  __lowerCAmelCase							)

  return new_model






"""simple docstring"""
def 			_SCREAMING_SNAKE_CASE						(__lowerCAmelCase=2_81_23							) ->						Optional[Any]:







  '''simple docstring'''


  lowercase_								= [1] * (limit + 1)

  for i in range(2 ,  int(limit**0.5							) + 1							):
    sum_divs[i * i] += i
    for k in range(i + 1 ,  limit // i + 1							):
      sum_divs[k * i] += k + i

  lowercase_								= set()
  lowercase_								= 0

  for n in range(1 ,  limit + 1							):
    if sum_divs[n] > n:
      abundants.add(__lowerCAmelCase							)

    if not any((n - a in abundants) for a in abundants							):
      res += n

  return res


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

