#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<long long>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define couta(x) for(auto iter : x) p(iter)
#define yes(x) x ? cout << "Yes" << endl : cout << "No" << endl;
using namespace std;
typedef long long lint;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<vector<int> > VVI;
typedef vector<vector<long long> > VVLL;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
using UnweightedGraph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
const long long INF = 2000000000ll;
const long double PI = acosl(-1);
const long double EPS = 1e-9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MOD = 2019;


long long power(long long a, long long b) {return b?power(a*a,b/2)*(b%2?a:1):1;}
long long perm(long long N, long long K){
    long long x=1;
    for(long long i=1;i<=K;i++)
    {
        x=x*(N-i+1);
    }
    return x;
}
long long factorial(long long N) {return perm(N,N);}
long long comb(long long N,long long K) {return factorial(N)/factorial(K)/factorial(N-K);}
long long hcomb(long long N, long long K) {return comb(N+K-1, N-1);}

int dtoi(double d) {return round(d);}

bool isprime(int n) {
    if (n < 2) return false;
    for (int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

long long mystoll(string s){
    long long ans = 0;
    for (int i = (int) s.length()-1; i >= 0; i--){
        ans += (s[i]-'0') * power(10,s.length()-1-i);
    }
    return ans;
}

template<class T>
long long SUM(T a) {
    long long sum = 0;
    for(auto itr : a) sum += itr.second;
    return sum;
}

void solve(string S);

long long modpow(long long a,long long b){return b?modpow(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}


int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string S;
    cin >> S;
    solve(S);
    return 0;
}

struct mint {
    long long x;
    constexpr mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    constexpr mint operator-() const {
      return mint(-x);
    }
    constexpr mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    constexpr mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    constexpr mint inv() const {
        return pow(MOD-2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
};
ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
}

void solve(string S) {
    mint a = 10;
    reverse(ALL(S));
    int N = SZ(S);
    VI T(2019,0);
    T[0]++;
    LL s = 0, x = 1, ans = 0;
    REP(i,N) {
        s = (s + (S[i]-'0')*x) % 2019;
        T[s]++;
        x = x*10 % 2019;
    }
    REP(i,2019) {
        ans += T[i]*(T[i]-1)/2;
    }
    pa;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc164/d && sh test.sh
cd ~/Desktop/AtCoder/contest/abc164/d && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc164/d && sh submit.sh
PLEASE TYPE :
abcc
*/


Measured memory_bytes: 3784