import std;

int calc(string s) {
    int[2019] a;
    a[0] = 1;
    int ans = 0;
    int p = 1;
    int now = 0;
    foreach_reverse (c; s) {
        now = (now  + p * (c - '0')) % 2019;
        p = p * 10 % 2019;
        ans += a[now];
        a[now]++;
    }
    return ans;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
