#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

vector<int> num;
int cnt = 0;
bool visited[300000][300000];
int N = 0;

void dfs(int i, int j) {
    if (visited[j][i]==true) return;
    if(i==N+1) {
        return;
    }
    if(j==N+1) {
        return;
    }
    visited[j][i] = true;
    int n = 0;
    for(int k=0; k<j-i; k++) {
        n += num[i+k]*pow(10, k);
    }
    if(n%2019==0 && n!=0) {
        cnt++;
    }
    dfs(i, j+1);
    dfs(i+1, j);
}

int main() {
    string S;
    cin >> S;
    for(auto s: S) {
        num.push_back(s-'0');
    }
    reverse(num.begin(), num.end());
    N = num.size();
    dfs(0, 0);
    print(cnt);

    return 0;
}