


'''simple docstring'''
from __future__ import annotations

from collections import deque






class        lowerCAmelCase_  :






       def __init__( self			,     _UpperCamelCase   )->      Dict:
            _A				=							[]
            self.adlist.append(
                {'value': '', 'next_states': [], 'fail_state': 0, 'output': []}   )

            for keyword in keywords:
                 self.add_keyword(_UpperCamelCase   )
            self.set_fail_transitions()






       def   UpperCamelCase						( self			,     _UpperCamelCase			,     _UpperCamelCase   )->      int | None:
            for state in self.adlist[current_state]["next_states"]:
                 if char == self.adlist[state]["value"]:
                      return state
            return None






       def   UpperCamelCase						( self			,     _UpperCamelCase   )->      None:
            _A				=							0
            for character in keyword:
                 _A				=							self.find_next_state(_UpperCamelCase			,     _UpperCamelCase   )
                 if next_state is None:
                      self.adlist.append(
                          {
                              'value': character,
                              'next_states': [],
                              'fail_state': 0,
                              'output': [],
                          }   )
                      self.adlist[current_state]["next_states"].append(len(self.adlist   ) - 1   )
                      _A				=							len(self.adlist   ) - 1
                 else:
                      _A				=							next_state
            self.adlist[current_state]["output"].append(_UpperCamelCase   )






       def   UpperCamelCase						( self   )->      None:
            _A				=							deque()
            for node in self.adlist[0]["next_states"]:
                 q.append(_UpperCamelCase   )
                 _A				=							0
            while q:
                 _A				=							q.popleft()
                 for child in self.adlist[r]["next_states"]:
                      q.append(_UpperCamelCase   )
                      _A				=							self.adlist[r]['fail_state']
                      while (
                          self.find_next_state(_UpperCamelCase			,     self.adlist[child]['value']   ) is None
                          and state != 0
                      ):
                           _A				=							self.adlist[state]['fail_state']
                      _A				=							self.find_next_state(
                          _UpperCamelCase			,     self.adlist[child]['value']   )
                      if self.adlist[child]["fail_state"] is None:
                           _A				=							0
                      _A				=							(
                          self.adlist[child]['output']
                          + self.adlist[self.adlist[child]['fail_state']]['output']
                      )






       def   UpperCamelCase						( self			,     _UpperCamelCase   )->      dict[str, list[int]]:
            _A				=							{}  # returns a dict with keywords and list of its occurrences
            _A				=							0
            for i in range(len(_UpperCamelCase   )   ):
                 while (
                     self.find_next_state(_UpperCamelCase			,     string[i]   ) is None
                     and current_state != 0
                 ):
                      _A				=							self.adlist[current_state]['fail_state']
                 _A				=							self.find_next_state(_UpperCamelCase			,     string[i]   )
                 if next_state is None:
                      _A				=							0
                 else:
                      _A				=							next_state
                      for key in self.adlist[current_state]["output"]:
                           if key not in result:
                                _A				=							[]
                           result[key].append(i - len(_UpperCamelCase   ) + 1   )
            return result


if __name__ == "__main__":
    import doctest

    doctest.testmod()









'''simple docstring'''
import math

import qiskit

def 					lowerCamelCase_ ( __UpperCamelCase					:       int = 1							,    __UpperCamelCase					:       int = 1							,    __UpperCamelCase					:       int = 1		)					->	qiskit.result.counts.Counts:







     """simple docstring"""
     if (
         isinstance(__UpperCamelCase							,    __UpperCamelCase		)
         or isinstance(__UpperCamelCase							,    __UpperCamelCase		)
         or isinstance(__UpperCamelCase							,    __UpperCamelCase		)
     ):
          raise TypeError('inputs must be integers.'		)

     if (input_a < 0) or (input_a < 0) or (carry_in < 0):
          raise ValueError('inputs must be positive.'		)

     if (
         (math.floor(__UpperCamelCase		) != input_a)
         or (math.floor(__UpperCamelCase		) != input_a)
         or (math.floor(__UpperCamelCase		) != carry_in)
     ):
          raise ValueError('inputs must be exact integers.'		)

     if (input_a > 2) or (input_a > 2) or (carry_in > 2):
          raise ValueError('inputs must be less or equal to 2.'		)

     # build registers
     _A				=							qiskit.QuantumRegister(4							,    'qr'		)
     _A				=							qiskit.ClassicalRegister(2							,    'cr'		)
     # list the entries
     _A				=							[input_a, input_a, carry_in]

     _A				=							qiskit.QuantumCircuit(__UpperCamelCase							,    __UpperCamelCase		)

     for i in range(0							,    3		):
          if entry[i] == 2:
               quantum_circuit.h(__UpperCamelCase		)  # for hadamard entries
          elif entry[i] == 1:
               quantum_circuit.x(__UpperCamelCase		)  # for 1 entries
          elif entry[i] == 0:
               quantum_circuit.i(__UpperCamelCase		)  # for 0 entries

    # build the circuit
     quantum_circuit.ccx(0							,    1							,    3		)  # ccx = toffoli gate
     quantum_circuit.cx(0							,    1		)
     quantum_circuit.ccx(1							,    2							,    3		)
     quantum_circuit.cx(1							,    2		)
     quantum_circuit.cx(0							,    1		)

     quantum_circuit.measure([2, 3]							,    __UpperCamelCase		)  # measure the last two qbits

     _A				=							qiskit.Aer.get_backend('aer_simulator'		)
     _A				=							qiskit.execute(__UpperCamelCase							,    __UpperCamelCase							,    shots=1_0_0_0		)

     return job.result().get_counts(__UpperCamelCase		)


if __name__ == "__main__":
    print(F'Total sum count for state is: {quantum_full_adder(1, 1, 1)}')





