def AND (x, y):
if x=='1' and y=='1':
return '1'
return '0'
def OR (x, y):
if x=='0' and y=='0':
return '0'
return '1'
def XOR (x, y):
if x!=y:
return '1'
return '0'
def dec2bin(n):
bin=""
while n>0:
bin=str(n%2)+bin
n=n//2
return bin
def checkio(first, second):
first=dec2bin(first)
second=dec2bin(second)
AND_table=[[0 for j in range(len(second))] for i in range(len(first))]
OR_table=[[0 for j in range(len(second))] for i in range(len(first))]
XOR_table=[[0 for j in range(len(second))] for i in range(len(first))]
for i in range(len(first)):
for j in range(len(second)):
AND_table[i][j]=AND(first[i], second[j])
OR_table[i][j]=OR(first[i], second[j])
XOR_table[i][j]=XOR(first[i], second[j])
sum_AND=[0 for i in range(len(first))]
sum_OR=[0 for i in range(len(first))]
sum_XOR=[0 for i in range(len(first))]
total=0
for i in range(len(first)):
for j in range(len(second)):
sum_AND[i]=sum_AND[i]*2
sum_AND[i]=sum_AND[i]+int(AND_table[i][j])
sum_OR[i]=sum_OR[i]*2
sum_OR[i]=sum_OR[i]+int(OR_table[i][j])
sum_XOR[i]=sum_XOR[i]*2
sum_XOR[i]=sum_XOR[i]+int(XOR_table[i][j])
total=total+sum_AND[i]+sum_OR[i]+sum_XOR[i]
return total
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(4, 6) == 38
assert checkio(2, 7) == 28
assert checkio(7, 2) == 18