from qiskit import *

circuit = QuantumCircuit(3,3)

# draw ckt
%matplotlib inline
circuit.draw(output='mpl')

# teleport from q0 to q2 (applying x gate)
circuit.x(0)
circuit.barrier()
circuit.draw()

circuit.h(1)
circuit.cx(1,2)

circuit.draw()

circuit.cx(0,1)
circuit.h(0)
circuit.draw()

circuit.barrier()
circuit.measure([0,1],[0,1])
circuit.draw()

circuit.barrier()
circuit.cx(1,2)
circuit.cz(0,2)
circuit.draw()

circuit.draw(output='mpl')

circuit.measure(2,2)
simulator = Aer.get_backend('qasm_simulator')
result = execute(circuit, backend=simulator, shots = 1024).result()
counts = result.get_counts()
from qiskit.tools.visualization import plot_histogram
plot_histogram(counts)

circuit.draw()

print(counts)