#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    string s;
    cin >> s;
    int len = s.length();

    int ten = 1;
    vector<int> d(len+1);
    for(int i=len-1; i>=0; i--){
        int a = (s[i] - '0') * ten % 2019;
        d[i] = (d[i+1] + a) % 2019;
        ten *= 10; ten %= 2019;
    }

    vector<int> cnt(2019);
    ll ans = 0;
    for(int i=len; i>=0; i--){
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
    return 0;
}