#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

string s;
LL n,cnt[2025] = {0},now = 0,tot = 0;

LL kpw(LL x,LL y){
	LL ans = 1,tmp = x;
	while(y){
		if(y & 1) ans = (ans * tmp) % 2019;
		tmp = (tmp * tmp) % 2019;
		y >>= 1;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> s; n = s.length(); s = ' ' + s;
	cnt[0] = 1;
	for(LL i = n;i >= 1;i --){
		now += kpw(10,n - i) * (s[i] - '0');
		now %= 2019;
		tot += cnt[now];
		cnt[now] ++;
//		cout << now << endl;
	}
	cout << tot << '\n';
	return 0;
}