Problem p03104 (python)

Fixed submission:
a,b=map(int,input().split())

def xor(p):
  if p%4 == 0:
    return p
  elif p%4 == 1:
    return 1
  elif p%4 == 2:
    return p+1
  elif p%4 == 3:
    return 0

if a==0:
  print(xor(b))
elif a == b:
  print(a)
else:
  s=max(xor(b),xor(a-1))
  t=min(xor(a-1),xor(b))
  data=[]
  while s>0:
    data.append(s%2)
    s=s//2
  for i in range(len(data)):
    if (data[i] == t%2):
      data[i] = 0
    else:
      data[i] = 1
    t = t//2
  sum=0
  for i in range(len(data)):
    sum+= data[i]*(2**i)
  print(sum)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())

def xor(p):
  if p%4 == 0:
    return p
  elif p%4 == 1:
    return 1
  elif p%4 == 2:
    return p+1:
  elif p%4 == 3:
    return 0

if a==0:
  print(xor(b))
elif a == b:
  print(a)
else:
  s=xor(b)
  t=xor(a-1)
  data=[]
  while s>0:
    data.append(s%2)
    s=s//2
  for i in range(len(data)):
    if (data[i] == t%2):
      data[i] = 0
    else:
      data[i] = 1
    t = t//2
  sum=0
  for i in range(len(data)):
    sum+= data[i]*(2**i)
  print(sum)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())

def xor(p):
  if p%4 == 0:
    return p
  elif p%4 == 1:
    return 1
  elif p%4 == 2:
    return p+1:
  elif p%4 == 3:
    return 0

if a==0:
  print(xor(b))
elif a == b:
  print(a)
else:
  s=xor(b)
  t=xor(a-1)
  data=[]
  while b>0:
    data.append(b%2)
    b=b//2
  for i in range(len(data)):
    if (data[i] == a%2):
      data[i] = 0
    else:
      data[i] = 1
    a = a//2
  sum=0
  for i in range(len(data)):
    sum+= data[i]*(2**i)
  print(sum)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a%2 == b%2:
  if ((b-a)%2)%2 == 0:
    print(b)
  else:
    if b%2 == 1:
      print(b-1)
    else:
      print(b+1)
else:
  c=b
  bits=[]
  perfect=False
  while b>0:
    bits.append(b%2)
    b= b//2
  if bits.count(1)==1 and bits[-1]==1:
    perfect=True
    b=c-1
    bits=[]
  while b>0:
    bits.append(b%2)
    b= b//2
  for i in range(len(bits)):
    if (bits[i]==1 and a%2==1) or (bits[i]==0 and a%2==0):
      bits[i]=0
    else:
      bits[i]=1
    a= a//2
    ans=0
  for i in range(len(bits)):
    ans+= bits[i]*(2**i)
  if perfect:
    print(ans+c)
  else:
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a%2 == b%2:
  if ((b-a)%2)%2 == 0:
    print(b)
  else:
    if b%2 == 1:
      print(b-1)
    else:
      print(b+1)
else:
  c=b
  bits=[]
  perfect=False
  while b>0:
  bits.append(b%2)
  b= b//2
  if bits.count(1)==1 and bits[-1]==1:
    perfect=True
    b=c-1
    bits=[]
  while b>0:
    bits.append(b%2)
    b= b//2
  for i in range(len(bits)):
    if (bits[i]==1 and a%2==1) or (bits[i]==0 and a%2==0):
      bits[i]=0
    else:
      bits[i]=1
    a= a//2
  ans=0
  for i in range(len(bits)):
    ans+= bits[i]*(2**i)
  if perfect:
    print(ans+c)
  else:
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
bits=[]
perfect=False
while b>0:
  bits.append(b%2)
  b= b//2
if 1==i for i in bits:
  perfect=True
for i in range(len(bits)):
  if (bits[i]==1 and a//2==1) or (bits[i]==0 and a//2==0):
    bits[i]=0
  else:
    bits[i]=1
ans=0
for i in range(len(bits)):
  ans+= bits[i]*(2**i)
if perfect:
  print(ans+1)
else:
  print(ans)