"""simple docstring"""





import torch
from torch import nn




class  _snake_case		(    nn.Module ):







				"""simple docstring"""






				def __init__(      self							:							Optional[int]      ,    _A							:							Optional[int]      ,    _A							:							List[Any]      ,    _A							:							Any      ,    _A							:							List[str]      ,    _A							:							int=1      ,    _A							:							Union[str, Any]=False):



											"""simple docstring"""







											super().__init__()

											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    n_token
											_SCREAMING_SNAKE_CASE		:						int			  =    d_embed
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    d_proj

											_SCREAMING_SNAKE_CASE		:						Tuple			  =    cutoffs + [n_token]
											_SCREAMING_SNAKE_CASE		:						Any			  =    [0] + self.cutoffs
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    div_val

											_SCREAMING_SNAKE_CASE		:						Any			  =    self.cutoffs[0]
											_SCREAMING_SNAKE_CASE		:						Dict			  =    len(self.cutoffs) - 1
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    self.shortlist_size + self.n_clusters

											if self.n_clusters > 0:
																		_SCREAMING_SNAKE_CASE		:						Any			  =    nn.Parameter(torch.zeros(self.n_clusters      ,    self.d_embed))
																		_SCREAMING_SNAKE_CASE		:						Dict			  =    nn.Parameter(torch.zeros(self.n_clusters))

											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    nn.ModuleList()
											_SCREAMING_SNAKE_CASE		:						int			  =    nn.ParameterList()

											if div_val == 1:
																		for i in range(len(self.cutoffs)):
																									if d_proj != d_embed:
																																self.out_projs.append(nn.Parameter(torch.FloatTensor(_A      ,    _A)))
																									else:
																																self.out_projs.append(_A)

																		self.out_layers.append(nn.Linear(_A      ,    _A))
											else:
																		for i in range(len(self.cutoffs)):
																									_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Any			  =    self.cutoff_ends[i], self.cutoff_ends[i + 1]
																									_SCREAMING_SNAKE_CASE		:						Dict			  =    d_embed // (div_val**i)

																									self.out_projs.append(nn.Parameter(torch.FloatTensor(_A      ,    _A)))

																									self.out_layers.append(nn.Linear(_A      ,    r_idx - l_idx))

											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    keep_order





				def 		_lowerCAmelCase		(      self							:							Optional[Any]      ,    _A							:							List[str]      ,    _A							:							Optional[Any]      ,    _A							:							Tuple      ,    _A							:							int):



											"""simple docstring"""







											if proj is None:
																		_SCREAMING_SNAKE_CASE		:						List[str]			  =    nn.functional.linear(_A      ,    _A      ,    bias=_A)
											else:
																		# if CUDA_MAJOR <= 9 and CUDA_MINOR <= 1:
																		_SCREAMING_SNAKE_CASE		:						List[str]			  =    nn.functional.linear(_A      ,    proj.t().contiguous())
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    nn.functional.linear(_A      ,    _A      ,    bias=_A)
																		# else:
																		#     logit = torch.einsum('bd,de,ev->bv', (hidden, proj, weight.t()))
																		#     if bias is not None:
																		#         logit = logit + bias

											return logit





				def 		_lowerCAmelCase		(      self							:							Optional[int]      ,    _A							:							Optional[Any]      ,    _A							:							Union[str, Any]=None      ,    _A							:							Optional[Any]=False):



											"""simple docstring"""







											if labels is not None:
																		# Shift so that tokens < n predict n
																		_SCREAMING_SNAKE_CASE		:						Dict			  =    hidden[..., :-1, :].contiguous()
																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    labels[..., 1:].contiguous()
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    hidden.view(-1      ,    hidden.size(-1))
																		_SCREAMING_SNAKE_CASE		:						List[str]			  =    labels.view(-1)
																		if hidden.size(0) != labels.size(0):
																									raise RuntimeError("""Input and labels should have the same size in the batch dimension.""")
											else:
																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    hidden.view(-1      ,    hidden.size(-1))

											if self.n_clusters == 0:
																		_SCREAMING_SNAKE_CASE		:						str			  =    self._compute_logit(_A      ,    self.out_layers[0].weight      ,    self.out_layers[0].bias      ,    self.out_projs[0])
																		if labels is not None:
																									_SCREAMING_SNAKE_CASE		:						List[str]			  =    labels != -1_0_0
																									_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    torch.zeros_like(_A      ,    dtype=hidden.dtype      ,    device=hidden.device)
																									_SCREAMING_SNAKE_CASE		:						Tuple			  =    (
																									    -nn.functional.log_softmax(_A      ,    dim=-1)[mask].gather(1      ,    labels[mask].unsqueeze(1)).squeeze(1)
																									)
																		else:
																									_SCREAMING_SNAKE_CASE		:						Any			  =    nn.functional.log_softmax(_A      ,    dim=-1)
											else:
																		# construct weights and biases
																		_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Any			  =    [], []
																		for i in range(len(self.cutoffs)):
																									if self.div_val == 1:
																																_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    self.cutoff_ends[i], self.cutoff_ends[i + 1]
																																_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    self.out_layers[0].weight[l_idx:r_idx]
																																_SCREAMING_SNAKE_CASE		:						Tuple			  =    self.out_layers[0].bias[l_idx:r_idx]
																									else:
																																_SCREAMING_SNAKE_CASE		:						Tuple			  =    self.out_layers[i].weight
																																_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    self.out_layers[i].bias

																									if i == 0:
																																_SCREAMING_SNAKE_CASE		:						int			  =    torch.cat([weight_i, self.cluster_weight]      ,    dim=0)
																																_SCREAMING_SNAKE_CASE		:						Tuple			  =    torch.cat([bias_i, self.cluster_bias]      ,    dim=0)

																									weights.append(_A)
																									biases.append(_A)

																		_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						str			  =    weights[0], biases[0], self.out_projs[0]

																		_SCREAMING_SNAKE_CASE		:						List[str]			  =    self._compute_logit(_A      ,    _A      ,    _A      ,    _A)
																		_SCREAMING_SNAKE_CASE		:						List[str]			  =    nn.functional.log_softmax(_A      ,    dim=1)

																		if labels is None:
																									_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    hidden.new_empty((head_logit.size(0), self.n_token))
																		else:
																									_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    torch.zeros_like(_A      ,    dtype=hidden.dtype      ,    device=hidden.device)

																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    0
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    [0] + self.cutoffs
																		for i in range(len(_A) - 1):
																									_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						List[Any]			  =    cutoff_values[i], cutoff_values[i + 1]

																									if labels is not None:
																																_SCREAMING_SNAKE_CASE		:						Dict			  =    (labels >= l_idx) & (labels < r_idx)
																																_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    mask_i.nonzero().squeeze()

																																if indices_i.numel() == 0:
																																							continue

																																_SCREAMING_SNAKE_CASE		:						List[str]			  =    labels.index_select(0      ,    _A) - l_idx
																																_SCREAMING_SNAKE_CASE		:						List[str]			  =    head_logprob.index_select(0      ,    _A)
																																_SCREAMING_SNAKE_CASE		:						int			  =    hidden.index_select(0      ,    _A)
																									else:
																																_SCREAMING_SNAKE_CASE		:						List[Any]			  =    hidden

																									if i == 0:
																																if labels is not None:
																																							_SCREAMING_SNAKE_CASE		:						List[Any]			  =    head_logprob_i.gather(1      ,    target_i[:, None]).squeeze(1)
																																else:
																																							_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    head_logprob[:, : self.cutoffs[0]]
																									else:
																																_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						List[str]			  =    weights[i], biases[i], self.out_projs[i]

																																_SCREAMING_SNAKE_CASE		:						int			  =    self._compute_logit(_A      ,    _A      ,    _A      ,    _A)
																																_SCREAMING_SNAKE_CASE		:						Dict			  =    nn.functional.log_softmax(_A      ,    dim=1)
																																_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.cutoffs[0] + i - 1  # No probability for the head cluster
																																if labels is not None:
																																							_SCREAMING_SNAKE_CASE		:						Any			  =    head_logprob_i[:, cluster_prob_idx] + tail_logprob_i.gather(
																																							    1      ,    target_i[:, None]).squeeze(1)
																																else:
																																							_SCREAMING_SNAKE_CASE		:						List[str]			  =    head_logprob[:, cluster_prob_idx, None] + tail_logprob_i
																																							_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    logprob_i

																									if labels is not None:
																																if (hasattr(self      ,    """keep_order""") and self.keep_order) or keep_order:
																																							out.index_copy_(0      ,    _A      ,    -logprob_i)
																																else:
																																							out[offset : offset + logprob_i.size(0)].copy_(-logprob_i)
																																offset += logprob_i.size(0)

											return out





				def 		_lowerCAmelCase		(      self							:							Dict      ,    _A							:							Any):



											"""simple docstring"""







											if self.n_clusters == 0:
																		_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    self._compute_logit(_A      ,    self.out_layers[0].weight      ,    self.out_layers[0].bias      ,    self.out_projs[0])
																		return nn.functional.log_softmax(_A      ,    dim=-1)
											else:
																		# construct weights and biases
																		_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						List[Any]			  =    [], []
																		for i in range(len(self.cutoffs)):
																									if self.div_val == 1:
																																_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						str			  =    self.cutoff_ends[i], self.cutoff_ends[i + 1]
																																_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.out_layers[0].weight[l_idx:r_idx]
																																_SCREAMING_SNAKE_CASE		:						str			  =    self.out_layers[0].bias[l_idx:r_idx]
																									else:
																																_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    self.out_layers[i].weight
																																_SCREAMING_SNAKE_CASE		:						Any			  =    self.out_layers[i].bias

																									if i == 0:
																																_SCREAMING_SNAKE_CASE		:						Dict			  =    torch.cat([weight_i, self.cluster_weight]      ,    dim=0)
																																_SCREAMING_SNAKE_CASE		:						Tuple			  =    torch.cat([bias_i, self.cluster_bias]      ,    dim=0)

																									weights.append(_A)
																									biases.append(_A)

																		_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    weights[0], biases[0], self.out_projs[0]
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    self._compute_logit(_A      ,    _A      ,    _A      ,    _A)

																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    hidden.new_empty((head_logit.size(0), self.n_token))
																		_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    nn.functional.log_softmax(_A      ,    dim=1)

																		_SCREAMING_SNAKE_CASE		:						str			  =    [0] + self.cutoffs
																		for i in range(len(_A) - 1):
																									_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						List[str]			  =    cutoff_values[i], cutoff_values[i + 1]

																									if i == 0:
																																_SCREAMING_SNAKE_CASE		:						List[Any]			  =    head_logprob[:, : self.cutoffs[0]]
																									else:
																																_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    weights[i], biases[i], self.out_projs[i]

																																_SCREAMING_SNAKE_CASE		:						Any			  =    self._compute_logit(_A      ,    _A      ,    _A      ,    _A)
																																_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    nn.functional.log_softmax(_A      ,    dim=1)

																																_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    head_logprob[:, -i] + tail_logprob_i
																																_SCREAMING_SNAKE_CASE		:						Dict			  =    logprob_i

																		return out



"""simple docstring"""





from decimal import Decimal, getcontext
from math import ceil, factorial



def      lowerCamelCase_(__SCREAMING_SNAKE_CASE  )->    str:

							if not isinstance(__SCREAMING_SNAKE_CASE     ,	__SCREAMING_SNAKE_CASE  ):
														raise TypeError("""Undefined for non-integers"""  )
							elif precision < 1:
														raise ValueError("""Undefined for non-natural numbers"""  )

							_SCREAMING_SNAKE_CASE		:						int			  =    precision
							_SCREAMING_SNAKE_CASE		:						Dict			  =    ceil(precision / 14  )
							_SCREAMING_SNAKE_CASE		:						int			  =    426_880 * Decimal(10_005  ).sqrt()
							_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    1
							_SCREAMING_SNAKE_CASE		:						str			  =    13_591_409
							_SCREAMING_SNAKE_CASE		:						Tuple			  =    Decimal(__SCREAMING_SNAKE_CASE  )
							for k in range(1     ,	__SCREAMING_SNAKE_CASE  ):
														_SCREAMING_SNAKE_CASE		:						Tuple			  =    factorial(6 * k  ) // (factorial(3 * k  ) * factorial(__SCREAMING_SNAKE_CASE  ) ** 3)
														linear_term += 545_140_134
														exponential_term *= -262_537_412_640_768_000
														partial_sum += Decimal(multinomial_term * linear_term  ) / exponential_term
							return str(constant_term / partial_sum  )[:-1]


if __name__ == "__main__":
			lowerCAmelCase_     =	50
			print(F"The first {n} digits of pi is: {pi(n)}")


