import std;

int calc(string s) {
    int[int] d = [0: 1];
    int x = 0;
    int p = 1;
    foreach_reverse (c; s) {
        x = (x + (c - '0') * p) % 2019;
        p = 10 * p % 2019;
        d[x]++;
    }
    return d.values.map!(e => e * (e - 1) / 2).sum;
}

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;
