#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

//const long long M = 1e9+7;
int ctoi(const char c){
    switch(c){
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default : return -1;
    }
}

int main()
{
    string s;
    cin >> s;
    ll n = 0;
    vint count;
    count.push_back(0);
    char c;
    REP(i, 0, s.size()){
        //        n = stoll(s.substr(s.size() - i, i));
        c = s[s.size() - i - 1];
        n += ctoi(c) * pow(10, i);
//        p(n);
//        p2(s.substr(s.size() - i, i), n%2019);
        count.push_back(n%2019);
    }

    sort(count.begin(), count.end());

    ll ans = 0;
    ll tmp = 1;
    REP(i, 0, count.size()-1){
        if(count[i] == count[i+1]){
            tmp++;
        } else {
            ans += (tmp*(tmp-1))/2;
            tmp = 1;
        }
    }

    if(tmp!=1){
        ans += (tmp*(tmp-1))/2;
    }

    p(ans);
}