// Problem : D - Multiple of 2019
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/* ID: vqt
LANG: C++14
PROB: namenum
*/

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include<unistd.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template <typename T> using o_set = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
// #define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>

// defines
#define int long long
// #define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define ii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define vii vector<ii>
#define PQ priority_queue
#define minPQ priority_queue<int,vt <int>,greater <int>>
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define ER equal_range
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define UNI(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())));
#define SORT_UNI(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define POS(c,x) (lower_bound(c.begin(),c.end(),(x))-c.begin())
#define max(a, b) ((a)<(b)? b : a)
#define min(a, b) ((a)<(b)? a : b)
#define setmin(a, b) a = min(a, b)
#define setmax(a, b) a = max(a, b)
#define MINMAX(x) minmax_element(begin(x), end(x))

//permanent constants
const long long INF64 = 1e18; const int INF32 = 1e9;
const double EPS = static_cast<double>(1e-10);
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const int MOD = 2019; //(int)1e9+7; //998244353
ll powMod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll invMod(ll a) {ll b=MOD,u=1,v=0;while(b){ll t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v);} return (MOD + u) % MOD;}
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

//Tricks:
// Sort w Lambda Function: sort(begin(v), end(v), [] (int a, int b) { return a > b; });
// Sort vector cua bo ba so: struct MyStr {int a, b, c;}; vector<MyStr> v; ...fill v...
// sort(all(v), [](MyStr &A, MyStr &B) { return tie(A.a, A.b, A.c) < tie(B.a, B.b, B.c); });
#define odd(x) ((x) & 1)
#define even(x) !((x) & 1)
// vec - vector, p(x) - predicate so that p(x) = true for all elements of some prefix of vector
// vec and false on all others. To find the first place where p(x) doesn't hold one can simply use: 
#define FIRST_FAIL(vec, p) partition_point(ALL(vec), p) - vec.begin()
// partition_point(begin, end, p) returns the first ITERATOR it that p(*it) = false
#define isIn(vec, key) binary_search(ALL(vec), key)
#define toBool(num) !!(num)
#define bin(N, num) cerr << bitset<N>(num) << "\n"
// vector a: tinh XOR sum tu l den r:
#define XORsum(a, l, r) accumulate(a.begin()+l-1, a.begin()+r, 0, [](int x, int y){ return x^y; })
// BASIC STRING: just like vector but allows to use a few string member functions/operators: operator+ and operator+=.:
/*  int n;    basic_string<int> a;
    cin >> n; FOR(i, 0, n) { int x;   cin >> x; a += x; }
    a += a; a = a.substr(n/2, n);
    cout << (a + a).find({1, 2, 1}) << '\n';
*/
// count(a.begin(), a.end(), val) - count how many val in an array a
vector<int> prefixSum(vector<int> &a) {vi b; std::partial_sum(a.begin(), a.end(), b.begin()); return b;} 

int mostSignDigit(int n) { double k = log10(n); return (int)pow(10, k-floor(k));}
int numOfDigits(int n) {return (int)floor(log10(n)) + 1;}
bool isPowerOfTwo(int x) {return x && (!(x&(x-1)));} // first x is for the case x=0

bool allPositive(vector<int> &a) {return all_of(begin(a), end(a), [](int x){return x > 0;});} // are all of the elements positive?
// CHECK there is all numbers in array is positive: bool ok=true; for(auto z: a) ok &= (z>0);
bool anyPositive(vector<int> &a) {return any_of(begin(a), end(a), [](int x){return x > 0;});} // is there at least one positive element?
bool nonePositive(vector<int> &a) {return none_of(begin(a), end(a), [](int x){return x > 0;});} // are none of the elements positive?

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); } 
//void FILEIO() {  freopen("berries.in", "r", stdin);  freopen("berries.out", "w", stdout); } // USACO

/********* DEBUG - OLD ******************
//Universal DEBUG: https://codeforces.com/blog/entry/68809
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
// void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "T" : "F");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
/* To debug, just type: debug(x, y, z...). It requires C++ 11 or above.
// It can work with: Primitive data types: bool, int, long long, float, ...; pair, string;
// Collection types: std::vector, std::map, std::set, ...; Expressions
// */

/*
// #define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

******************* END DEBUG - OLD *********************/

/* ----------------------------- DEBUG ------------------------------*/

// #define LOCAL

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
    char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
    vector<char*> v({token});
    while( (token = strtok(NULL,", ")) ) v.push_back(token);
    return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { if(args.size()>0) cerr << args.size(); cerr << " "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
    debug() << " [" << args.back() << ": " << H << "] ";
    args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifdef LOCAL
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif

//********************** Codes go here *********************/

//********SEGMENT TREE: SIMPLE (NO LAZY UPDATE), OFFLINE: SORT INPUT, RANGE QUERY RANGE UPDATE **********//
// LIBRARY: cho vector cac query l, r, k. Dem so cac so cua vector d trong doan [l, r] lon hon k

void build(vi &d, vi &st, int id, int l, int r) {// recursive function to build tree based on vec d
    if (l == r) {st[id] = d[l]; return ;} // Nút id chỉ gồm 1 phần tử
    int mid = (l + r) / 2; build(d, st, id * 2, l, mid); build(d, st, id * 2+1, mid+1, r);
    st[id] = st[id*2] + st[id*2+1]; // lay tong tren 2 doan con 
}

void update(vi & d, vi &st, int id, int l, int r, int u) { //update tree khi update d[u]=0
    if (u < l || r < u) return; // u nằm ngoài đoạn [l, r]
    if (l == r) {  st[id] = d[l];    return ;   } // d[id]=0
    int mid = (l+r)/2; update(d, st, id*2, l, mid, u); update(d, st, id*2 + 1, mid+1, r, u);
    st[id] = st[id*2] + st[id*2+1];
}
void update(vi &d, vi &st, int u) {return update(d, st, 1, 0, SZ(d)-1, u); } // cap nhat cay khi d[u]=0 

int get(vi &d, vi &st, int id, int l, int r, int u, int v) { // truy van tren doan
    if (v < l || r < u) return 0; // Đoạn [l, r] nằm ngoài đoạn [u, v]
    if (u <= l && r <= v) return st[id]; // [l, r] nằm trong [u, v]: tra ket qua o nut id quan ly [l,r]
    int mid = (l+r)/2; 
    return get(d, st, id*2, l, mid, u, v) + get(d, st, id*2+1, mid+1, r, u, v); // tong cac so 1 cua vec d trong doan tu [l,r]
}
int get(vi &d, vi & st, int u, int v) { return get(d, st, 1, 0, SZ(d)-1, u, v);}

vi allQueries(vi &v, vec<pair<ii, int>> & vQue) { // v: input vector, return all answers
	// sort queries:
	struct Q {int l, r, k, id;}; // query: dem so cac so trong [l,r] lon hon k
	vec<Q> vq;
	FOR(i, 0, SZ(vQue)) {Q que = {vQue[i].F.F, vQue[i].F.S, vQue[i].S, i}; vq.PB(que);}
	sort(ALL(vq), [](Q x, Q y){return x.k < y.k;});
	// creat auxiliary vector:
	int n=SZ(v); vi d(n, 1); // array phu tro de dem so cac so c[i] > k (=-c[j]): d[i]=1 neu c[i]>k
	// build seg tree from d:
	vi st(4*n);	build(d, st, 1, 0, n-1); // build tree based on d, root = 1, on [0, n-1]
	// sort (in-place) initial vector v:
	vii tmp(n); FOR(i, 0, n) tmp[i] = {v[i], i}; sort(ALL(tmp)); 
	vi id(n); FOR(i, 0, n) id[i] = tmp[i].S; // now {v[id[i]] is sorted!}
	// calculate all answers on all queries in sorted order:
	vi ans(SZ(vq)); int m = 0; // m - chi so se chay tu [0, n-1] de check v[]>k khong 
	FOR(i, 0, SZ(vq)) {
		Q q = vq[i]; //read a (sorted) query: q.k se tang dan
		while(m<n and v[id[m]] <= q.k) { // do da sort, tong cac operation nay = n
			d[id[m]] = 0; // tai vi tri id nao co: c[id]<=k thi update d=0 tai do
			update(d, st, id[m]); // update(1, 0, n-1, id[m]); // cap nhat cung tai id[m]!!, logn
			m++;
		}
		ans[q.id]= get(d, st, q.l, q.r); // get(d, st, 1, 0, n-1, q.l, q.r);
	}
	return ans;
} 
/*********************END LIB ********************************/

/**************************************************/
void solve() {
	string s; cin >> s;
	int n = s.length();
	vi mod(n+1); mod[n]=0;
	int prev = 0;
	FORD(i, n-1, 0) {
		int cur;
		if(i!=n-1) cur = powMod(10ll, (n-1)-i) * (s[i]-'0') % MOD + prev;
		else cur = (s[i]-'0') + prev;
		mod[i] = cur%MOD; // mod[n-1] = s[n-1], ...
		prev = cur % MOD;
	}
	
	dbg(s); dbg(n); dbg(mod);
	
	int ans = 0;
	map<int, int> mp;
	FOR(i, 0, n+1) mp[mod[i]]++;
	for(auto z : mp) {
		ans += z.S*(z.S-1)/2;
	}
	
	vi inv10(n); inv10[0] = 1; // (10^-i) mod 2019
	FOR(i, 1, n) {
		inv10[i] = inv10[i-1] * invMod(10ll) % MOD;
	}
	
	dbg(inv10);
	// FOR(i, 0, SZ(inv10)) cerr << inv10[i]*powMod(10ll, i) % MOD << ", ";
	// cerr << endl;
	
	// vec<pair<ii, int>> vp, vp1;
	// FOR(i, 0, n) {
		// if(inv10[i]==3) { // tim so cac so D: (MOD + D%MOD - C%MOD) % MOD = 673 => 
			// int k = (mod[i] + 673) % MOD;
			// pair<ii, int> p = {{0, n-i-2}, k};
			// pair<ii, int> p1 = {{0, n-i-2}, k-1};
// 			
			// dbg(i, p);
// 			
			// vp.PB(p); vp1.PB(p1);
			// // ans += count(mod, 0, n-i-2, k); // so cac so cua mod tu [0, n-i-2] = k 
		// }
		// if(inv10[i]==673) { // tim so cac so D: (MOD + D%MOD - C%MOD) % MOD = 3 => 
			// int k = (mod[i] + 3) % MOD;
			// pair<ii, int> p = {{0, n-i-2}, k};
			// pair<ii, int> p1 = {{0, n-i-2}, k-1};
// 
			// dbg(i, p);
// 			
			// vp.PB(p); vp1.PB(p1);
			// // ans += count(mod, 0, n-i-2, k); // so cac so cua mod tu [0, n-i-2] = k 
		// }
	// }
	// vi res = allQueries(mod, vp), res1 = allQueries(mod, vp1);
// 	
	// dbg(res); dbg(res1);
// 	
	// FOR(i, 0, SZ(res)) ans += (res[i]-res1[i]);
// 	
	cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
  // FILEIO();
//  auto beginProgram = chrono::steady_clock::now();

// preCalc(); // any 1-time precalculation need to do before many test cases?

// int t; cin >> t; FOR(i, 0, t)
  {
//	  cout << "Case #" << i+1 << ": "; // Google CodeJam style
	  solve();
  }

//  auto endProgram = chrono::steady_clock::now();
//  cerr << chrono::duration_cast<chrono::milliseconds>(endProgram - beginProgram).count() << " ms" << endl;
  return 0;
}



Measured memory_bytes: 6880