#include <bits/stdc++.h>

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    lld rmd[2019];
    lld tmp[2019];

    cin >> s;

    lld ans = 0;
    for (char &c : s) {
        c -= '0';
        for (int i = 0; i < 2019; i++) {
            
            if ((i * 10 + c) % 2019 == 0) {
                ans += rmd[i];
            }
        }

        for (int i = 0; i < 2019; i++) {
            tmp[(i * 10 + c) % 2019] = rmd[i];
        }

        for (int i = 0; i < 2019; i++) {
            rmd[i] = tmp[i];
        }
        rmd[c]++;

    }

    cout << ans << '\n';

    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17