#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

ll dp[200005][2020];
constexpr int m = 2019;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    int n = s.length();
    
    dp[0][0] = 1;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        int num = s[i] - '0';
        vector<ll> nextdp(m, 0);
        for(int j = 0; j < m; ++j){
            if(!dp[i][j])   continue;
            int nj = (j * 10 + num) % m;
            dp[i + 1][nj] += dp[i][j];
        }
        ans += dp[i + 1][0]++;
    }
    cout << ans << endl;
}
