No Idea!

  • + 0 comments

    Here is a simple Python 3 solution:

    def read_line():
        """Read a line of integers from STDIN."""
        return map(int, input().split())
    
    
    input()
    array = read_line()
    a, b = {*read_line()}, {*read_line()}
    print(sum(1 if i in a else -1 if i in b else 0 for i in array))
    

    Here is a more verbose Python 3 solution using Counter:

    from collections import Counter
    
    input()
    
    
    def read_input(sequence):
        """Read a line of integers from STDIN."""
        return sequence(map(int, input().split()))
    
    
    def create_happiness_calculator(scores):
        """Create a happiness calculator for the given scores."""
    
        def _happiness_calculator(subset):
            """Calculate the happiness of the given subset."""
            return sum(scores[key] for key in scores.keys() & subset)
    
        return _happiness_calculator
    
    
    calculate_happiness = create_happiness_calculator(read_input(Counter))
    print(calculate_happiness(read_input(set)) - calculate_happiness(read_input(set)))
    

    Here is a code-golfed Python 3 solution (107 characters):

    input();f=lambda:map(int,input().split());n=f();a,b={*f()},{*f()};print(sum([i in a,-1][i in b]for i in n))