import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto S = readln.chomp;
    auto T = S.to!(dchar[]);
    T.reverse();
    S = T.to!string;
    auto N = S.length.to!int;

    auto A = new long[](2020);
    A[0] = 1;
    int tmp = 0;
    auto tmps = new int[](N+1);

    auto ten = 1;

    foreach (i, s; S) {
        tmp += ten * (s - '0');
        tmp %= 2019;
        ten = ten * 10 % 2019;
        A[tmp] += 1;
        tmps[i+1] = tmp;
    }


    long ans = 0;

    foreach_reverse (i, s; S) {
        A[tmp] -= 1;
        ans += A[tmp];
        tmp = tmps[i];
    }

    ans.writeln;
}

