def main():

    s = eval(input())

    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018

    rem[0] = 1  # why? can't understand.



    temp = 0

    digit = 1

    for i, c in enumerate(s[::-1]):

        # No time to pow.

        temp += int(c) * digit

        rem[temp % 2019] += 1

        digit *= 10

        digit %= 2019



    return sum(c * (c - 1) // 2 for c in rem)





if __name__ == '__main__':

    print((main()))

def main():

    s = eval(input())

    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018

    rem[0] = 1  # why? can't understand.



    temp = 0

    digit = 1

    for c in s[::-1]:

        # No time to pow.

        temp += int(c) * digit

        rem[temp % 2019] += 1

        digit *= 10

        digit %= 2019



    return sum(c * (c - 1) // 2 for c in rem)





if __name__ == '__main__':

    print((main()))

def main():
    s = eval(input())
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.
    temp = 0
    digit = 1
    for i, c in enumerate(s[::-1]):
        # No time to pow.
        temp += int(c) * digit
        rem[temp % 2019] += 1
        digit *= 10
        digit %= 2019
    return sum(c * (c - 1) // 2 for c in rem)


if __name__ == "__main__":
    print((main()))

def main():
    s = eval(input())
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.
    temp = 0
    digit = 1
    for c in s[::-1]:
        # No time to pow.
        temp += int(c) * digit
        rem[temp % 2019] += 1
        digit *= 10
        digit %= 2019
    return sum(c * (c - 1) // 2 for c in rem)


if __name__ == "__main__":
    print((main()))

-    for i, c in enumerate(s[::-1]): +    for c in s[::-1]: