



A_		:     List[Any]        =     [
    (10_00, '''M'''),
    (9_00, '''CM'''),
    (5_00, '''D'''),
    (4_00, '''CD'''),
    (1_00, '''C'''),
    (90, '''XC'''),
    (50, '''L'''),
    (40, '''XL'''),
    (10, '''X'''),
    (9, '''IX'''),
    (5, '''V'''),
    (4, '''IV'''),
    (1, '''I'''),
]


def 	UpperCAmelCase__      (      UpperCAmelCase__ :str					):






 '''simple docstring'''

 a						=		{"I": 1, "V": 5, "X": 10, "L": 50, "C": 1_00, "D": 5_00, "M": 10_00}
 a						=		0
 a						=		0
 while place < len(UpperCAmelCase__					):
  if (place + 1 < len(UpperCAmelCase__					)) and (vals[roman[place]] < vals[roman[place + 1]]):
   total += vals[roman[place + 1]] - vals[roman[place]]
   place += 2
  else:
   total += vals[roman[place]]
   place += 1
 return total


def 	UpperCAmelCase__      (      UpperCAmelCase__ :int					):






 '''simple docstring'''

 a						=		[]
 for arabic, roman in ROMAN:
  ((a)		,  (a))						=		divmod(UpperCAmelCase__ ,					UpperCAmelCase__					)
  result.append(roman * factor					)
  if number == 0:
   break
 return "".join(UpperCAmelCase__					)


if __name__ == "__main__":
     import doctest

     doctest.testmod()






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	):

   def 		A							(      self			:       Union[str, Any]							)       ->				int:


    """simple docstring"""






    a						=		[[1, 2, 4], [1, 2, 3, 4]]
    a						=		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 		A							(      self			:       Tuple							)       ->				Dict:


    """simple docstring"""






    a						=		[[1, 2], [1, 2, 3, 4]]

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

   def 		A							(      self			:       int							)       ->				Any:


    """simple docstring"""






    a						=		[[1, 2, 3], [1, 2, 4]]

    a						=		DisjunctiveConstraint(__lowerCAmelCase							)

    a		,  a		,  a						=		dc.update(1							)
    a						=		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]							)

    a		,  a		,  a						=		dc.update(2							)
    a						=		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]							)

    a		,  a		,  a						=		dc.update(3							)
    a						=		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 		A							(      self			:       List[Any]							)       ->				List[Any]:


    """simple docstring"""






    a						=		[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

    a						=		DisjunctiveConstraint(__lowerCAmelCase							)

    a		,  a		,  a						=		dc.update(1							)
    self.assertTrue(not dc.completed							)
    self.assertTrue(dc.current_seq == [1]							)

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

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

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

    dc.reset()

    a		,  a		,  a						=		dc.update(1							)
    self.assertTrue(not dc.completed							)
    self.assertTrue(dc.remaining() == 3							)
    self.assertTrue(dc.current_seq == [1]							)

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

    a		,  a		,  a						=		dc.update(5							)
    self.assertTrue(dc.completed							)  # Completed!
    self.assertTrue(dc.remaining() == 0							)
    self.assertTrue(dc.current_seq == [1, 2, 5]							)

