#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, b, c, d, i;
  cin >> n;
  a = 0;
  
  b = 1000;
  d = 10000;
  i = 4;
  while(n > b) {
    b *=10;
    if(n < b) {
      for (int j = 0; j < i - 3; j++) { //切り取る桁の場合分け
        c = n;
        for (int k = 0; k < i - 3 - j; k++) { //切り取る場所の場合分け n桁ならd=10^n+1
          if (c%d%2019 == 0)
            a++;
          c /= 10;
        }
        d *=10;
      }
    }
    i++;
  }

  cout << a << endl;
}

