




def 				lowerCAmelCase_	(     snake_case_     ):
      _A							:     List[Any]			=						generate_pascal_triangle(_UpperCAmelCase     )
      for row_idx in range(_UpperCAmelCase     ):
            # Print left spaces
            for _ in range(num_rows - row_idx - 1     ):
                  print(end=""" """     )
            # Print row values
            for col_idx in range(row_idx + 1     ):
                  if col_idx != row_idx:
                        print(triangle[row_idx][col_idx],end=""" """     )
                  else:
                        print(triangle[row_idx][col_idx],end=""""""     )
            print()







def 				lowerCAmelCase_	(     snake_case_     ):

      if not isinstance(_UpperCAmelCase,_UpperCAmelCase     ):
            raise TypeError("""The input value of 'num_rows' should be 'int'"""     )

      if num_rows == 0:
            return []
      elif num_rows < 0:
            raise ValueError(
                """The input value of 'num_rows' should be greater than or equal to 0"""     )

      _A							:     list[list[int]]			=						[]
      for current_row_idx in range(_UpperCAmelCase     ):
            _A							:     List[Any]			=						populate_current_row(_UpperCAmelCase,_UpperCAmelCase     )
            triangle.append(_UpperCAmelCase     )
      return triangle







def 				lowerCAmelCase_	(     snake_case_,snake_case_     ):
      _A							:     Dict			=						[-1] * (current_row_idx + 1)
      # first and last elements of current row are equal to 1
      _A							:     Tuple			=						1, 1
      for current_col_idx in range(1,_UpperCAmelCase     ):
            calculate_current_element(
                _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase     )
      return current_row







def 				lowerCAmelCase_	(     snake_case_,snake_case_,snake_case_,snake_case_,):
      _A							:     str			=						triangle[current_row_idx - 1][current_col_idx - 1]
      _A							:     Optional[int]			=						triangle[current_row_idx - 1][current_col_idx]
      _A							:     str			=						above_to_left_elt + above_to_right_elt







def 				lowerCAmelCase_	(     snake_case_     ):

      if not isinstance(_UpperCAmelCase,_UpperCAmelCase     ):
            raise TypeError("""The input value of 'num_rows' should be 'int'"""     )

      if num_rows == 0:
            return []
      elif num_rows < 0:
            raise ValueError(
                """The input value of 'num_rows' should be greater than or equal to 0"""     )

      _A							:     list[list[int]]			=						[[1]]

      for row_index in range(1,_UpperCAmelCase     ):
            _A							:     Any			=						[0] + result[-1] + [0]
            _A							:     Tuple			=						row_index + 1
            # Calculate the number of distinct elements in a row
            _A							:     Any			=						sum(divmod(_UpperCAmelCase,2     )     )
            _A							:     Optional[int]			=						[
                temp_row[i - 1] + temp_row[i] for i in range(1,distinct_elements + 1     )
            ]
            _A							:     Tuple			=						row_first_half[: (row_index + 1) // 2]
            row_second_half.reverse()
            _A							:     List[str]			=						row_first_half + row_second_half
            result.append(_UpperCAmelCase     )

      return result







def 				lowerCAmelCase_	(     ):
      from collections.abc import Callable
      from timeit import timeit

      def benchmark_a_function(snake_case_,snake_case_     ) -> None:
            _A							:     int			=						f'''{func.__name__}({value})'''
            _A							:     List[str]			=						timeit(f'''__main__.{call}''',setup="""import __main__"""     )
            # print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
            print(f'''{call:38} -- {timing:.4f} seconds'''     )

      for value in range(15     ):  # (1, 7, 14):
            for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
                  benchmark_a_function(_UpperCAmelCase,_UpperCAmelCase     )
            print()


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  benchmark()




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
						import torch

						from transformers.generation import DisjunctiveConstraint



@require_torch
class   __lowercase				( unittest.TestCase	):




			"""simple docstring"""







			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									# For consistency across different places the DisjunctiveConstraint is called,
									# dc.token_ids is a list of integers. It is also initialized only by integers.

									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       [[1, 2, 4], [1, 2, 3, 4]]
									SCREAMING_SNAKE_CASE_: Any  		=       DisjunctiveConstraint(lowerCAmelCase__)
									self.assertTrue(isinstance(dc.token_ids   ,						lowerCAmelCase__))

									with self.assertRaises(lowerCAmelCase__):
															DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]))

									with self.assertRaises(lowerCAmelCase__):
															DisjunctiveConstraint([torch.LongTensor([1, 2, 4]), torch.LongTensor([1, 2, 3, 4, 5])])



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									# We can't have constraints that are complete subsets of another. This leads to a preverse
									# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
									# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
									# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
									# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       [[1, 2], [1, 2, 3, 4]]

									with self.assertRaises(lowerCAmelCase__):
															DisjunctiveConstraint(lowerCAmelCase__)  # fails here



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: List[str]  		=       [[1, 2, 3], [1, 2, 4]]

									SCREAMING_SNAKE_CASE_: Tuple  		=       DisjunctiveConstraint(lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: int  		=       dc.update(1)
									SCREAMING_SNAKE_CASE_: Dict  		=       stepped is True and completed is False and reset is False
									self.assertTrue(lowerCAmelCase__)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: str  		=       dc.update(2)
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       stepped is True and completed is False and reset is False
									self.assertTrue(lowerCAmelCase__)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Tuple  		=       dc.update(3)
									SCREAMING_SNAKE_CASE_: Tuple  		=       stepped is True and completed is True and reset is False
									self.assertTrue(lowerCAmelCase__)
									self.assertTrue(dc.completed)  # Completed!
									self.assertTrue(dc.current_seq == [1, 2, 3])




			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

									SCREAMING_SNAKE_CASE_: List[Any]  		=       DisjunctiveConstraint(lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Optional[Any]  		=       dc.update(1)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Dict  		=       dc.update(2)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Tuple  		=       dc.update(4)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2, 4])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Optional[Any]  		=       dc.update(5)
									self.assertTrue(dc.completed)  # Completed!
									self.assertTrue(dc.current_seq == [1, 2, 4, 5])

									dc.reset()

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: List[Any]  		=       dc.update(1)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.remaining() == 3)
									self.assertTrue(dc.current_seq == [1])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Tuple  		=       dc.update(2)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.remaining() == 2)
									self.assertTrue(dc.current_seq == [1, 2])

									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       dc.update(5)
									self.assertTrue(dc.completed)  # Completed!
									self.assertTrue(dc.remaining() == 0)
									self.assertTrue(dc.current_seq == [1, 2, 5])






