


'''simple docstring'''



from functools import partial
from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload

import torch
import torch.nn as nn
import torch.types



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    bool							)					->		torch.Tensor:
     # The first operation in a checkpoint can't be in-place, but it's
     # nice to have in-place addition during inference. Thus...
     if not inplace:
          __lowerCamelCase       :     List[Any]        =		ma + ma
     else:
          ma += ma

     return ma



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    List[int]							)					->		torch.Tensor:
     __lowerCamelCase       :     int        =		-1 * len(UpperCAmelCase_							)
     __lowerCamelCase       :     Any        =		list(range(len(tensor.shape[:zero_index]							)							)							)
     return tensor.permute(first_inds + [zero_index + i for i in inds]							)



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    int							)					->		torch.Tensor:
     return t.reshape(t.shape[:-no_dims] + (-1,)							)



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    int				,   UpperCAmelCase_   :    float = 1e-4							)					->		torch.Tensor:
     __lowerCamelCase       :     Tuple        =		mask.expand(*value.shape							)
     return torch.sum(mask * value				,   dim=UpperCAmelCase_							) / (eps + torch.sum(UpperCAmelCase_				,   dim=UpperCAmelCase_							))



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    torch.types.Number = 2.3_125				,   UpperCAmelCase_   :    torch.types.Number = 21.6_875				,   UpperCAmelCase_   :    int = 64							)					->		torch.Tensor:
     __lowerCamelCase       :     Union[str, Any]        =		torch.linspace(UpperCAmelCase_				,   UpperCAmelCase_				,   no_bins - 1				,   device=pts.device							)
     __lowerCamelCase       :     Optional[Any]        =		torch.sqrt(torch.sum((pts.unsqueeze(-2							) - pts.unsqueeze(-3							)) ** 2				,   dim=-1							)							)
     return torch.bucketize(UpperCAmelCase_				,   UpperCAmelCase_							)



def       UpperCAmelCase__ (     UpperCAmelCase_   :    Callable[[list], Any]				,   UpperCAmelCase_   :    List[dict]							)					->		dict:
     __lowerCamelCase       :     int        =		dicts[0]
     __lowerCamelCase       :     Optional[int]        =		{}
     for k, v in first.items():
          __lowerCamelCase       :     Dict        =		[d[k] for d in dicts]
          if isinstance(UpperCAmelCase_				,   UpperCAmelCase_							):
               __lowerCamelCase       :     List[Any]        =		dict_multimap(UpperCAmelCase_				,   UpperCAmelCase_							)
          else:
               __lowerCamelCase       :     int        =		fn(UpperCAmelCase_							)

     return new_dict



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    torch.Tensor							)					->		torch.Tensor:
     __lowerCamelCase       :     Union[str, Any]        =		v_bins.view(((1,) * len(x.shape							)) + (len(UpperCAmelCase_							),)							)
     __lowerCamelCase       :     int        =		x[..., None] - reshaped_bins
     __lowerCamelCase       :     Any        =		torch.argmin(torch.abs(UpperCAmelCase_							)				,   dim=-1							)
     return nn.functional.one_hot(UpperCAmelCase_				,   num_classes=len(UpperCAmelCase_							)							).float()



def       UpperCAmelCase__ (     UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    torch.Tensor				,   UpperCAmelCase_   :    int = 0				,   UpperCAmelCase_   :    int = 0							)					->		torch.Tensor:
     __lowerCamelCase       :     List[Union[slice, torch.Tensor]]        =		[]
     for i, s in enumerate(data.shape[:no_batch_dims]							):
          __lowerCamelCase       :     Dict        =		torch.arange(UpperCAmelCase_							)
          __lowerCamelCase       :     Dict        =		r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape							) - i - 1)))							)
          ranges.append(UpperCAmelCase_							)

     __lowerCamelCase       :     List[Union[slice, torch.Tensor]]        =		[slice(UpperCAmelCase_							) for _ in range(len(data.shape							) - no_batch_dims							)]
     __lowerCamelCase       :     Any        =		inds
     ranges.extend(UpperCAmelCase_							)
     # Matt note: Editing this to get around the behaviour of using a list as an array index changing
     # in recent Numpy versions
     return data[tuple(UpperCAmelCase_							)]


A__		: Optional[int]												=  TypeVar("""T""")



def       UpperCAmelCase__ (     UpperCAmelCase_   :    Callable[[T], Any]				,   UpperCAmelCase_   :    Dict[Any, Union[dict, list, tuple, T]]				,   UpperCAmelCase_   :    Type[T]							)					->		Dict[Any, Union[dict, list, tuple, Any]]:
     __lowerCamelCase       :     Dict[Any, Union[dict, list, tuple, Any]]        =		{}
     for k, v in dic.items():
          if isinstance(UpperCAmelCase_				,   UpperCAmelCase_							):
               __lowerCamelCase       :     Dict        =		dict_map(UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_							)
          else:
               __lowerCamelCase       :     Tuple        =		tree_map(UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_							)

     return new_dict



@overload
def       UpperCAmelCase__ (     UpperCAmelCase_   :    Callable[[T], Any]				,   UpperCAmelCase_   :    T				,   UpperCAmelCase_   :    Type[T]							)					->		Any:
     ...



@overload
def       UpperCAmelCase__ (     UpperCAmelCase_   :    Callable[[T], Any]				,   UpperCAmelCase_   :    dict				,   UpperCAmelCase_   :    Type[T]							)					->		dict:
     ...



@overload
def       UpperCAmelCase__ (     UpperCAmelCase_   :    Callable[[T], Any]				,   UpperCAmelCase_   :    list				,   UpperCAmelCase_   :    Type[T]							)					->		list:
     ...



@overload
def       UpperCAmelCase__ (     UpperCAmelCase_   :    Callable[[T], Any]				,   UpperCAmelCase_   :    tuple				,   UpperCAmelCase_   :    Type[T]							)					->		tuple:
     ...



def       UpperCAmelCase__ (     UpperCAmelCase_   :    Dict				,   UpperCAmelCase_   :    Union[str, Any]				,   UpperCAmelCase_   :    List[Any]							)					->		int:
     if isinstance(UpperCAmelCase_				,   UpperCAmelCase_							):
          return dict_map(UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_							)
     elif isinstance(UpperCAmelCase_				,   UpperCAmelCase_							):
          return [tree_map(UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_							) for x in tree]
     elif isinstance(UpperCAmelCase_				,   UpperCAmelCase_							):
          return tuple(tree_map(UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_							) for x in tree							)
     elif isinstance(UpperCAmelCase_				,   UpperCAmelCase_							):
          return fn(UpperCAmelCase_							)
     else:
          print(type(UpperCAmelCase_							)							)
          raise ValueError('Not supported'							)

A__		: str												=  partial(tree_map, leaf_type=torch.Tensor)










'''simple docstring'''



def       UpperCAmelCase__ (     UpperCAmelCase_   :    int = 4_00_00_00							)					->		int:
     __lowerCamelCase       :     int        =		1
     __lowerCamelCase       :     Union[str, Any]        =		2
     __lowerCamelCase       :     Optional[int]        =		0
     while j <= n:
          if j % 2 == 0:
               total += j
          __lowerCamelCase    ,	__lowerCamelCase       :     List[Any]        =		j, i + j

     return total


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






