




'''simple docstring'''


import tensorflow as tf

from ...tf_utils import shape_list

class 	__lowercase				(  tf.keras.layers.Layer    ):

			def __init__(self			,   A			,   A			,   A			,   A			,   A=1			,   A=False			,   **A      ):
								super().__init__(**A_      )

								lowerCamelCase_					:      List[Any]     =		vocab_size
								lowerCamelCase_					:      Tuple     =		d_embed
								lowerCamelCase_					:      Dict     =		d_proj

								lowerCamelCase_					:      Optional[Any]     =		cutoffs + [vocab_size]
								lowerCamelCase_					:      Any     =		[0] + self.cutoffs
								lowerCamelCase_					:      int     =		div_val

								lowerCamelCase_					:      str     =		self.cutoffs[0]
								lowerCamelCase_					:      str     =		len(self.cutoffs      ) - 1
								lowerCamelCase_					:      List[str]     =		self.shortlist_size + self.n_clusters
								lowerCamelCase_					:      List[str]     =		keep_order

								lowerCamelCase_					:      Tuple     =		[]
								lowerCamelCase_					:      List[Any]     =		[]

			def        UpperCAmelCase__ (self			,   A      ):
								if self.n_clusters > 0:
													lowerCamelCase_					:      str     =		self.add_weight(
													    shape=(self.n_clusters, self.d_embed)			,   initializer='''zeros'''			,   trainable=A_			,   name='''cluster_weight'''      )
													lowerCamelCase_					:      str     =		self.add_weight(
													    shape=(self.n_clusters,)			,   initializer='''zeros'''			,   trainable=A_			,   name='''cluster_bias'''      )

								if self.div_val == 1:
													for i in range(len(self.cutoffs      )      ):
																		if self.d_proj != self.d_embed:
																							lowerCamelCase_					:      Tuple     =		self.add_weight(
																							    shape=(self.d_embed, self.d_proj)			,   initializer='''zeros'''			,   trainable=A_			,   name=F"""out_projs_._{i}"""			,   )
																							self.out_projs.append(A_      )
																		else:
																							self.out_projs.append(A_      )
																		lowerCamelCase_					:      Optional[Any]     =		self.add_weight(
																		    shape=(self.vocab_size, self.d_embed)			,   initializer='''zeros'''			,   trainable=A_			,   name=F"""out_layers_._{i}_._weight"""			,   )
																		lowerCamelCase_					:      List[str]     =		self.add_weight(
																		    shape=(self.vocab_size,)			,   initializer='''zeros'''			,   trainable=A_			,   name=F"""out_layers_._{i}_._bias"""			,   )
																		self.out_layers.append((weight, bias)      )
								else:
													for i in range(len(self.cutoffs      )      ):
																		lowerCamelCase_,      lowerCamelCase_					:      Dict     =		self.cutoff_ends[i], self.cutoff_ends[i + 1]
																		lowerCamelCase_					:      Optional[int]     =		self.d_embed // (self.div_val**i)

																		lowerCamelCase_					:      Union[str, Any]     =		self.add_weight(
																		    shape=(d_emb_i, self.d_proj)			,   initializer='''zeros'''			,   trainable=A_			,   name=F"""out_projs_._{i}"""      )
																		self.out_projs.append(A_      )
																		lowerCamelCase_					:      int     =		self.add_weight(
																		    shape=(r_idx - l_idx, d_emb_i)			,   initializer='''zeros'''			,   trainable=A_			,   name=F"""out_layers_._{i}_._weight"""			,   )
																		lowerCamelCase_					:      Tuple     =		self.add_weight(
																		    shape=(r_idx - l_idx,)			,   initializer='''zeros'''			,   trainable=A_			,   name=F"""out_layers_._{i}_._bias"""			,   )
																		self.out_layers.append((weight, bias)      )
								super().build(A_      )

			@staticmethod
			def        UpperCAmelCase__ (A			,   A			,   A			,   A=None      ):
								lowerCamelCase_					:      str     =		x
								if proj is not None:
													lowerCamelCase_					:      List[str]     =		tf.einsum('''ibd,ed->ibe'''			,   A_			,   A_      )
								return tf.einsum('''ibd,nd->ibn'''			,   A_			,   A_      ) + b

			@staticmethod
			def        UpperCAmelCase__ (A			,   A      ):
								lowerCamelCase_					:      Union[str, Any]     =		shape_list(A_      )
								lowerCamelCase_					:      str     =		tf.range(lp_size[0]			,   dtype=target.dtype      )
								lowerCamelCase_					:      List[str]     =		tf.stack([r, target]			,   1      )
								return tf.gather_nd(A_			,   A_      )






			def        UpperCAmelCase__ (self			,   A			,   A			,   A=True			,   A=False      ):
								lowerCamelCase_					:      Optional[int]     =		0
								if self.n_clusters == 0:
													lowerCamelCase_					:      Dict     =		self._logit(A_			,   self.out_layers[0][0]			,   self.out_layers[0][1]			,   self.out_projs[0]      )
													if target is not None:
																		lowerCamelCase_					:      List[str]     =		tf.nn.sparse_softmax_cross_entropy_with_logits(labels=A_			,   logits=A_      )
													lowerCamelCase_					:      Dict     =		tf.nn.log_softmax(A_			,   axis=-1      )
								else:
													lowerCamelCase_					:      Optional[int]     =		shape_list(A_      )
													lowerCamelCase_					:      Union[str, Any]     =		[]
													lowerCamelCase_					:      Dict     =		tf.zeros(hidden_sizes[:2]      )
													for i in range(len(self.cutoffs      )      ):
																		lowerCamelCase_,      lowerCamelCase_					:      Tuple     =		self.cutoff_ends[i], self.cutoff_ends[i + 1]
																		if target is not None:
																							lowerCamelCase_					:      Dict     =		(target >= l_idx) & (target < r_idx)
																							lowerCamelCase_					:      Any     =		tf.where(A_      )
																							lowerCamelCase_					:      int     =		tf.boolean_mask(A_			,   A_      ) - l_idx

																		if self.div_val == 1:
																							lowerCamelCase_					:      Any     =		self.out_layers[0][0][l_idx:r_idx]
																							lowerCamelCase_					:      List[Any]     =		self.out_layers[0][1][l_idx:r_idx]
																		else:
																							lowerCamelCase_					:      Any     =		self.out_layers[i][0]
																							lowerCamelCase_					:      Optional[int]     =		self.out_layers[i][1]

																		if i == 0:
																							lowerCamelCase_					:      str     =		tf.concat([cur_W, self.cluster_weight]			,   0      )
																							lowerCamelCase_					:      Any     =		tf.concat([cur_b, self.cluster_bias]			,   0      )

																							lowerCamelCase_					:      List[str]     =		self._logit(A_			,   A_			,   A_			,   self.out_projs[0]      )
																							lowerCamelCase_					:      List[Any]     =		tf.nn.log_softmax(A_      )
																							out.append(head_logprob[..., : self.cutoffs[0]]      )
																							if target is not None:
																												lowerCamelCase_					:      str     =		tf.boolean_mask(A_			,   A_      )
																												lowerCamelCase_					:      Any     =		self._gather_logprob(A_			,   A_      )
																		else:
																							lowerCamelCase_					:      Union[str, Any]     =		self._logit(A_			,   A_			,   A_			,   self.out_projs[i]      )
																							lowerCamelCase_					:      List[str]     =		tf.nn.log_softmax(A_      )
																							lowerCamelCase_					:      int     =		self.cutoffs[0] + i - 1  # No probability for the head cluster
																							lowerCamelCase_					:      Optional[int]     =		head_logprob[..., cluster_prob_idx, None] + tail_logprob
																							out.append(A_      )
																							if target is not None:
																												lowerCamelCase_					:      Tuple     =		tf.boolean_mask(A_			,   A_      )
																												lowerCamelCase_					:      str     =		tf.boolean_mask(A_			,   A_      )
																												lowerCamelCase_					:      str     =		self._gather_logprob(A_			,   A_      )
																												cur_logprob += cur_head_logprob[:, self.cutoff_ends[1] + i - 1]
																		if target is not None:
																							loss += tf.scatter_nd(A_			,   -cur_logprob			,   shape_list(A_      )      )
													lowerCamelCase_					:      Union[str, Any]     =		tf.concat(A_			,   axis=-1      )

								if target is not None:
													if return_mean:
																		lowerCamelCase_					:      List[str]     =		tf.reduce_mean(A_      )
													# Add the training-time loss value to the layer using `self.add_loss()`.
													self.add_loss(A_      )

													# Log the loss as a metric (we could log arbitrary metrics,
													# including different metrics for training and inference.
													self.add_metric(A_			,   name=self.name			,   aggregation='''mean''' if return_mean else ''''''      )

								return out




'''simple docstring'''


def lowercase_	(   _lowercase = 1_000				)     ->							int:
					'''simple docstring'''

					lowerCamelCase_					:      Dict     =		2**power
					lowerCamelCase_					:      Union[str, Any]     =		str(_lowercase				)
					lowerCamelCase_					:      Union[str, Any]     =		list(_lowercase				)
					lowerCamelCase_					:      Dict     =		0

					for i in list_num:
										sum_of_num += int(_lowercase				)

					return sum_of_num


if __name__ == "__main__":
					__lowercase							:   Optional[Any]					=     int(input('''Enter the power of 2: ''').strip())
					print('''2 ^ ''', power, ''' = ''', 2**power)
					__lowercase							:   Tuple					=     solution(power)
					print('''Sum of the digits is: ''', result)


