import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

@safe
long solve (const string s) {
  enum m = 2019;
  auto c = new int[m];
  auto d = new int[m];
  long res;
  foreach (ch; s) {
    c[0] += 1;
    const int k = ch.to!int - 48;
    d[] = 0;
    int v = k;
    foreach (j; 0 .. m) {
      d[v] += c[j];
      v += 10;
      if (v >= m) v -= m;
    }
    swap (c, d);
    res += c[0];
  }
  return res;
}

void main() {
  auto s = readln.stripRight;
  writeln (solve (s));
}

