#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;

int main(){
  string s; cin >> s;
  int size = s.size();
  //cout << size << endl;
  vector<int> amari(2019,0);
  amari[0]++;
  int ten = 1;
  int ans = 0;
  for(int i = size - 1; i >= 0; i--){
    int tmp = ( tmp + (s[i] - '0') * ten ) % 2019;
    ans += amari[tmp]++;
    ten = ( ten * 10 ) % 2019;
  }

  cout << ans << endl;
}

