
#include<forward_list>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<iterator> 
#include<sstream>
#include<fstream>
#include<istream>
#include<utility>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<list>
#include<map> 
#include<set>
#define NinjaTurtle ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infile freopen(".txt", "r", stdin);
#define outfile freopen(".txt", "w", stdout);
#define all(v) v.begin(),v.end()
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long 
#define endl "\n"
using namespace std;
int frq[10];
int main()
{
	NinjaTurtle
		string s,st;
	cin >> s;
	int cnt = 0,x=0;
	for (int i = 0; i < s.size(); i++){
		x = 0;
		x = ((x * 10) + s[i] - '0') % 2019;
		
		for (int j = i + 1; j < s.size(); j++){
			x = ((x * 10) + s[j] - '0') % 2019;
			if (x%2019==0)cnt++;
			
		}
	}
	cout << cnt << endl;





}