#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;

	vi md(2019, 0);
	vi md2(2019, 0);

	ll ans = 0;

	rep(i, s.size()) {
		int k = s[i] - '0';

		rep(j, 2019) {
			md[(10 * j + k) % 2019] = md2[j];
		}

		ans += md[0];

		rep(j, 2019) {
			md2[j] = md[j];
		}

		md[k]++;md2[k]++;
	}

	cout << ans << endl;

}