#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;


int main() {
  string S; cin >> S;
  int L = S.size();
  vector<vector<LL>> dp(L+1, vector<LL>(2020, 0));
  int cnt = 0;
  for (int i = 0; i < 2020; ++i) dp[0][0] = 0;

  for (int i = 1; i <= L; ++i) {
    int x = S[i-1]-'0';
    for (int j = 0; j < 2020; ++j) {
      int y = (j*10+x) % 2019;
      dp[i][y] += dp[i-1][j];
    }
    ++dp[i][x];
    cnt += dp[i][0];
  }
  cout << cnt << endl;
}
