We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def happiness_1(n,m,my_array,my_a,my_b):
happiness=0
for num in my_array:
if num in my_a:
happiness += 1
elif num in my_b:
happiness -= 1
return happiness
if name == 'main':
sizeArray, sizesAB = input().split()
my_array = input().split()
setA= set(input().split())
setB = set(input().split())
print(len([char for char in my_array if char in setA])-len([char for char in my_array if char in setB]))
Simple Python Solution (using counter):
n,m =map(int,input().split()) my_array =map(int,input().split()) my_a=set(map(int,input().split())) my_b=set(map(int,input().split()))
def happiness_1(n,m,my_array,my_a,my_b): happiness=0 for num in my_array: if num in my_a: happiness += 1 elif num in my_b: happiness -= 1 return happiness
print(happiness_1(n,m,my_array,my_a,my_b))
Enter your code here. Read input from STDIN. Print output to STDOUT
Read a single line of input for n and m
nm = input() # Example input: "3 2"
Split the input line into parts and convert each to an integer
n,m = map(int, nm.split())
array = list(map(int, input().split()))
2sets: A: set, B:set each containing m integers
A = set(map(int, input().split())) B = set(map(int, input().split()))
happiness = 0
for i in array: if i in A: happiness+=1 elif i in B: happiness -=1 else: happiness +=0 print(happiness)
if name == 'main': sizeArray, sizesAB = input().split() my_array = input().split() setA= set(input().split()) setB = set(input().split()) print(len([char for char in my_array if char in setA])-len([char for char in my_array if char in setB]))