class Bag:
    def __init__(self):
        self.__elements = []
    def add(self, e):
        self.__elements.append(e)
    def remove(self, e):
        if e in self.__elements:
            self.__elements.remove(e)
            return True
        return False
    def search(self, e):
        return e in self.__elements
    def size(self):
        return len(self.__elements)
    def nrOccurrences(self, e):
        return self.__elements.count(e)
    def destroy(self):
        del(self)
    def iterator(self):
        return BagIterator(self.__elements)


class BagIterator:
    def __init__(self, elements):
        self.__elements = elements
        self.__current = 0
    def first(self):
        self.__current = 0
    def valid(self):
        return self.__current < len(self.__elements)
    def next(self):
        if self.valid():
            self.__current += 1
    def getCurrent(self):
        if self.valid():
            return self.__elements[self.__current]
        else:
            raise ValueError("Invalid iterator position.")
    