# -*- coding: utf-8 -*-





def main():

    # 入力

    st = eval(input())



    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく

    mod_res_dic = {0: [0]}

    tmp_mod_val = 0

    r_st = ''.join(list(reversed(st)))

    cnt = 0

    for i in range(len(r_st)):

        target_st = r_st[i:i+1]

        tmp_mod_val += int(target_st)*pow(10, i, 2019)

        tmp_mod_val %= 2019

        ls = mod_res_dic.setdefault(tmp_mod_val, [])

        ls.append(i-1)

        if len(ls) > 1:

            cnt += len(ls)-1



    print((int(cnt)))





main()

# -*- coding: utf-8 -*-





def main():

    # 入力

    st = eval(input())



    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく

    mod_res_dic = {0: 1}

    tmp_mod_val = 0

    r_st = ''.join(list(reversed(st)))

    cnt = 0

    for i in range(len(r_st)):

        target_st = r_st[i:i+1]

        tmp_mod_val += int(target_st)*pow(10, i, 2019)

        tmp_mod_val %= 2019

        ls = mod_res_dic.setdefault(tmp_mod_val, 0)

        mod_res_dic[tmp_mod_val] = ls+1

        if ls > 0:

            cnt += ls



    print(cnt)





main()

# -*- coding: utf-8 -*-
def main():
    # 入力
    st = eval(input())
    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく
    mod_res_dic = {0: [0]}
    tmp_mod_val = 0
    r_st = "".join(list(reversed(st)))
    cnt = 0
    for i in range(len(r_st)):
        target_st = r_st[i : i + 1]
        tmp_mod_val += int(target_st) * pow(10, i, 2019)
        tmp_mod_val %= 2019
        ls = mod_res_dic.setdefault(tmp_mod_val, [])
        ls.append(i - 1)
        if len(ls) > 1:
            cnt += len(ls) - 1
    print((int(cnt)))


main()

# -*- coding: utf-8 -*-
def main():
    # 入力
    st = eval(input())
    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく
    mod_res_dic = {0: 1}
    tmp_mod_val = 0
    r_st = "".join(list(reversed(st)))
    cnt = 0
    for i in range(len(r_st)):
        target_st = r_st[i : i + 1]
        tmp_mod_val += int(target_st) * pow(10, i, 2019)
        tmp_mod_val %= 2019
        ls = mod_res_dic.setdefault(tmp_mod_val, 0)
        mod_res_dic[tmp_mod_val] = ls + 1
        if ls > 0:
            cnt += ls
    print(cnt)


main()

-    mod_res_dic = {0: [0]} +    mod_res_dic = {0: 1} -        ls = mod_res_dic.setdefault(tmp_mod_val, []) -        ls.append(i - 1) -        if len(ls) > 1: -            cnt += len(ls) - 1 -    print((int(cnt))) +        ls = mod_res_dic.setdefault(tmp_mod_val, 0) +        mod_res_dic[tmp_mod_val] = ls + 1 +        if ls > 0: +            cnt += ls +    print(cnt)