#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
 
#define REP(i, n) for(LL i = 0; i < (LL)(n); i++)
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const LL IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 2019;
 
LL power(LL x, LL y) {
    LL res = 1;
    for(;0 < y;) {
        if(y%2 == 0) {
            x *= x;
            x %= MOD;
            y /= 2;
        }else{
            res *= x;
            res %= MOD;
            y--;
        }
    }
    return res;
}
 
int main() {
    string s;
    cin >> s;
    reverse(ALL(s));
    LL N;
    N = s.size();
    vector<LL> v(N, 0);
    vector<LL> c(MOD, 0);
    // c[0] = 1;
    v[0] = s[0] - '0';
    FOR(i, 1, N) {
        LL p = s[i] - '0';
        v[i] = power(10, i)*p + v[i - 1];
        v[i] %= MOD;
        c[v[i]]++;
    }
    LL res = 0;
    res += c[0];
    REP(i, MOD) {
        res += c[i]*(c[i] - 1)/2;
    }
    cout << res << endl;
    return 0;
}