def allocate_examples(max_examples, subtasks):
    """Calculates the number of examples each subtask should evaluate.

    Implements this requirement by BIG-bench organizers:
    https://github.com/google/BIG-bench/pull/288#issuecomment-844333336

    For example, we're allowed to evaluate only 7 examples, but we have 4 subtasks: "A", "B", "C", "D".
    We could allocate the number of allowed examples as follows: {"A":2, "B":2, "C":2, "D":1}

    If max_examples is lower than the number of subtasks, some subtasks will get 0. As the result, such subtasks
    will not be evaluated.

    Args:
        max_examples: Int. How many examples total should be evaluated in this task
        subtasks: List of strings. Each string is the name of a subtask
    Returns:
        Dict. Each key is a subtask name, the value is the number of examples that the subtask should evaluate
    """
    if isinstance(max_examples, int):
        examples_per_subtask = int(max_examples / len(subtasks))
        examples_nums = {k: examples_per_subtask for k in subtasks}
        rest = max_examples % len(subtasks)
        for key, value in examples_nums.items():
            if rest > 0:
                examples_nums[key] += 1
                rest -= 1
            else:
                break
    else:
        examples_nums = {k: None for k in subtasks}
    return examples_nums