Set Mutations

  • + 0 comments
    a=int(input())
    b=set(map(int, input().split()))
    c=int(input())
    for _ in range(c):
        d,_=input().split()
        other_set = set(map(int, input().split()))
        if d=="intersection_update":
            b.intersection_update(other_set)
        elif d=="update":
            b.update(other_set)
        elif d=="symmetric_difference_update":
            b.symmetric_difference_update(other_set)
        elif d=="difference_update":
            b.difference_update(other_set)
    print(sum(b))