#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <random>
#include <bitset>
#include <chrono>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#ifndef ONLINE_JUDGE
// #include "debug.h"
#else
// #define debug(...) 42
#endif

const int M = 1e3+5;
const int MD= 1e9+7;

map<int,int>mp;
int main() {
	fast_cin();
	int t=1;
	// cin>>t;
	while(t--)
	{
		ll pro=1,sum=0,res=0;
		string s;
		cin>>s;
		int n=s.length();
		mp[0]++;
		for(int i=n-1;i>=0;i--){
			sum=(sum+pro*(s[i]-'0'))%2019;
			res+=mp[sum];
			mp[sum]++;
			pro=(pro*10)%2019;
		}
		cout<<res<<"\n";
	}
	return 0;
}