





import tensorflow as tf

from ...tf_utils import shape_list



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






			def __init__(self   ,				__magic_name__   ,				__magic_name__   ,				__magic_name__   ,				__magic_name__   ,				__magic_name__=1   ,				__magic_name__=False   ,				**__magic_name__       )	->  Dict:


							'''simple docstring'''



							super().__init__(**__magic_name__       )

							snake_case_		:       List[Any]           =    vocab_size
							snake_case_		:       Dict           =    d_embed
							snake_case_		:       Union[str, Any]           =    d_proj

							snake_case_		:       str           =    cutoffs + [vocab_size]
							snake_case_		:       int           =    [0] + self.cutoffs
							snake_case_		:       Optional[int]           =    div_val

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

							snake_case_		:       int           =    []
							snake_case_		:       Union[str, Any]           =    []






			def      lowerCamelCase    (self   ,				__magic_name__       )	->  Union[str, Any]:


							'''simple docstring'''



							if self.n_clusters > 0:
											snake_case_		:       Tuple           =    self.add_weight(
											    shape=(self.n_clusters, self.d_embed)   ,				initializer='''zeros'''   ,				trainable=__magic_name__   ,				name='''cluster_weight'''       )
											snake_case_		:       Optional[Any]           =    self.add_weight(
											    shape=(self.n_clusters,)   ,				initializer='''zeros'''   ,				trainable=__magic_name__   ,				name='''cluster_bias'''       )

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

															snake_case_		:       int           =    self.add_weight(
															    shape=(d_emb_i, self.d_proj)   ,				initializer='''zeros'''   ,				trainable=__magic_name__   ,				name=F'''out_projs_._{i}'''       )
															self.out_projs.append(__magic_name__       )
															snake_case_		:       int           =    self.add_weight(
															    shape=(r_idx - l_idx, d_emb_i)   ,				initializer='''zeros'''   ,				trainable=__magic_name__   ,				name=F'''out_layers_._{i}_._weight'''   ,				)
															snake_case_		:       Any           =    self.add_weight(
															    shape=(r_idx - l_idx,)   ,				initializer='''zeros'''   ,				trainable=__magic_name__   ,				name=F'''out_layers_._{i}_._bias'''   ,				)
															self.out_layers.append((weight, bias)       )
							super().build(__magic_name__       )






			@staticmethod
			def      lowerCamelCase    (__magic_name__   ,				__magic_name__   ,				__magic_name__   ,				__magic_name__=None       )	->  str:


							'''simple docstring'''



							snake_case_		:       Union[str, Any]           =    x
							if proj is not None:
											snake_case_		:       List[str]           =    tf.einsum('''ibd,ed->ibe'''   ,				__magic_name__   ,				__magic_name__       )
							return tf.einsum('''ibd,nd->ibn'''   ,				__magic_name__   ,				__magic_name__       ) + b






			@staticmethod
			def      lowerCamelCase    (__magic_name__   ,				__magic_name__       )	->  Any:


							'''simple docstring'''



							snake_case_		:       Union[str, Any]           =    shape_list(__magic_name__       )
							snake_case_		:       Tuple           =    tf.range(lp_size[0]   ,				dtype=target.dtype       )
							snake_case_		:       Dict           =    tf.stack([r, target]   ,				1       )
							return tf.gather_nd(__magic_name__   ,				__magic_name__       )






			def      lowerCamelCase    (self   ,				__magic_name__   ,				__magic_name__   ,				__magic_name__=True   ,				__magic_name__=False       )	->  str:


							'''simple docstring'''



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

															if self.div_val == 1:
																			snake_case_		:       Any           =    self.out_layers[0][0][l_idx:r_idx]
																			snake_case_		:       Dict           =    self.out_layers[0][1][l_idx:r_idx]
															else:
																			snake_case_		:       Union[str, Any]           =    self.out_layers[i][0]
																			snake_case_		:       int           =    self.out_layers[i][1]

															if i == 0:
																			snake_case_		:       List[Any]           =    tf.concat([cur_W, self.cluster_weight]   ,				0       )
																			snake_case_		:       Tuple           =    tf.concat([cur_b, self.cluster_bias]   ,				0       )

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

							if target is not None:
											if return_mean:
															snake_case_		:       int           =    tf.reduce_mean(__magic_name__       )
											# Add the training-time loss value to the layer using `self.add_loss()`.
											self.add_loss(__magic_name__       )

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

							return out




def     __SCREAMING_SNAKE_CASE							(       )		->     Optional[int]:




						'''simple docstring'''







						__UpperCAmelCase			:							str	    =	[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

						__UpperCAmelCase			:							Union[str, Any]	    =	6
						__UpperCAmelCase			:							Optional[Any]	    =	1
						__UpperCAmelCase			:							Tuple	    =	1901

						__UpperCAmelCase			:							Any	    =	0

						while year < 2001:
												day += 7

												if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
																		if day > days_per_month[month - 1] and month != 2:
																								month += 1
																								__UpperCAmelCase			:							Optional[int]	    =	day - days_per_month[month - 2]
																		elif day > 29 and month == 2:
																								month += 1
																								__UpperCAmelCase			:							Optional[Any]	    =	day - 29
												else:
																		if day > days_per_month[month - 1]:
																								month += 1
																								__UpperCAmelCase			:							Optional[Any]	    =	day - days_per_month[month - 2]

												if month > 12:
																		year += 1
																		__UpperCAmelCase			:							int	    =	1

												if year < 2001 and day == 1:
																		sundays += 1
						return sundays


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

