'''simple docstring'''

from typing import Dict, Iterable, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format, to_pil_image
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_pytesseract_available, is_vision_available, logging, requires_backends


if is_vision_available():
  import PIL

# soft dependency
if is_pytesseract_available():
  import pytesseract

__a:			Any	       =       logging.get_logger(__name__)
def       __UpperCamelCase	(       UpperCAmelCase		,					UpperCAmelCase		,					UpperCAmelCase					):
 return [
     int(1000 * (box[0] / width)					),
     int(1000 * (box[1] / height)					),
     int(1000 * (box[2] / width)					),
     int(1000 * (box[3] / height)					),
 ]
def       __UpperCamelCase	(       UpperCAmelCase		,					UpperCAmelCase		,					UpperCAmelCase					):
 lowercase__    :   str						= to_pil_image(UpperCAmelCase					)
 lowercase__			,							lowercase__    :   Optional[int]						= pil_image.size
 lowercase__    :   List[str]						= pytesseract.image_to_data(UpperCAmelCase		,					lang=UpperCAmelCase		,					output_type='''dict'''		,					config=UpperCAmelCase					)
 lowercase__			,							lowercase__			,							lowercase__			,							lowercase__			,							lowercase__    :   Union[str, Any]						= data['''text'''], data['''left'''], data['''top'''], data['''width'''], data['''height''']

 # filter empty words and corresponding coordinates
 lowercase__    :   int						= [idx for idx, word in enumerate(UpperCAmelCase					) if not word.strip()]
 lowercase__    :   Optional[Any]						= [word for idx, word in enumerate(UpperCAmelCase					) if idx not in irrelevant_indices]
 lowercase__    :   Optional[int]						= [coord for idx, coord in enumerate(UpperCAmelCase					) if idx not in irrelevant_indices]
 lowercase__    :   Any						= [coord for idx, coord in enumerate(UpperCAmelCase					) if idx not in irrelevant_indices]
 lowercase__    :   Optional[int]						= [coord for idx, coord in enumerate(UpperCAmelCase					) if idx not in irrelevant_indices]
 lowercase__    :   Tuple						= [coord for idx, coord in enumerate(UpperCAmelCase					) if idx not in irrelevant_indices]

 # turn coordinates into (left, top, left+width, top+height) format
 lowercase__    :   Union[str, Any]						= []
 for x, y, w, h in zip(UpperCAmelCase		,					UpperCAmelCase		,					UpperCAmelCase		,					UpperCAmelCase					):
  lowercase__    :   str						= [x, y, x + w, y + h]
  actual_boxes.append(UpperCAmelCase					)

 # finally, normalize the bounding boxes
 lowercase__    :   List[str]						= []
 for box in actual_boxes:
  normalized_boxes.append(normalize_box(UpperCAmelCase		,					UpperCAmelCase		,					UpperCAmelCase					)					)

 assert len(UpperCAmelCase					) == len(UpperCAmelCase					), "Not as many words as there are bounding boxes"

 return words, normalized_boxes





class       UpperCAmelCase  (						a__ ):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE 		=   ["pixel_values"]

       def __init__(						self     ,       __lowerCAmelCase = True     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = PILImageResampling.BILINEAR     ,       __lowerCAmelCase = True     ,       __lowerCAmelCase = 1 / 255     ,       __lowerCAmelCase = True     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = True     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = ""     ,       **__lowerCAmelCase     ,       )  ->  None:
        super().__init__(**__lowerCAmelCase			)
        lowercase__    :   Tuple						= size if size is not None else {'''height''': 224, '''width''': 224}
        lowercase__    :   int						= get_size_dict(__lowerCAmelCase			)

        lowercase__    :   Any						= do_resize
        lowercase__    :   List[Any]						= size
        lowercase__    :   Optional[int]						= resample
        lowercase__    :   Optional[int]						= do_rescale
        lowercase__    :   Union[str, Any]						= rescale_value
        lowercase__    :   int						= do_normalize
        lowercase__    :   List[str]						= image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        lowercase__    :   List[Any]						= image_std if image_std is not None else IMAGENET_STANDARD_STD
        lowercase__    :   Union[str, Any]						= apply_ocr
        lowercase__    :   Tuple						= ocr_lang
        lowercase__    :   int						= tesseract_config

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase = PILImageResampling.BILINEAR     ,       __lowerCAmelCase = None     ,       **__lowerCAmelCase     ,       )  ->  np.ndarray:
        lowercase__    :   Tuple						= get_size_dict(__lowerCAmelCase			)
        if "height" not in size or "width" not in size:
         raise ValueError(F"""The size dictionary must contain the keys 'height' and 'width'. Got {size.keys()}"""			)
        lowercase__    :   List[str]						= (size['''height'''], size['''width'''])
        return resize(__lowerCAmelCase     ,       size=__lowerCAmelCase     ,       resample=__lowerCAmelCase     ,       data_format=__lowerCAmelCase     ,       **__lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase = None     ,       **__lowerCAmelCase     ,       )  ->  np.ndarray:
        return rescale(__lowerCAmelCase     ,       scale=__lowerCAmelCase     ,       data_format=__lowerCAmelCase     ,       **__lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase = None     ,       **__lowerCAmelCase     ,       )  ->  np.ndarray:
        return normalize(__lowerCAmelCase     ,       mean=__lowerCAmelCase     ,       std=__lowerCAmelCase     ,       data_format=__lowerCAmelCase     ,       **__lowerCAmelCase			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase=None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = ChannelDimension.FIRST     ,       **__lowerCAmelCase     ,       )  ->  PIL.Image.Image:
        lowercase__    :   Optional[Any]						= do_resize if do_resize is not None else self.do_resize
        lowercase__    :   Optional[int]						= size if size is not None else self.size
        lowercase__    :   Optional[Any]						= get_size_dict(__lowerCAmelCase			)
        lowercase__    :   Any						= resample if resample is not None else self.resample
        lowercase__    :   Dict						= do_rescale if do_rescale is not None else self.do_rescale
        lowercase__    :   Tuple						= rescale_factor if rescale_factor is not None else self.rescale_factor
        lowercase__    :   Tuple						= do_normalize if do_normalize is not None else self.do_normalize
        lowercase__    :   Union[str, Any]						= image_mean if image_mean is not None else self.image_mean
        lowercase__    :   List[Any]						= image_std if image_std is not None else self.image_std
        lowercase__    :   Tuple						= apply_ocr if apply_ocr is not None else self.apply_ocr
        lowercase__    :   Optional[int]						= ocr_lang if ocr_lang is not None else self.ocr_lang
        lowercase__    :   Dict						= tesseract_config if tesseract_config is not None else self.tesseract_config

        lowercase__    :   Dict						= make_list_of_images(__lowerCAmelCase			)

        if not valid_images(__lowerCAmelCase			):
         raise ValueError(
             '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
             '''torch.Tensor, tf.Tensor or jax.ndarray.'''			)

        if do_resize and size is None:
         raise ValueError('''Size must be specified if do_resize is True.'''			)

        if do_rescale and rescale_factor is None:
         raise ValueError('''Rescale factor must be specified if do_rescale is True.'''			)

        if do_normalize and (image_mean is None or image_std is None):
         raise ValueError('''If do_normalize is True, image_mean and image_std must be specified.'''			)

        # All transformations expect numpy arrays.
        lowercase__    :   Dict						= [to_numpy_array(__lowerCAmelCase			) for image in images]

        # Tesseract OCR to get words + normalized bounding boxes
        if apply_ocr:
         requires_backends(self     ,       '''pytesseract'''			)
         lowercase__    :   Tuple						= []
         lowercase__    :   List[Any]						= []
         for image in images:
          lowercase__			,							lowercase__    :   Optional[Any]						= apply_tesseract(__lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)
          words_batch.append(__lowerCAmelCase			)
          boxes_batch.append(__lowerCAmelCase			)

        if do_resize:
         lowercase__    :   Any						= [self.resize(image=__lowerCAmelCase     ,       size=__lowerCAmelCase     ,       resample=__lowerCAmelCase			) for image in images]

        if do_rescale:
         lowercase__    :   str						= [self.rescale(image=__lowerCAmelCase     ,       scale=__lowerCAmelCase			) for image in images]

        if do_normalize:
         lowercase__    :   int						= [self.normalize(image=__lowerCAmelCase     ,       mean=__lowerCAmelCase     ,       std=__lowerCAmelCase			) for image in images]

        lowercase__    :   Optional[Any]						= [to_channel_dimension_format(__lowerCAmelCase     ,       __lowerCAmelCase			) for image in images]

        lowercase__    :   Tuple						= BatchFeature(data={'''pixel_values''': images}     ,       tensor_type=__lowerCAmelCase			)

        if apply_ocr:
         lowercase__    :   List[Any]						= words_batch
         lowercase__    :   int						= boxes_batch
        return data


'''simple docstring'''

def       __UpperCamelCase	(       ):
 lowercase__    :   Any						= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

 lowercase__    :   Any						= 6
 lowercase__    :   Optional[Any]						= 1
 lowercase__    :   int						= 1901

 lowercase__    :   List[str]						= 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
    lowercase__    :   List[Any]						= day - days_per_month[month - 2]
   elif day > 29 and month == 2:
    month += 1
    lowercase__    :   Any						= day - 29
  else:
   if day > days_per_month[month - 1]:
    month += 1
    lowercase__    :   List[Any]						= day - days_per_month[month - 2]

  if month > 12:
   year += 1
   lowercase__    :   Dict						= 1

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


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

