#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)

constexpr int m = 2019;

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

    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int n = s.length();
    
    vector<int> sum(n + 1);
    sum[0] = 0;
    int mul = 1;
    for(int i = 0; i < n; ++i){
        int num = s[i] - '0';
        sum[i + 1] = (sum[i] + num * mul) % m;
        mul *= 10;
        if(mul > m) mul %= m;
    }
    map<int, int> mp;
    for(int i = 0; i <= n; ++i) ++mp[sum[i]];
    ll ans = 0;
    for(auto it : mp)   ans += (ll)it.second * (it.second - 1) / 2;
    cout << ans << endl;
}