#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<stack>
#include<sstream>
using namespace std;
string s;
int vis[200005];
int main()
{
cin >> s;
long long num = 0;
int a = 1,cnt = 0;
vis[0] = 1;//余数为零直接cnt++不用找出余数相同的数
for (int i = s.size() - 1; i >= 0; i--)
{
num = (num + a * (s[i] - '0') % 2019) % 2019;
a = a * 10 % 2019;
cnt += vis[num];//余数相同的数之间的区间都可以整除2019
vis[num]++;
}
cout << cnt << endl;
return 0;
}