



'''simple docstring'''


import torch

from transformers import AutoModel







class 	UpperCAmelCase	(		torch.nn.Module):


	'''simple docstring'''




	def __init__(   self							,  lowerCAmelCase_="sayef/fsner-bert-base-uncased") ->      Tuple:



						"""simple docstring"""







						super(UpperCAmelCase__							,  self).__init__()

						a_       		=AutoModel.from_pretrained(UpperCAmelCase__							,  return_dict=UpperCAmelCase__)
						a_       		=torch.nn.CosineSimilarity(3							,  1e-08)
						a_       		=torch.nn.Softmax(dim=1)




	def       lowercase_  (   self							,  **lowerCAmelCase_) ->      Tuple:



						"""simple docstring"""







						return self.bert(**UpperCAmelCase__).last_hidden_state




	def       lowercase_  (   self							,  lowerCAmelCase_) ->      Tuple:



						"""simple docstring"""







						return token_embeddings.sum(2							,  keepdim=UpperCAmelCase__)




	def       lowercase_  (   self							,  lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_=1) ->      List[str]:



						"""simple docstring"""







						return self.softmax(T * self.cos(UpperCAmelCase__							,  UpperCAmelCase__))




	def       lowercase_  (   self							,  lowerCAmelCase_							,  lowerCAmelCase_) ->      str:



						"""simple docstring"""







						a_       		=W_supports['''sizes'''].tolist()
						a_       		=W_supports['''start_token_id'''].item()
						a_       		=W_supports['''end_token_id'''].item()

						del W_supports["sizes"]
						del W_supports["start_token_id"]
						del W_supports["end_token_id"]

						a_       		=self.BERT(**UpperCAmelCase__)
						a_       		=self.BERT(**UpperCAmelCase__)

						a_       		=None
						a_       		=None

						a_       		=W_supports['''input_ids'''] == start_token_id
						a_       		=W_supports['''input_ids'''] == end_token_id

						for i, size in enumerate(UpperCAmelCase__):
											if i == 0:
																a_       		=0
											else:
																a_       		=support_sizes[i - 1]

											a_       		=S[s : s + size][start_token_masks[s : s + size]]
											a_       		=S[s : s + size][end_token_masks[s : s + size]]

											a_       		=torch.matmul(q[i]							,  s_start.T).sum(1).softmax(0)
											a_       		=torch.matmul(q[i]							,  s_end.T).sum(1).softmax(0)

											if p_starts is not None:
																a_       		=torch.vstack((p_starts, p_start))
																a_       		=torch.vstack((p_ends, p_end))
											else:
																a_       		=p_start
																a_       		=p_end

						return p_starts, p_ends







'''simple docstring'''


from __future__ import annotations






def  UpperCAmelCase_       (		lowercase__       ):


     '''simple docstring'''







     a_       		=str(lowercase__       )
     return len(lowercase__       ) == 9 and set(lowercase__       ) == set("123456789"       )






def  UpperCAmelCase_       (		):


     '''simple docstring'''







     for base_num in range(9_9_9_9       ,	4_9_9_9       ,	-1       ):
          a_       		=1_0_0_0_0_2 * base_num
          if is_9_pandigital(lowercase__       ):
               return candidate

     for base_num in range(3_3_3       ,	9_9       ,	-1       ):
          a_       		=1_0_0_2_0_0_3 * base_num
          if is_9_pandigital(lowercase__       ):
               return candidate

     return None


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


