


"""simple docstring"""


import argparse
import shutil
from pathlib import Path

from tqdm import tqdm

from transformers import AutoTokenizer




def   snake_case		(     UpperCamelCase__       :						Any			,				UpperCamelCase__       :						Union[str, Any]			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						Optional[int]=1024    )   ->      Any:

      '''simple docstring'''





      lowerCamelCase					:					Union[str, Any]        =	[], []

      lowerCamelCase					:					List[str]        =	list(zip(UpperCamelCase__			,				UpperCamelCase__    )    )
      lowerCamelCase					:					List[Any]        =	sorted_examples[0]

      def is_too_big(UpperCamelCase__       :						Tuple    ):
            return tok(UpperCamelCase__			,				return_tensors="""pt"""    ).input_ids.shape[1] > max_tokens

      for src, tgt in tqdm(sorted_examples[1:]    ):
            lowerCamelCase					:					Optional[Any]        =	new_src + """ """ + src
            lowerCamelCase					:					int        =	new_tgt + """ """ + tgt
            if is_too_big(UpperCamelCase__    ) or is_too_big(UpperCamelCase__    ):  # cant fit, finalize example
                  finished_src.append(UpperCamelCase__    )
                  finished_tgt.append(UpperCamelCase__    )
                  lowerCamelCase					:					Tuple        =	src, tgt
            else:  # can fit, keep adding
                  lowerCamelCase					:					int        =	cand_src, cand_tgt

    # cleanup
      if new_src:
            assert new_tgt
            finished_src.append(UpperCamelCase__    )
            finished_tgt.append(UpperCamelCase__    )
      return finished_src, finished_tgt




def   snake_case		(     UpperCamelCase__       :						Any			,				UpperCamelCase__       :						Path			,				UpperCamelCase__       :						Any			,				UpperCamelCase__       :						List[Any]    )   ->      Optional[int]:

      '''simple docstring'''





      lowerCamelCase					:					List[str]        =	Path(UpperCamelCase__    )
      save_path.mkdir(exist_ok=UpperCamelCase__    )
      for split in ["train"]:
            lowerCamelCase					:					int        =	data_dir / F'{split}.source', data_dir / F'{split}.target'
            lowerCamelCase					:					Optional[int]        =	[x.rstrip() for x in Path(UpperCamelCase__    ).open().readlines()]
            lowerCamelCase					:					Optional[Any]        =	[x.rstrip() for x in Path(UpperCamelCase__    ).open().readlines()]
            lowerCamelCase					:					Union[str, Any]        =	pack_examples(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )
            print(F'packed {split} split from {len(UpperCamelCase__    )} examples -> {len(UpperCamelCase__    )}.'    )
            Path(save_path / F'{split}.source'    ).open("""w"""    ).write("""\n""".join(UpperCamelCase__    )    )
            Path(save_path / F'{split}.target'    ).open("""w"""    ).write("""\n""".join(UpperCamelCase__    )    )
      for split in ["val", "test"]:
            lowerCamelCase					:					int        =	data_dir / F'{split}.source', data_dir / F'{split}.target'
            shutil.copyfile(UpperCamelCase__			,				save_path / F'{split}.source'    )
            shutil.copyfile(UpperCamelCase__			,				save_path / F'{split}.target'    )




def   snake_case		(     )   ->      Any:

      '''simple docstring'''





      lowerCamelCase					:					int        =	argparse.ArgumentParser()
      parser.add_argument("""--tok_name"""			,				type=UpperCamelCase__			,				help="""like facebook/bart-large-cnn,t5-base, etc."""    )
      parser.add_argument("""--max_seq_len"""			,				type=UpperCamelCase__			,				default=128    )
      parser.add_argument("""--data_dir"""			,				type=UpperCamelCase__    )
      parser.add_argument("""--save_path"""			,				type=UpperCamelCase__    )
      lowerCamelCase					:					Any        =	parser.parse_args()
      lowerCamelCase					:					List[str]        =	AutoTokenizer.from_pretrained(args.tok_name    )
      return pack_data_dir(UpperCamelCase__			,				Path(args.data_dir    )			,				args.max_seq_len			,				args.save_path    )


if __name__ == "__main__":
    packer_cli()








"""simple docstring"""


import os




def   snake_case		(     )   ->      Optional[Any]:
      with open(os.path.dirname(UpperCamelCase__    ) + """/grid.txt"""    ) as f:
            lowerCamelCase					:					int        =	[]  # noqa: E741
            for _ in range(20    ):
                  l.append([int(UpperCamelCase__    ) for x in f.readline().split()]    )

            lowerCamelCase					:					Union[str, Any]        =	0

            # right
            for i in range(20    ):
                  for j in range(17    ):
                        lowerCamelCase					:					Dict        =	l[i][j] * l[i][j + 1] * l[i][j + 2] * l[i][j + 3]
                        if temp > maximum:
                              lowerCamelCase					:					Tuple        =	temp

        # down
            for i in range(17    ):
                  for j in range(20    ):
                        lowerCamelCase					:					Any        =	l[i][j] * l[i + 1][j] * l[i + 2][j] * l[i + 3][j]
                        if temp > maximum:
                              lowerCamelCase					:					Optional[Any]        =	temp

        # diagonal 1
            for i in range(17    ):
                  for j in range(17    ):
                        lowerCamelCase					:					List[Any]        =	l[i][j] * l[i + 1][j + 1] * l[i + 2][j + 2] * l[i + 3][j + 3]
                        if temp > maximum:
                              lowerCamelCase					:					List[str]        =	temp

        # diagonal 2
            for i in range(17    ):
                  for j in range(3			,				20    ):
                        lowerCamelCase					:					List[str]        =	l[i][j] * l[i + 1][j - 1] * l[i + 2][j - 2] * l[i + 3][j - 3]
                        if temp > maximum:
                              lowerCamelCase					:					List[Any]        =	temp
            return maximum


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




