def add_elements(arr, k):
    """
    Given a non-empty array of integers arr and an integer k, return
    the sum of the first k element that has at most two digits.

    Example:

        Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4
        Output: 24 # sum of 21 + 3

    Constraints:
        1. 1 <= len(arr) <= 100
        2. 1 <= k <= len(arr)
    """

    return sum(elem for elem in arr[k] if len(str(elem)) <= 2)


def check(candidate):

    # Check some simple cases
    assert candidate([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) == -4
    assert candidate([111, 121, 3, 4000, 5, 6], 2) == 0
    assert candidate([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) == 125
    assert (
        candidate([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) == 24
    ), "This prints if this assert fails 1 (good for debugging!)"

    # Check some edge cases that are easy to work out by hand.
    assert (
        candidate([1], 1) == 1
    ), "This prints if this assert fails 2 (also good for debugging!)"


if __name__ == "__main__":
    check(add_elements)
