output_description: Print the smallest number of operations required to make strings A and B
  equal, or -1 if the goal is unreachable.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A
      B
attempt: from collections import defaultdict, deque, Counter
  from heapq import heappush, heappop, heapify
  import math
  import bisect
  import random
  from itertools import permutations, accumulate, combinations, product
  import sys
  import string
  from bisect import bisect_left, bisect_right
  from math import factorial, ceil, floor
  from operator import mul
  from functools import reduce
  
  
  sys.setrecursionlimit(2147483647)
  INF = 10**13
  
  
  def LI():
      return list(map(int, sys.stdin.readline().split()))
  
  
  def I():
      return int(sys.stdin.readline())
  
  
  def LS():
      return sys.stdin.readline().rstrip().split()
  
  
  def S():
      return sys.stdin.readline().rstrip()
  
  
  def IR(n):
      return [I() for i in range(n)]
  
  
  def LIR(n):
      return [LI() for i in range(n)]
  
  
  def SR(n):
      return [S() for i in range(n)]
  
  
  def LSR(n):
      return [LS() for i in range(n)]
  
  
  def SRL(n):
      return [list(S()) for i in range(n)]
  
  
  def MSRL(n):
      return [[int(j) for j in list(S())] for i in range(n)]
  
  
  mod = 10**9 + 7
  
  
  A = S()
  B = S()
  n = len(B)
  A *= 2
  B *= 2
  l = [0] * n
  r = [0] * n
  for i in range(n):
      if A[i] != B[i]:
          for j in range(n):
              if B[(i + j) % n] == "1":
                  r[i] = j
                  break
          for k in range(n):
              if B[(i - k) % n] == "1":
                  l[i] = k
                  break
  
  D = [0] * n
  for m in range(n):
      ret = 0
      ss = []
      for h in range(n):
          if D[h]:
              continue
          if B[(m + h) % n]:
              D[h] = 1
          else:
              r[h] -= 1
              ss += l[h]
              ss += r[h]
      ss.sort()
  
      ss *= 2
  
  
  print(l, r)
  
problem_description: Statement
  
  You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same
  length consisting of 0 and 1.
  
  You can transform A using the following operations in any order and as many
  times as you want:
  
    * Shift A by one character to the left (i.e., if A = A_1 A_2 ... A_n, replace A with A_2 A_3 ... A_n A_1).
    * Shift A by one character to the right (i.e., if A = A_1 A_2 ... A_n, replace A with A_n A_1 A_2 ... A_{n-1}).
    * Choose any i such that B_i = 1. Flip A_i (i.e., set A_i = 1 - A_i).
  
  You goal is to make strings A and B equal.
  
  Print the smallest number of operations required to achieve this, or -1 if the
  goal is unreachable.
samples: [{"input": "1010\n    1100", "output": "3\n    \n\nHere is one fastest way to achieve the goal:\n\n  * Flip A_1: A = 0010\n  * Shift A to the left: A = 0100\n  * Flip A_1 again: A = 1100\n\n* * *"}, {"input": "1\n    0", "output": "-1\n    \n\nThere is no way to flip the only bit in A.\n\n* * *"}, {"input": "11010\n    10001", "output": "4\n    \n\nHere is one fastest way to achieve the goal:\n\n  * Shift A to the right: A = 01101\n  * Flip A_5: A = 01100\n  * Shift A to the left: A = 11000\n  * Shift A to the left again: A = 10001\n\n* * *"}, {"input": "0100100\n    1111111", "output": "5\n    \n\nFlip A_1, A_3, A_4, A_6 and A_7 in any order."}]