'''
cartesian product of two sets and binary relations
'''
def binaryof(a, arr):
i = 0
while(a):
arr[i]= a%2
a //= 2
i += 1
print("enter the elements in set A: ",end="")
A = {int(x) for x in input("").split()}
print("enter the elements in set B: ",end="")
B = {int(x) for x in input("").split()}
C={}
a=[]
C= set((i,j) for i in A for j in B)
print("Total no of Elements in A x B is ",len(C) ," Those are:",C)
binary = [0 for i in range(len(C))]
Q=list(C)
subset=[]
for i in range(2**len(Q)):
set = []
binaryof(i,binary)
for j in range(len(binary)):
if(binary[j] == 1):
set.append(Q[j])
subset.append(set)
print("Total No of Binary relations are:",len(subset),"\n Those are:")
for i in range(len(subset)):
print(subset[i])