def solve(_n, arr):
    """

    Given a list of list of "passports"
    separated by newlines, count
    the number of valid tokens
    where a token is said to be valid
    if and only if the keys in the tokens
    are either equal to a given set of keys
    or is missing a given key.

    :return: The answer required.
    """
    fields = {"byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid", "cid"}

    def valid(keys):
        """
        Given a list of keys
        determine if the list
        contains the same keys
        as fields or if it is missing
        at most one key "cid".

        :return: True if it is the same
        as fields or if it is missing the
        "cid" key; False otherwise.
        """
        return fields == set(keys) or fields == set(keys) | {"cid"}

    _i = 0
    count = 0

    tokens = []

    while _i < _n:
        if arr[_i] == "":
            if valid(tokens):
                count += 1
            tokens = []
        else:
            ln = arr[_i].split(" ")
            for pair in ln:
                _k, _v = pair.split(":")
                tokens.append(_k)
        _i += 1

    if valid(tokens):
        count += 1

    return count