def METHOD_NAME(full_data: Tensor, full_targets: Tensor, num_samples: int, digits: Sequence):
    classes = {d: 0 for d in digits}
    indexes = []
    for idx, target in enumerate(full_targets):
        label = target.item()
        if classes.get(label, float("inf")) >= num_samples:
            continue
        indexes.append(idx)
        classes[label] += 1
        if all(classes[k] >= num_samples for k in classes):
            break
    data = full_data[indexes]
    targets = full_targets[indexes]
    return data, targets