Set Mutations

  • + 1 comment
    A = int(input())
    set_A = set(map(int,input().split()))
    B = int(input())
    
    for _ in range(B):
    
        command = list(map(str, input().split()))
        set_B = set(map(int,input().split()))
        
        if command[0].lower() == 'intersection_update':
            set_A &= set_B
        elif command[0].lower() == 'update':
            set_A |= set_B
        elif command[0].lower() == 'symmetric_difference_update':
            set_A ^= set_B
        elif command[0].lower() == 'difference_update':
            set_A -= set_B
            
    
    print(sum(set_A))