


'''simple docstring'''






import argparse
import json
from typing import List

from ltp import LTP

from transformers import BertTokenizer






def 	_A				(lowerCAmelCase__  :Union[str, Any]		)   ->  Optional[Any]:




     '''simple docstring'''



     if (
         (cp >= 0x4_e_0_0 and cp <= 0x9_f_f_f)
         or (cp >= 0x3_4_0_0 and cp <= 0x4_d_b_f)  #
         or (cp >= 0x2_0_0_0_0 and cp <= 0x2_a_6_d_f)  #
         or (cp >= 0x2_a_7_0_0 and cp <= 0x2_b_7_3_f)  #
         or (cp >= 0x2_b_7_4_0 and cp <= 0x2_b_8_1_f)  #
         or (cp >= 0x2_b_8_2_0 and cp <= 0x2_c_e_a_f)  #
         or (cp >= 0xf_9_0_0 and cp <= 0xf_a_f_f)
         or (cp >= 0x2_f_8_0_0 and cp <= 0x2_f_a_1_f)  #
     ):  #
          return True

     return False






def 	_A				(lowerCAmelCase__  :str		)   ->  Optional[int]:




     '''simple docstring'''



     for char in word:
          _a			      =							ord(lowerCAmelCase__		)
          if not _is_chinese_char(lowerCAmelCase__		):
               return 0
     return 1






def 	_A				(lowerCAmelCase__  :List[str]		)   ->  Any:




     '''simple docstring'''



     _a			      =							set()

     for token in tokens:
          _a			      =							len(lowerCAmelCase__		) > 1 and is_chinese(lowerCAmelCase__		)
          if chinese_word:
               word_set.add(lowerCAmelCase__		)
     _a			      =							list(lowerCAmelCase__		)
     return word_list






def 	_A				(lowerCAmelCase__  :List[str]				,						lowerCAmelCase__  :set()		)   ->  int:




     '''simple docstring'''



     if not chinese_word_set:
          return bert_tokens
     _a			      =							max([len(lowerCAmelCase__		) for w in chinese_word_set]		)

     _a			      =							bert_tokens
     _a      ,   _a			      =							0, len(lowerCAmelCase__		)
     while start < end:
          _a			      =							True
          if is_chinese(bert_word[start]		):
               _a			      =							min(end - start				,						lowerCAmelCase__		)
               for i in range(lowerCAmelCase__				,						1				,						-1		):
                    _a			      =							''.join(bert_word[start : start + i]		)
                    if whole_word in chinese_word_set:
                         for j in range(start + 1				,						start + i		):
                              _a			      =							'##' + bert_word[j]
                         _a			      =							start + i
                         _a			      =							False
                         break
          if single_word:
               start += 1
     return bert_word






def 	_A				(lowerCAmelCase__  :List[str]				,						lowerCAmelCase__  :LTP				,						lowerCAmelCase__  :BertTokenizer		)   ->  List[str]:




     '''simple docstring'''



     _a			      =							[]

     for i in range(0				,						len(lowerCAmelCase__		)				,						1_00		):
          _a			      =							ltp_tokenizer.seg(lines[i : i + 1_00]		)[0]
          _a			      =							[get_chinese_word(lowerCAmelCase__		) for r in res]
          ltp_res.extend(lowerCAmelCase__		)
     assert len(lowerCAmelCase__		) == len(lowerCAmelCase__		)

     _a			      =							[]
     for i in range(0				,						len(lowerCAmelCase__		)				,						1_00		):
          _a			      =							bert_tokenizer(lines[i : i + 1_00]				,						add_special_tokens=lowerCAmelCase__				,						truncation=lowerCAmelCase__				,						max_length=5_12		)
          bert_res.extend(res['input_ids']		)
     assert len(lowerCAmelCase__		) == len(lowerCAmelCase__		)

     _a			      =							[]
     for input_ids, chinese_word in zip(lowerCAmelCase__				,						lowerCAmelCase__		):
          _a			      =							[]
          for id in input_ids:
               _a			      =							bert_tokenizer._convert_id_to_token(lowerCAmelCase__		)
               input_tokens.append(lowerCAmelCase__		)
          _a			      =							add_sub_symbol(lowerCAmelCase__				,						lowerCAmelCase__		)
          _a			      =							[]
          # We only save pos of chinese subwords start with ##, which mean is part of a whole word.
          for i, token in enumerate(lowerCAmelCase__		):
               if token[:2] == "##":
                    _a			      =							token[2:]
                    # save chinese tokens' pos
                    if len(lowerCAmelCase__		) == 1 and _is_chinese_char(ord(lowerCAmelCase__		)		):
                         ref_id.append(lowerCAmelCase__		)
          ref_ids.append(lowerCAmelCase__		)

     assert len(lowerCAmelCase__		) == len(lowerCAmelCase__		)

     return ref_ids






def 	_A				(lowerCAmelCase__  :Union[str, Any]		)   ->  Optional[Any]:




     '''simple docstring'''



     with open(args.file_name				,						'r'				,						encoding='utf-8'		) as f:
          _a			      =							f.readlines()
     _a			      =							[line.strip() for line in data if len(lowerCAmelCase__		) > 0 and not line.isspace()]  # avoid delimiter like '\u2029'
     _a			      =							LTP(args.ltp		)  # faster in GPU device
     _a			      =							BertTokenizer.from_pretrained(args.bert		)

     _a			      =							prepare_ref(lowerCAmelCase__				,						lowerCAmelCase__				,						lowerCAmelCase__		)

     with open(args.save_path				,						'w'				,						encoding='utf-8'		) as f:
          _a			      =							[json.dumps(lowerCAmelCase__		) + '\n' for ref in ref_ids]
          f.writelines(lowerCAmelCase__		)


if __name__ == "__main__":
 a_					:    Dict          =    argparse.ArgumentParser(description="prepare_chinese_ref")
 parser.add_argument(
     "--file_name",
     type=str,
     default="./resources/chinese-demo.txt",
     help="file need process, same as training data in lm",
 )
 parser.add_argument(
     "--ltp", type=str, default="./resources/ltp", help="resources for LTP tokenizer, usually a path"
 )
 parser.add_argument("--bert", type=str, default="./resources/robert", help="resources for Bert tokenizer")
 parser.add_argument("--save_path", type=str, default="./resources/ref.txt", help="path to save res")

 a_					:    str          =    parser.parse_args()
 main(args)





'''simple docstring'''






from functools import reduce

a_					:    Any          =    (
    "73167176531330624919225119674426574742355349194934"
    "96983520312774506326239578318016984801869478851843"
    "85861560789112949495459501737958331952853208805511"
    "12540698747158523863050715693290963295227443043557"
    "66896648950445244523161731856403098711121722383113"
    "62229893423380308135336276614282806444486645238749"
    "30358907296290491560440772390713810515859307960866"
    "70172427121883998797908792274921901699720888093776"
    "65727333001053367881220235421809751254540594752243"
    "52584907711670556013604839586446706324415722155397"
    "53697817977846174064955149290862569321978468622482"
    "83972241375657056057490261407972968652414535100474"
    "82166370484403199890008895243450658541227588666881"
    "16427171479924442928230863465674813919123162824586"
    "17866458359124566529476545682848912883142607690042"
    "24219022671055626321111109370544217506941658960408"
    "07198403850962455444362981230987879927244284909188"
    "84580156166097919133875499200524063689912560717606"
    "05886116467109405077541002256983155200055935729725"
    "71636269561882670428252483600823257530420752963450"
)






def 	_A				(lowerCAmelCase__  :str = N		)   ->  int:




     '''simple docstring'''



     return max(
         # mypy cannot properly interpret reduce
         int(reduce(lambda lowerCAmelCase__				,						lowerCAmelCase__		: str(int(lowerCAmelCase__		) * int(lowerCAmelCase__		)		)				,						n[i : i + 13]		)		)
         for i in range(len(lowerCAmelCase__		) - 12		)		)


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

