#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

string s;
ll ans, n, t, rem[2020], mul = 1;

int main() {
	fastio; cin >> s;
	n = s.length(); s = " " + s;
	rem[0] = 1; t = 0;
	DEC(i, n, 1) {
		t = (t + mul*(s[i]-'0')) % 2019;
		ans += (rem[t] * (rem[t]+1))/2;
		rem[t]++; mul = (10*mul) % 2019;
	}
	cout << ans;
}