#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;


template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


long long kaijo(long long a){
    if(a == 1){
        return 1;
    }

    return a * kaijo(a-1);
}


int main(){
    string S;
    cin >> S;

    vector<long long> mod_count(2019, 0);
    long long factor = 10;
    long long prev = S.back() - '0';
    ++mod_count[prev];

    for(int i = S.size() - 2; i >= 0; --i){
        long long next = (S[i] - '0') * factor;
        next %= 2019;
        next = (next + prev) % 2019;
        ++mod_count[next];

        factor = (factor * 10) % 2019;
        prev = next;
    }

    long long sum = 0;
    if(mod_count[0]){
        sum += kaijo(mod_count[0]);
    }

    for(int i = 1; i < 2019; ++i){
        if(mod_count[i] > 1){
            sum += kaijo(mod_count[i]-1);
        }
    }
    cout << sum;

}
