**Physical Address**

304 North Cardinal St.

Dorchester Center, MA 02124

There is an array of n integers. There are also 2 disjoint sets, A and B, each containing m integers. You like all the integers in set A and dislike all the integers in set B. Your initial happiness is 0. For each i integer in the array, if i (- A , you add 1 to your happiness. If i (- B, you add -1 to your happiness. Otherwise, your happiness does not change. Output your final happiness at the end.

**Note:** Since A and B are sets, they have no repeated elements. However, the array might contain duplicate elements.

- 1 <= n <= 10^5
- 1 <= m <= 10^5
- 1 <= any integer in the input <= 10^9

The first line contains integers n and m separated by a space.

The second line contains n integers, the elements of the array.

The third and fourth lines contain m integers, A and B, respectively.

Output a single integer, your total happiness.

**3** **2**
**1** **5** **3**
**3** **1**
**5** **7**

**1**

You gain 1 unit of happiness for elements 3 and 1 in set A. You lose 1 unit for 5 in set B. The element 7 in set B does not exist in the array so it is not included in the calculation.

Hence, the total happiness is 2 – 1 = 1.

```
import sys
def main():
h = Happiness()
input = get_input()
m = input["m"]
n = input["n"]
n_array = input["n_array"]
A_set = input["A_set"]
B_set = input["B_set"]
for num in n_array:
if num in A_set:
h.incr()
elif num in B_set:
h.decr()
print h.val
class Happiness():
def __init__(self):
self.val = 0
def incr(self):
self.val += 1
def decr(self):
self.val -= 1
def get_input():
input_m_n = sys.stdin.readline().strip()
input_n_array = sys.stdin.readline().strip()
input_A_set = sys.stdin.readline().strip()
input_B_set = sys.stdin.readline().strip()
m, n = input_m_n.split(' ')
n_array = input_n_array.split(' ')
A_set = set(input_A_set.split(' '))
B_set = set(input_B_set.split(' '))
result = {"m":m, "n":n, "n_array": n_array, "A_set": A_set, "B_set": B_set}
return result
if __name__ == '__main__':
main()
```

```
# Enter your code here. Read input from STDIN. Print output to STDOUT
n, m = input().split()
sc_ar = input().split()
A = set(input().split())
B = set(input().split())
print(sum([(i in A) - (i in B) for i in sc_ar]))
```

```
# Enter your code here. Read input from STDIN. Print output to STDOUT
n, m = raw_input().split()
arr = raw_input().split()
A = set(raw_input().split())
B = set(raw_input().split())
print sum([(i in A) - (i in B) for i in arr])
```

```
# Enter your code here. Read input from STDIN. Print output to STDOUT
numlst =input().split()
l = input().split()
A = set(input().split())
B = set(input().split())
print(len(list(filter(lambda x: x in A, l))) - len(list(filter(lambda x: x in B, l))))
```

In our experience, we suggest you solve this No Idea Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

No Idea Hacker Rank Solution problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get No Idea Hacker Rank Solution Hacker Rank Solution

I hope this No Idea Hacker Rank Solution Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning Programming in a business context; there are no prerequisites.

Keep Learning!

**More Hacker Rank Problem & Solutions >>**

Staircase Hacker Rank Solution

A Very Big Sum Hacker Rank Solution

Diagonal Difference Hacker Rank Solution