#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll zero = 0;
ll INF = 10000000000;
int ctoi(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 0;
	}
}
int main(){
    string S;
    cin >> S;
    int N;
    N = S.size();
    
    vector<int> mod10(2020); //10のi乗を2019で割ったあまり
    mod10.at(0) = 1;
    for(int i = 1; i < 2020; i++){
        mod10.at(i) = (mod10.at(i-1) * 10) % 2019;
    }
    
    vector<int> mod(N + 1); //下からi桁目までを2019で割ったあまり
    mod.at(0) = 0;
    for(int i = 1; i < N + 1; i++){
        mod.at(i) = (mod.at(i-1) + ctoi(S.at(N-i)) * mod10.at(i-1)) % 2019;
    }
    
    vector<int> count(2019,0); //配列modで中身がiなものの個数
    for(int i = 0; i < N + 1; i++){
        count.at(mod.at(i))++;
    }
    
    ll ans = 0;
    int kl = 0;
    for(int i = 0; i < 2019; i++){
        ans += count.at(i) * (count.at(i) - 1) / 2;
    }
    printf("%lld\n", ans);
    
}