



'''simple docstring'''



import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import SPIECE_UNDERLINE, logging


lowerCamelCase	 =       logging.get_logger(__name__)

lowerCamelCase	 =       {"""vocab_file""": """spiece.model"""}

lowerCamelCase	 =       {
    """vocab_file""": {
        """xlnet-base-cased""": """https://huggingface.co/xlnet-base-cased/resolve/main/spiece.model""",
        """xlnet-large-cased""": """https://huggingface.co/xlnet-large-cased/resolve/main/spiece.model""",
    }
}

lowerCamelCase	 =       {
    """xlnet-base-cased""": None,
    """xlnet-large-cased""": None,
}

# Segments (not really needed)
lowerCamelCase	 =       0
lowerCamelCase	 =       1
lowerCamelCase	 =       2
lowerCamelCase	 =       3
lowerCamelCase	 =       4





class _UpperCamelCase		(     A		):





				'''simple docstring'''





				lowerCAmelCase__					    =    VOCAB_FILES_NAMES
				lowerCAmelCase__					    =    PRETRAINED_VOCAB_FILES_MAP
				lowerCAmelCase__					    =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCAmelCase__					    =    """left"""

				def __init__(							self  :  Union[str, Any]  ,       _lowerCAmelCase  :  Union[str, Any]  ,       _lowerCAmelCase  :  Optional[int]=False  ,       _lowerCAmelCase  :  Optional[int]=True  ,       _lowerCAmelCase  :  Optional[Any]=False  ,       _lowerCAmelCase  :  Optional[int]="<s>"  ,       _lowerCAmelCase  :  Optional[int]="</s>"  ,       _lowerCAmelCase  :  Optional[int]="<unk>"  ,       _lowerCAmelCase  :  List[Any]="<sep>"  ,       _lowerCAmelCase  :  List[str]="<pad>"  ,       _lowerCAmelCase  :  List[str]="<cls>"  ,       _lowerCAmelCase  :  Dict="<mask>"  ,       _lowerCAmelCase  :  Union[str, Any]=["<eop>", "<eod>"]  ,       _lowerCAmelCase  :  Optional[Dict[str, Any]] = None  ,       **_lowerCAmelCase  :  Optional[Any]  ,       ):







											'''simple docstring'''

											__lowercase       	=AddedToken(_lowerCAmelCase  ,       lstrip=_lowerCAmelCase  ,       rstrip=_lowerCAmelCase) if isinstance(_lowerCAmelCase  ,       _lowerCAmelCase) else mask_token

											__lowercase       	={} if sp_model_kwargs is None else sp_model_kwargs

											super().__init__(
											    do_lower_case=_lowerCAmelCase  ,       remove_space=_lowerCAmelCase  ,       keep_accents=_lowerCAmelCase  ,       bos_token=_lowerCAmelCase  ,       eos_token=_lowerCAmelCase  ,       unk_token=_lowerCAmelCase  ,       sep_token=_lowerCAmelCase  ,       pad_token=_lowerCAmelCase  ,       cls_token=_lowerCAmelCase  ,       mask_token=_lowerCAmelCase  ,       additional_special_tokens=_lowerCAmelCase  ,       sp_model_kwargs=self.sp_model_kwargs  ,       **_lowerCAmelCase  ,       )

											__lowercase       	=3

											__lowercase       	=do_lower_case
											__lowercase       	=remove_space
											__lowercase       	=keep_accents
											__lowercase       	=vocab_file

											__lowercase       	=spm.SentencePieceProcessor(**self.sp_model_kwargs)
											self.sp_model.Load(_lowerCAmelCase)

				@property
				def 				__lowerCamelCase     (							self  :  List[Any]):







											'''simple docstring'''

											return len(self.sp_model)

				def 				__lowerCamelCase     (							self  :  Dict):







											'''simple docstring'''

											__lowercase       	={self.convert_ids_to_tokens(_lowerCAmelCase): i for i in range(self.vocab_size)}
											vocab.update(self.added_tokens_encoder)
											return vocab

				def __getstate__(							self  :  Tuple):







											'''simple docstring'''

											__lowercase       	=self.__dict__.copy()
											__lowercase       	=None
											return state

				def __setstate__(							self  :  int  ,       _lowerCAmelCase  :  str):







											'''simple docstring'''

											__lowercase       	=d

											# for backward compatibility
											if not hasattr(self  ,       'sp_model_kwargs'):
																		__lowercase       	={}

											__lowercase       	=spm.SentencePieceProcessor(**self.sp_model_kwargs)
											self.sp_model.Load(self.vocab_file)

				def 				__lowerCamelCase     (							self  :  str  ,       _lowerCAmelCase  :  str):







											'''simple docstring'''

											if self.remove_space:
																		__lowercase       	=' '.join(inputs.strip().split())
											else:
																		__lowercase       	=inputs
											__lowercase       	=outputs.replace('``'  ,       '"').replace('\'\''  ,       '"')

											if not self.keep_accents:
																		__lowercase       	=unicodedata.normalize('NFKD'  ,       _lowerCAmelCase)
																		__lowercase       	=''.join([c for c in outputs if not unicodedata.combining(_lowerCAmelCase)])
											if self.do_lower_case:
																		__lowercase       	=outputs.lower()

											return outputs

				def 				__lowerCamelCase     (							self  :  Union[str, Any]  ,       _lowerCAmelCase  :  str):







											'''simple docstring'''

											__lowercase       	=self.preprocess_text(_lowerCAmelCase)
											__lowercase       	=self.sp_model.encode(_lowerCAmelCase  ,       out_type=_lowerCAmelCase)
											__lowercase       	=[]
											for piece in pieces:
																		if len(_lowerCAmelCase) > 1 and piece[-1] == str(',') and piece[-2].isdigit():
																									__lowercase       	=self.sp_model.EncodeAsPieces(piece[:-1].replace(_lowerCAmelCase  ,       ''))
																									if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
																																if len(cur_pieces[0]) == 1:
																																							__lowercase       	=cur_pieces[1:]
																																else:
																																							__lowercase       	=cur_pieces[0][1:]
																									cur_pieces.append(piece[-1])
																									new_pieces.extend(_lowerCAmelCase)
																		else:
																									new_pieces.append(_lowerCAmelCase)

											return new_pieces

				def 				__lowerCamelCase     (							self  :  Optional[Any]  ,       _lowerCAmelCase  :  List[Any]):







											'''simple docstring'''

											return self.sp_model.PieceToId(_lowerCAmelCase)

				def 				__lowerCamelCase     (							self  :  List[Any]  ,       _lowerCAmelCase  :  Union[str, Any]):







											'''simple docstring'''

											return self.sp_model.IdToPiece(_lowerCAmelCase)

				def 				__lowerCamelCase     (							self  :  Optional[int]  ,       _lowerCAmelCase  :  Dict):







											'''simple docstring'''

											__lowercase       	=''.join(_lowerCAmelCase).replace(_lowerCAmelCase  ,       ' ').strip()
											return out_string

				def 				__lowerCamelCase     (							self  :  List[str]  ,       _lowerCAmelCase  :  List[int]  ,       _lowerCAmelCase  :  bool = False  ,       _lowerCAmelCase  :  bool = None  ,       _lowerCAmelCase  :  bool = True  ,       **_lowerCAmelCase  :  Dict  ,       ):







											'''simple docstring'''

											__lowercase       	=kwargs.pop('use_source_tokenizer'  ,       _lowerCAmelCase)

											__lowercase       	=self.convert_ids_to_tokens(_lowerCAmelCase  ,       skip_special_tokens=_lowerCAmelCase)

											# To avoid mixing byte-level and unicode for byte-level BPT
											# we need to build string separately for added tokens and byte-level tokens
											# cf. https://github.com/huggingface/transformers/issues/1133
											__lowercase       	=[]
											__lowercase       	=[]
											for token in filtered_tokens:
																		if skip_special_tokens and token in self.all_special_ids:
																									continue
																		if token in self.added_tokens_encoder:
																									if current_sub_text:
																																sub_texts.append(self.convert_tokens_to_string(_lowerCAmelCase))
																																__lowercase       	=[]
																									sub_texts.append(_lowerCAmelCase)
																		else:
																									current_sub_text.append(_lowerCAmelCase)
											if current_sub_text:
																		sub_texts.append(self.convert_tokens_to_string(_lowerCAmelCase))

											# Mimic the behavior of the Rust tokenizer:
											# By default, there are no spaces between special tokens
											__lowercase       	=''.join(_lowerCAmelCase)

											__lowercase       	=(
											    clean_up_tokenization_spaces
											    if clean_up_tokenization_spaces is not None
											    else self.clean_up_tokenization_spaces
											)
											if clean_up_tokenization_spaces:
																		__lowercase       	=self.clean_up_tokenization(_lowerCAmelCase)
																		return clean_text
											else:
																		return text

				def 				__lowerCamelCase     (							self  :  Tuple  ,       _lowerCAmelCase  :  List[int]  ,       _lowerCAmelCase  :  Optional[List[int]] = None):







											'''simple docstring'''

											__lowercase       	=[self.sep_token_id]
											__lowercase       	=[self.cls_token_id]
											if token_ids_a is None:
																		return token_ids_a + sep + cls
											return token_ids_a + sep + token_ids_a + sep + cls

				def 				__lowerCamelCase     (							self  :  Optional[Any]  ,       _lowerCAmelCase  :  List[int]  ,       _lowerCAmelCase  :  Optional[List[int]] = None  ,       _lowerCAmelCase  :  bool = False):







											'''simple docstring'''

											if already_has_special_tokens:
																		return super().get_special_tokens_mask(
																		    token_ids_a=_lowerCAmelCase  ,       token_ids_a=_lowerCAmelCase  ,       already_has_special_tokens=_lowerCAmelCase)

											if token_ids_a is not None:
																		return ([0] * len(_lowerCAmelCase)) + [1] + ([0] * len(_lowerCAmelCase)) + [1, 1]
											return ([0] * len(_lowerCAmelCase)) + [1, 1]

				def 				__lowerCamelCase     (							self  :  List[str]  ,       _lowerCAmelCase  :  List[int]  ,       _lowerCAmelCase  :  Optional[List[int]] = None):







											'''simple docstring'''

											__lowercase       	=[self.sep_token_id]
											__lowercase       	=[2]

											if token_ids_a is None:
																		return len(token_ids_a + sep) * [0] + cls_segment_id
											return len(token_ids_a + sep) * [0] + len(token_ids_a + sep) * [1] + cls_segment_id

				def 				__lowerCamelCase     (							self  :  Optional[int]  ,       _lowerCAmelCase  :  str  ,       _lowerCAmelCase  :  Optional[str] = None):







											'''simple docstring'''

											if not os.path.isdir(_lowerCAmelCase):
																		logger.error(f"""Vocabulary path ({save_directory}) should be a directory""")
																		return
											__lowercase       	=os.path.join(
											    _lowerCAmelCase  ,       (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file'])

											if os.path.abspath(self.vocab_file) != os.path.abspath(_lowerCAmelCase) and os.path.isfile(self.vocab_file):
																		copyfile(self.vocab_file  ,       _lowerCAmelCase)
											elif not os.path.isfile(self.vocab_file):
																		with open(_lowerCAmelCase  ,       'wb') as fi:
																									__lowercase       	=self.sp_model.serialized_model_proto()
																									fi.write(_lowerCAmelCase)

											return (out_vocab_file,)








'''simple docstring'''



def   _A       (   _lowerCAmelCase  ,   _lowerCAmelCase  ,   _lowerCAmelCase					):



							"""simple docstring"""



							if len(_lowerCAmelCase					) != len(_lowerCAmelCase					):
														raise ValueError('The length of profit and weight must be same.'					)
							if max_weight <= 0:
														raise ValueError('max_weight must greater than zero.'					)
							if any(p < 0 for p in profit					):
														raise ValueError('Profit can not be negative.'					)
							if any(w < 0 for w in weight					):
														raise ValueError('Weight can not be negative.'					)

							# List created to store profit gained for the 1kg in case of each weight
							# respectively.  Calculate and append profit/weight for each element.
							__lowercase       	=[p / w for p, w in zip(_lowerCAmelCase  ,   _lowerCAmelCase					)]

							# Creating a copy of the list and sorting profit/weight in ascending order
							__lowercase       	=sorted(_lowerCAmelCase					)

							# declaring useful variables
							__lowercase       	=len(_lowerCAmelCase					)
							__lowercase       	=0
							__lowercase       	=0
							__lowercase       	=0

							# loop till the total weight do not reach max limit e.g. 15 kg and till i<length
							while limit <= max_weight and i < length:
														# flag value for encountered greatest element in sorted_profit_by_weight
														__lowercase       	=sorted_profit_by_weight[length - i - 1]
														__lowercase       	=profit_by_weight.index(_lowerCAmelCase					)
														__lowercase       	=-1

														# check if the weight encountered is less than the total weight
														# encountered before.
														if max_weight - limit >= weight[index]:
																					limit += weight[index]
																					# Adding profit gained for the given weight 1 ===
																					# weight[index]/weight[index]
																					gain += 1 * profit[index]
														else:
																					# Since the weight encountered is greater than limit, therefore take the
																					# required number of remaining kgs and calculate profit for it.
																					# weight remaining / weight[index]
																					gain += (max_weight - limit) / weight[index] * profit[index]
																					break
														i += 1
							return gain


if __name__ == "__main__":
		print(
		    """Input profits, weights, and then max_weight (all positive ints) separated by """
		    """spaces."""
		)

		lowerCamelCase	 =       [int(x) for x in input("""Input profits separated by spaces: """).split()]
		lowerCamelCase	 =       [int(x) for x in input("""Input weights separated by spaces: """).split()]
		lowerCamelCase	 =       int(input("""Max weight allowed: """))

		# Function Call
		calc_profit(profit, weight, max_weight)



