Problem p03104 (python)

Fixed submission:
a,b = map(lambda x:
          int(format(int(x),'b')),input().split())
a -= 1
A = str(a)
la = len(A)
ga = [0]*la
if a%4 == 1 or a%4 == 2:
  ga[-1] = 1
for ai in range(0,la-1):
  if A[ai] == '1' and A[-1] == '0':
    ga[ai] = 1
aa = 0
for ai in range(la):
  aa *= 2
  aa += ga[ai]
B = str(b)
lb = len(B)
gb = [0]*lb
if b%4 == 1 or b%4 == 2:
  gb[-1] = 1
for bi in range(0,lb-1):
  if B[bi] == '1' and B[-1] == '0':
    gb[bi] = 1
bb = 0
for bi in range(lb):
  bb *= 2
  bb += gb[bi]
if a < 0:
  print(bb)
else:
  print(aa^bb)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
a = format(A-1,'b')
b = format(B,'b')
if int(a) < 0:
  a = 0
le = len(b)
part = []
whole = []
for i in range(1,le+1):
  whole += [int(b[i-1])]
  df = le - len(a)
  if i <= df:
    part += [0]
  else:
    part += [int(a[i-1-df])]
p = 0
for i in range(le):
  p *= 10
  if i == le-1:
    if int(a)%4 == 1 or int(a)%4 == 2:
      p += 1
  elif part[i] == 0:
    pass
  else:
    p += 1- int(a)%2
w = 0
for i in range(le):
  w *= 10
  if i == le-1:
    if int(b)%4 == 1 or int(b)%4 == 2:
      w += 1
  elif whole[i] == 0:
    pass
  else:
    w += 1- int(b)%2
print(int(str(w),2)^int(str(p),2))

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
a = format(A-1,'b')
b = format(B,'b')
if a < 0:
  a = 0
le = len(b)
part = []
whole = []
for i in range(1,le+1):
  whole += [int(b[i-1])]
  df = le - len(a)
  if i <= df:
    part += [0]
  else:
    part += [int(a[i-1-df])]
p = 0
for i in range(le):
  p *= 10
  if i == le-1:
    if int(a)%4 == 1 or int(a)%4 == 2:
      p += 1
  elif part[i] == 0:
    pass
  else:
    p += 1- int(a)%2
w = 0
for i in range(le):
  w *= 10
  if i == le-1:
    if int(b)%4 == 1 or int(b)%4 == 2:
      w += 1
  elif whole[i] == 0:
    pass
  else:
    w += 1- int(b)%2
print(int(str(w),2)^int(str(p),2))

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
a = format(A-1,'b')
b = format(B,'b')
le = len(b)
part = []
whole = []
for i in range(1,le+1):
  whole += [int(b[i-1])]
  df = le - len(a)
  if i <= df:
    part += [0]
  else:
    part += [int(a[i-1-df])]
p = 0
for i in range(le):
  p *= 10
  if i == le-1:
    if int(a)%4 == 1 or int(a)%4 == 2:
      p += 1
  elif part[i] == 0:
    pass
  else:
    p += 1- int(a)%2
w = 0
for i in range(le):
  w *= 10
  if i == le-1:
    if int(b)%4 == 1 or int(b)%4 == 2:
      w += 1
  elif whole[i] == 0:
    pass
  else:
    w += 1- int(b)%2
print(int(str(w),2)^int(str(p),2))

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
a = format(A-1,'b')
b = format(B,'b')
le = len(b)
part = []
whole = []
for i in range(1,le+1):
  whole += [int(b[i-1])]
  df = le - len(a)
  if i <= df:
    part += [0]
  else:
    part += [int(a[i-1-df])]
p = 0
for i in range(le):
  p *= 10
  if i == le-1:
    if int(a)%4 == 1 or int(a)%4 == 2:
      p += 1
  elif part[i] == 0:
    pass
  else:
    p += 1- int(a)%2
w = 0
for i in range(le):
  w *= 10
  if i == le-1:
    if int(b)%4 == 1 or int(b)%4 == 2:
      w += 1
  elif whole[i] == 0:
    pass
  else:
    w += 1- int(b)%2
print(int(str(w),2)^int(str(p),2))

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
a = format(A-1,'b')
b = format(B,'b')
le = len(b)
part = []
whole = []
for i in range(1,le+1):
  whole += [int(b[i-1])]
  df = le - len(a)
  if i <= df:
    part += [0]
  else:
    part += [int(a[i-1-df])]
p = 0
for i in range(le):
  p *= 10
  if i == le-1:
    if int(a)%4 == 1 or int(a)%4 == 2:
      p += 1
  elif part[i] == 0:
    pass
  else:
    p += 1- int(a)%2
w = 0
for i in range(le):
  w *= 10
  if i == le-1:
    if int(b)%4 == 1 or int(b)%4 == 2:
      p += 1
  elif whole[i] == 0:
    pass
  else:
    w += 1- int(b)%2
print(int(str(p),2)^int(str(w),2))